/* Reset and Base Styles */
:root {
    --bg-body: #f5f7fa;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #f7fafc;
    --bg-active: #eff6ff;
    --bg-header-start: #1e40af;
    --bg-header-end: #3b82f6;

    --text-primary: #2d3748;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;

    --border-color: #e2e8f0;
    --border-focus: #3b82f6;

    --brand-primary: #3b82f6;
    --brand-dark: #1e40af;
    
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.1);

    --btn-secondary-bg: #f1f5f9;
    --btn-secondary-text: #475569;
    --btn-secondary-border: #e2e8f0;
    --btn-secondary-hover: #e2e8f0;
}

body.dark-mode {
    --bg-body: #111827;
    --bg-card: #1f2937;
    --bg-sidebar: #1f2937;
    --bg-input: #374151;
    --bg-hover: #374151;
    --bg-active: #365314;
    --bg-header-start: #1a2e05;
    --bg-header-end: #365314;

    --brand-primary: #84cc16;
    --brand-dark: #4d7c0f;

    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --text-inverse: #f9fafc;

    --border-color: #374151;
    
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.5);

    --btn-secondary-bg: #374151;
    --btn-secondary-text: #f9fafb;
    --btn-secondary-border: #4b5563;
    --btn-secondary-hover: #4b5563;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Layout */
a {
    color: var(--brand-primary);
    text-decoration: none;
}

a:hover {
    color: var(--brand-dark);
    text-decoration: underline;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    background: linear-gradient(135deg, var(--bg-header-start) 0%, var(--bg-header-end) 100%);
    color: var(--text-inverse);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header h1 i {
    margin-right: 0.5rem;
}

.app-logo-img {
    display: none;
    height: 1.5em;
    vertical-align: middle;
    margin-right: 0.5rem;
}

body.dark-mode .app-logo-icon {
    display: none;
}

body.dark-mode .app-logo-img {
    display: inline-block;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Profile Dropdown */
.profile-dropdown {
    position: relative;
}

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 180px;
}

.profile-trigger:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.profile-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    text-align: left;
    min-width: 0;
}

.profile-name {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-role {
    font-size: 0.75rem;
    opacity: 0.8;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-chevron {
    font-size: 0.75rem;
    opacity: 0.7;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.profile-dropdown.open .profile-chevron {
    transform: rotate(180deg);
}

.profile-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 280px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
}

.profile-dropdown.open .profile-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.profile-menu-header {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px 12px 0 0;
}

.profile-avatar-large {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.profile-details {
    flex: 1;
    min-width: 0;
}

.profile-name-large {
    font-weight: 600;
    font-size: 1rem;
    color: #1f2937;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-email {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-role-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: #dbeafe;
    color: #1e40af;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

.profile-menu-divider {
    height: 1px;
    background: #f3f4f6;
    margin: 0.5rem 0;
}

.profile-menu-items {
    padding: 0.5rem;
}

.profile-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: #374151;
    font-size: 0.875rem;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.profile-menu-item:hover {
    background: #f9fafb;
    color: #1f2937;
}

.profile-menu-item i {
    width: 1rem;
    text-align: center;
    opacity: 0.7;
}

.profile-menu-item span {
    flex: 1;
}

.profile-menu-logout {
    color: #dc2626;
}

.profile-menu-logout:hover {
    background: #fef2f2;
    color: #dc2626;
}

.profile-menu-logout i {
    opacity: 1;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Content Area */
.content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--bg-body);
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    margin-bottom: 2rem;
    flex: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #f3f4f6;
}

.copyright {
    text-align: center;
    color: #9ca3af;
    font-size: 0.75rem;
    line-height: 1.4;
}

.copyright p {
    margin: 0.25rem 0;
}

.copyright .version {
    font-weight: 600;
    color: #6b7280;
}

.sidebar-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Search Box */
.search-box {
    position: relative;
    margin-bottom: 1rem;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s;
    background: var(--bg-input);
    color: var(--text-primary);
}

.search-box input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-box i {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* View List */
.view-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.view-item {
    border-radius: 8px;
    transition: all 0.2s;
}

.view-item:hover {
    background: var(--bg-hover);
}

.view-item.active {
    background: var(--bg-active);
    border-left: 4px solid var(--brand-primary);
}

.view-link {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
    gap: 0.75rem;
}

.view-link:hover {
    color: var(--brand-dark);
}

.view-link i:first-child {
    font-size: 1.125rem;
    width: 1.25rem;
    text-align: center;
    color: var(--text-secondary);
}

.view-info {
    flex: 1;
}

.view-name {
    font-weight: 500;
    font-size: 0.875rem;
    display: block;
}

.view-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
    margin-top: 0.25rem;
}

.view-customize {
    color: #9ca3af;
    font-size: 0.875rem;
}

.view-customize:hover {
    color: #3b82f6;
}

/* Loading States */
.loading {
    text-align: center;
    padding: 2rem;
    color: #6b7280;
}

.loading i {
    font-size: 1.5rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 24, 39, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.loading-content {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    max-width: 400px;
    width: 90%;
}

.yoda-loader {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-image {
    width: 60px;
    height: auto;
    position: relative;
    z-index: 2;
    animation: float 3s ease-in-out infinite;
}

.force-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--brand-primary);
    opacity: 0;
    animation: force-pulse 2s infinite;
}

.loading-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-primary);
    min-height: 1.5em;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes force-pulse {
    0% {
        width: 60px;
        height: 60px;
        opacity: 0.8;
        border-width: 2px;
    }
    100% {
        width: 100px;
        height: 100px;
        opacity: 0;
        border-width: 0px;
    }
}

/* Auth Loading Screen - shown before authentication is verified */
.auth-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-body, #f8fafc);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.auth-loading-content {
    text-align: center;
}

.auth-loading .yoda-loader {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-loading .loading-image {
    width: 70px;
    height: auto;
    position: relative;
    z-index: 2;
    animation: float 3s ease-in-out infinite;
}

.auth-loading .force-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--brand-primary, #3b82f6);
    opacity: 0;
    animation: force-pulse 2s infinite;
}

.auth-loading .loading-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
}

