@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Poppins:wght@400;500;600;700&display=swap');

:root {
    /* Brand Colors */
    --primary-gold: #FFC107;
    --primary-blue: #246EB9;
    --dark-navy: #161829;

    /* Light Mode Palette */
    --bg-main: #F1F5F9;
    --bg-surface: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-sidebar: #0F172A;
    --bg-header: #FFFFFF;

    --text-main: #0F172A;
    --text-muted: #64748B;
    --text-inverse: #FFFFFF;

    --border-color: #E2E8F0;
    --border-hover: #CBD5E1;
    --input-bg: #FFFFFF;

    /* Semantic Colors */
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #3B82F6;

    /* Constants */
    --sidebar-w: 280px;
    --sidebar-collapsed-w: 80px;
    --header-h: 72px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.04), 0 4px 6px -4px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.05), 0 8px 10px -6px rgb(0 0 0 / 0.05);
    --shadow-premium: 0 20px 40px -12px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-main: #020617;
    --bg-surface: #0F172A;
    --bg-card: #1E293B;
    --bg-header: #0F172A;

    --text-main: #F8FAFC;
    --text-muted: #94A3B8;

    --border-color: #1E293B;
    --border-hover: #334155;
    --input-bg: #0F172A;

    --shadow-premium: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
}

button, input, select, textarea {
    font-family: inherit;
}

a { text-decoration: none; color: inherit; }

/* Layout Architecture */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
aside {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1001;
    transition: var(--transition);
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
}

body.sidebar-collapsed aside {
    width: var(--sidebar-collapsed-w);
}

.sidebar-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-logo {
    height: 32px;
    background: #fff;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

body.sidebar-collapsed .sidebar-logo {
    width: 32px;
    padding: 2px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 14px;
}

.sidebar-group { margin-bottom: 28px; }

.sidebar-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    padding: 0 12px 10px;
    opacity: 0.5;
}

body.sidebar-collapsed .sidebar-label { display: none; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    white-space: nowrap;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.65);
    width: 100%;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.nav-item.active {
    background: var(--primary-gold);
    color: var(--dark-navy);
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.2);
}

.nav-item i {
    font-size: 18px;
    width: 20px;
    text-align: center;
    opacity: 0.8;
}

.nav-item.active i { opacity: 1; }

body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 12px 0;
}

body.sidebar-collapsed .nav-item span { display: none; }

/* Main Section */
main {
    flex: 1;
    margin-left: var(--sidebar-w);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

body.sidebar-collapsed main {
    margin-left: var(--sidebar-collapsed-w);
}

/* Header */
header {
    height: var(--header-h);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.sidebar-toggle {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    color: var(--primary-blue);
    border-color: var(--primary-blue);
    background: #fff;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.header-search {
    position: relative;
    width: 340px;
}

.header-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
}

.header-search input {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px 10px 40px;
    font-size: 14px;
    transition: var(--transition);
}

.header-search input:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary-blue);
    box-shadow: 0 4px 12px rgba(36, 110, 185, 0.08);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.icon-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    position: relative;
    display: grid;
    place-items: center;
}

.icon-btn:hover { background: #fff; color: var(--primary-blue); border-color: var(--primary-blue); }

.badge-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 10px;
    border: 2px solid var(--bg-header);
}

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    border: 1px solid transparent;
}

.profile-trigger:hover { background: var(--bg-surface); border-color: var(--border-color); }

.avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary-blue), #1e5ba3);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(36, 110, 185, 0.2);
}

/* Page Content */
.content-body {
    padding: 32px;
    max-width: 1440px;
    margin: 0 auto;
    width: 100%;
}

.page-header {
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.page-title h1 { font-size: 24px; margin-bottom: 4px; }
.page-title p { color: var(--text-muted); font-size: 14px; }

/* Components */
.grid { display: grid; gap: 24px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-premium);
    border-color: var(--border-hover);
}

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 160px;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.stat-label {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.stat-trend {
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.stat-trend span { color: var(--text-muted); font-weight: 500; }

.trend-up { color: var(--success); }
.trend-down { color: var(--danger); }

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    letter-spacing: 0.01em;
}

.btn-primary {
    background: var(--primary-gold);
    color: var(--dark-navy);
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.2);
}
.btn-primary:hover {
    background: #eab308;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 193, 7, 0.3);
}

.btn-secondary {
    background: var(--primary-blue);
    color: #fff;
    box-shadow: 0 4px 12px rgba(36, 110, 185, 0.2);
}
.btn-secondary:hover {
    background: #1e5ba3;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(36, 110, 185, 0.3);
}

.btn-outline {
    background: #fff;
    border-color: var(--border-color);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}
.btn-outline:hover {
    background: var(--bg-surface);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    padding: 14px 20px;
    text-align: left;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    vertical-align: middle;
    color: var(--text-main);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-surface); }

/* Badges */
.badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid transparent;
}

.badge-success {
    background: rgba(16, 185, 129, 0.08);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}
.badge-warning {
    background: rgba(245, 158, 11, 0.08);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.2);
}
.badge-danger {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}
.badge-info {
    background: rgba(59, 130, 246, 0.08);
    color: var(--info);
    border-color: rgba(59, 130, 246, 0.2);
}

/* Drawer & Overlay */
#detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.4);
    backdrop-filter: blur(8px);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

#detail-overlay.open { opacity: 1; pointer-events: auto; }

#detail-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    bottom: 20px;
    width: 640px;
    max-width: calc(100% - 40px);
    background: var(--bg-card);
    z-index: 2001;
    transform: translateX(120%);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-premium);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

#detail-panel.open { transform: translateX(0); }

.detail-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-header h2 { font-size: 20px; letter-spacing: -0.01em; }

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
}

.detail-footer {
    padding: 24px 32px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 16px;
    background: var(--bg-surface);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade {
    animation: fadeIn 0.4s ease forwards;
}

/* Auth Visibility Logic */
body.auth #login-screen { display: none !important; }
body.not-auth .app-wrapper { display: none !important; }

/* Login Screen */
#login-screen {
    position: fixed;
    inset: 0;
    background: #020617;
    background-image:
        radial-gradient(at 0% 0%, rgba(36, 110, 185, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(255, 193, 7, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(36, 110, 185, 0.15) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(255, 193, 7, 0.08) 0px, transparent 50%);
    display: grid;
    place-items: center;
    z-index: 9999;
}

.login-card {
    width: 100%;
    max-width: 440px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 48px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1;
}

[data-theme="dark"] .login-card {
    background: rgba(15, 23, 42, 0.95);
    border-color: rgba(255, 255, 255, 0.05);
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.login-logo-container {
    display: inline-block;
    padding: 12px;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

.login-header h2 {
    font-size: 24px;
    color: #0f172a;
    letter-spacing: -0.02em;
    font-weight: 800;
}

[data-theme="dark"] .login-header h2 { color: #fff; }

.login-field { margin-bottom: 24px; }

.login-field label {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 10px;
}

.login-input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 500;
    transition: var(--transition);
}

.login-input:focus {
    outline: none;
    border-color: var(--primary-blue);
    background: #fff;
    box-shadow: 0 4px 12px rgba(36, 110, 185, 0.1);
}

.input-with-icon i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
    transition: var(--transition);
}

.login-btn {
    width: 100%;
    height: 56px;
    font-size: 15px;
    font-weight: 800;
    margin-top: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.login-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.login-footer p {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.8;
}

/* Skeleton Loaders */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--border-color) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite linear;
    border-radius: var(--radius-sm);
    display: inline-block;
    height: 1em;
    width: 100%;
}

.skeleton-circle {
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Toast */
#toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 16px 24px;
    background: var(--bg-card);
    border-left: 4px solid var(--primary-blue);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#toast.show { transform: translateX(0); }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.animate-fade {
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Responsive Adjustments */
#sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.mobile-close {
    display: none;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
}

@media (max-width: 1024px) {
    :root { --sidebar-w: 80px; }
    .sidebar-label, .nav-item span { display: none; }
    main { margin-left: var(--sidebar-collapsed-w); }
    .sidebar-toggle { display: none; }
    body.sidebar-collapsed main { margin-left: var(--sidebar-collapsed-w); }
}

@media (max-width: 768px) {
    :root { --header-h: 64px; }

    aside {
        transform: translateX(-100%);
        width: 280px !important;
        box-shadow: 10px 0 30px rgba(0,0,0,0.3);
    }

    .mobile-close { display: block; margin-left: auto; }

    .sidebar-label, .nav-item span { display: flex; }

    body.sidebar-mobile-open aside { transform: translateX(0); }
    body.sidebar-mobile-open #sidebar-overlay { opacity: 1; pointer-events: auto; }

    main { margin-left: 0 !important; }

    header { padding: 0 16px; }
    .header-left { gap: 12px; }
    .sidebar-toggle { display: grid; }
    .breadcrumb { display: none; }

    .header-search { display: none; }
    .header-right { gap: 6px; }

    #connection-status span { display: none; }
    #connection-status { width: 32px; padding: 0; justify-content: center; }

    #envSelector { display: none; }

    .header-right { gap: 4px; }
    .icon-btn { width: 34px; height: 34px; font-size: 14px; }
    .avatar { width: 34px; height: 34px; font-size: 12px; }

    .profile-trigger div { display: none; }
    .profile-trigger { padding: 4px; }

    .content-body { padding: 20px 16px; }

    .grid { gap: 16px; }
    .grid-4, .grid-2 { grid-template-columns: 1fr; }

    .page-header { flex-direction: column; align-items: flex-start; gap: 16px; }
    .page-header .btn { width: 100%; }

    .stat-card { min-height: auto; padding: 20px; }
    .stat-value { font-size: 24px; }

    /* Table Responsiveness */
    .table-wrapper {
        border: none;
        margin: 0 -16px;
        width: calc(100% + 32px);
        border-radius: 0;
    }

    table thead { display: none; }
    table tr {
        display: block;
        padding: 16px;
        border-bottom: 8px solid var(--bg-main);
        background: #fff;
    }

    table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        text-align: right;
    }

    table td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        font-size: 12px;
        color: var(--text-muted);
        text-transform: uppercase;
    }

    table td:first-child {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
        margin-bottom: 8px;
    }

    table td:first-child::before { display: none; }

    #detail-panel {
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    .login-card { padding: 32px 24px; }
    .login-header h2 { font-size: 20px; }
    .stat-grid { grid-template-columns: 1fr; }
}