/* Dark mode support for auth loading */
.dark-mode .auth-loading {
    background: var(--bg-body);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--brand-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border: 1px solid var(--btn-secondary-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--btn-secondary-hover);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-icon {
    padding: 0.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    gap: 0.25rem;
}

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-light {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-light:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-link {
    background: none;
    color: var(--brand-primary);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    text-decoration: underline;
}

.btn-link:hover {
    color: var(--brand-dark);
}

/* Alerts */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    position: relative;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.alert-error .error-list {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
}

.alert-error .error-list li {
    margin: 0.25rem 0;
}

.alert-warning {
    background: #fffbeb;
    border: 1px solid #fed7aa;
    color: #92400e;
}

.alert-info {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #1e40af;
}

.alert-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

.alert-close:hover {
    opacity: 1;
}

/* Empty and Error States */
.empty-state,
.error-state,
.coming-soon {
    text-align: center;
    padding: 4rem 2rem;
    color: #6b7280;
}

.dashboard-error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.empty-state i,
.error-state i,
.coming-soon i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #d1d5db;
}

.error-state i {
    color: #ef4444;
}

.coming-soon i {
    color: #f59e0b;
}

.empty-state h3,
.error-state h3,
.coming-soon h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mr-2 {
    margin-right: 0.5rem;
}

.ml-2 {
    margin-left: 0.5rem;
}

.p-4 {
    padding: 1rem;
}

.px-4 {
    padding-left: 1rem;
    padding-right: 1rem;
}

.py-2 {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.flex {
    display: flex;
}

.flex-1 {
    flex: 1;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

/* ========================================
   Toast Notifications
   ======================================== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--brand-primary);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast.toast-enter {
    opacity: 1;
    transform: translateX(0);
}

.toast.toast-exit {
    opacity: 0;
    transform: translateX(100%);
}

.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--brand-primary);
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.toast-message {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    margin: -0.25rem;
    font-size: 0.875rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

.toast-action {
    margin-top: 0.5rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--brand-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.toast-action:hover {
    background: var(--brand-dark);
}

.toast-clickable {
    cursor: pointer;
}

.toast-clickable:hover {
    background: var(--bg-hover);
}

/* Toast type variations */
.toast-info {
    border-left-color: #3b82f6;
}
.toast-info .toast-icon { color: #3b82f6; }

.toast-success,
.toast-create {
    border-left-color: #22c55e;
}
.toast-success .toast-icon,
.toast-create .toast-icon { color: #22c55e; }

.toast-warning {
    border-left-color: #f59e0b;
}
.toast-warning .toast-icon { color: #f59e0b; }

.toast-error,
.toast-delete {
    border-left-color: #ef4444;
}
.toast-error .toast-icon,
.toast-delete .toast-icon { color: #ef4444; }

.toast-update {
    border-left-color: #8b5cf6;
}
.toast-update .toast-icon { color: #8b5cf6; }

/* Dark mode adjustments */
body.dark-mode .toast {
    background: #1f2937;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Animation */
@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Easter Egg: The Force */
@keyframes levitate {
    0% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0); }
}

body.use-the-force .metric-card,
body.use-the-force .dashboard-card,
body.use-the-force .view-item,
body.use-the-force .btn {
    animation: levitate 3s ease-in-out infinite;
    box-shadow: 0 15px 30px rgba(132, 204, 22, 0.2); /* Yoda green glow */
    transition: all 0.5s ease;
}

body.use-the-force .metric-card:nth-child(odd),
body.use-the-force .dashboard-card:nth-child(even) {
    animation-delay: 1.5s;
}