:root {
    --header-height: 76px;

    /* Palette (matches dashboard mock) */
    --bg-primary: #f3f4f8;
    --bg-surface: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e6e9f2;

    --accent-color: #6c5ce7;
    --accent-2: #3b82f6;

    --sidebar-bg: #1c1f35;
    --sidebar-text: #f5f7ff;
    --sidebar-muted: rgba(245, 247, 255, 0.72);
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(255, 255, 255, 0.12);

    --shadow-soft: 0 10px 25px rgba(17, 24, 39, 0.08);
    --glow: 0 14px 34px rgba(108, 92, 231, 0.18);
}

[data-theme="dark"] {
    --bg-primary: #0b1020;
    --bg-surface: #0f172a;
    --text-primary: #eef2ff;
    --text-secondary: rgba(238, 242, 255, 0.72);
    --border-color: rgba(255, 255, 255, 0.08);

    --sidebar-bg: #0b1020;
    --sidebar-text: #eef2ff;
    --sidebar-muted: rgba(238, 242, 255, 0.72);
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(255, 255, 255, 0.1);

    --glow: 0 14px 44px rgba(108, 92, 231, 0.22);
    --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

body.no-scroll {
    overflow: hidden;
}

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

[data-theme="dark"] a {
    color: var(--text-primary);
}

.app-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.app-header {
    height: var(--header-height);
    padding: 14px 22px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-shell {
    display: flex;
    min-height: calc(100vh - var(--header-height));
    gap: 0;
}

.app-sidebar {
    width: 264px;
    min-height: calc(100vh - var(--header-height));
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    padding: 18px 16px;
    position: sticky;
    top: var(--header-height);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    color: var(--sidebar-text);
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
    box-shadow: var(--glow);
}

.brand-meta {
    display: grid;
    line-height: 1.1;
}

.brand-name {
    font-weight: 800;
    letter-spacing: 0.02em;
}

.brand-sub {
    font-size: 12px;
    color: var(--sidebar-muted);
}

.sidebar-nav {
    gap: 6px;
}

.sidebar-section {
    margin-top: 14px;
    margin-bottom: 8px;
    padding: 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-muted);
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--sidebar-muted);
    transition: background 0.15s ease, color 0.15s ease;
    border: 1px solid transparent;
}

.nav-icon {
    width: 14px;
    height: 14px;
    color: rgba(245, 247, 255, 0.9);
    flex: 0 0 auto;
}

.nav-icon svg {
    display: block;
    width: 14px;
    height: 14px;
}

.app-sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.app-sidebar .nav-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text);
    border-color: rgba(255, 255, 255, 0.14);
}

.app-content {
    padding: 24px;
    width: 100%;
}

.card {
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    box-shadow: var(--shadow-soft);
    border-radius: 16px;
    color: var(--text-primary);
}

.metric-card {
    padding: 18px;
    border-radius: 14px;
    border: 1px solid rgba(124, 58, 237, 0.25);
}

.metric-label {
    color: var(--text-secondary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.login-wrapper {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 20% 20%, rgba(124, 58, 237, 0.12), transparent 32%),
                radial-gradient(circle at 80% 0%, rgba(14, 165, 233, 0.14), transparent 26%),
                var(--bg-primary);
}

.login-card {
    width: min(420px, 92vw);
    padding: 28px;
    background: var(--bg-surface);
    border: 1px solid rgba(124, 58, 237, 0.25);
    border-radius: 20px;
    box-shadow: var(--glow);
}

.login-body {
    background: #d8d8d8;
    font-family: 'Poppins', 'Plus Jakarta Sans', 'Segoe UI', Tahoma, sans-serif;
}

.login-surface {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
}

.login-tablet {
    width: min(1160px, 96vw);
    background: #ffffff;
    border-radius: 28px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.14);
    border: 1px solid #efefef;
    padding: 34px 38px 48px;
}

.system-title {
    text-align: center;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #3167a6;
    font-size: 24px;
    text-transform: uppercase;
    margin-bottom: 26px;
}

.scene-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 42px;
}

.auth-panel {
    width: min(360px, 100%);
    background: #ffffff;
    border-radius: 12px;
    padding: 28px 30px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid #f3f3f3;
}

.auth-title {
    font-size: 28px;
    font-weight: 800;
    color: #111111;
    margin-bottom: 14px;
}

.input-field {
    position: relative;
    margin-bottom: 12px;
}

.input-field input {
    width: 100%;
    padding: 12px 14px 12px 44px;
    border: 1px solid #e6e6e6;
    border-radius: 7px;
    font-size: 14px;
    color: #5a6270;
    background: #fdfdfd;
}

.input-field input:focus {
    outline: none;
    border-color: #8ab3ff;
    box-shadow: 0 0 0 3px rgba(76, 142, 255, 0.18);
}

.field-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #8fa7ba;
}

.remember-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 16px;
    font-size: 13px;
    color: #2f3640;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
    background: #e7eef7;
    border-radius: 24px;
    padding: 3px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.toggle input {
    position: absolute;
    inset: 0;
    opacity: 0;
}

.toggle-handle {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #35b567;
    box-shadow: 0 3px 8px rgba(53, 181, 103, 0.4);
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle input:checked + .toggle-handle {
    transform: translateX(20px);
    background: #2fb36c;
}

.login-btn {
    width: 100%;
    border: none;
    border-radius: 8px;
    padding: 12px 14px;
    background: linear-gradient(90deg, #349aff, #1e52d8);
    color: #ffffff;
    font-weight: 700;
    font-size: 16px;
    box-shadow: 0 12px 24px rgba(47, 121, 255, 0.35);
    margin-top: 4px;
}

.touch-btn {
    width: 100%;
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 14px;
    border-radius: 10px;
    border: 1px solid #d1dbe8;
    background: #ffffff;
    color: #0f2f6e;
    font-weight: 600;
}

.touch-btn svg {
    width: 46px;
    height: 46px;
    color: #1d4ed8;
}

.illustration-panel {
    position: relative;
    min-height: 320px;
    display: grid;
    place-items: center;
}

.illustration-blob {
    position: absolute;
    inset: 20px 12px 0 12px;
    background: radial-gradient(circle at 18% 32%, rgba(146, 206, 255, 0.35), transparent 42%),
                radial-gradient(circle at 82% 50%, rgba(104, 168, 255, 0.3), transparent 50%),
                #ffffff;
    border-radius: 38px;
}

.scene-graphic {
    position: relative;
    width: 100%;
    max-width: 520px;
    z-index: 1;
    display: block;
    height: auto;
    border-radius: 18px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.12);
    object-fit: contain;
}

.form-control {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-color);
    border-radius: 12px;
}

.form-select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-color);
    border-radius: 12px;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background: #1a2338;
    color: #f1f5ff;
    border-color: #32405f;
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    box-shadow: 0 0 0 0.2rem rgba(124, 58, 237, 0.25);
}

.form-control::placeholder {
    color: var(--text-secondary);
}
[data-theme="dark"] .form-control::placeholder {
    color: #9aa8c8;
}

.form-label {
    color: var(--text-secondary);
}
[data-theme="dark"] .form-label {
    color: #c3c9e6;
}

.modal-content {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .modal-content {
    background: #0f172a;
    color: #f1f5ff;
    border-color: #32405f;
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
    border-color: #32405f;
}

.btn-accent {
    background: linear-gradient(120deg, var(--accent-color), var(--accent-2));
    color: #ffffff;
    border: none;
    box-shadow: 0 10px 25px rgba(14, 165, 233, 0.25);
    border-radius: 12px;
}

.btn-accent:hover {
    filter: brightness(1.05);
}

.user-avatar {
    width: 40px;
    height: 40px;
    font-weight: 700;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
    color: #ffffff;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-titles {
    display: grid;
    gap: 2px;
    line-height: 1.1;
}

.header-kicker {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    font-weight: 700;
}

.header-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.header-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(520px, 46vw);
    background: rgba(17, 24, 39, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 10px 12px;
}

.header-search svg {
    width: 18px;
    height: 18px;
    color: rgba(17, 24, 39, 0.5);
}

.header-search-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: rgba(17, 24, 39, 0.02);
    color: rgba(17, 24, 39, 0.75);
    display: grid;
    place-items: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.icon-btn:hover {
    background: rgba(17, 24, 39, 0.06);
    transform: translateY(-1px);
}

.icon-btn--ghost {
    background: transparent;
}

[data-theme="dark"] .app-sidebar .icon-btn,
.app-sidebar .icon-btn {
    border-color: rgba(255, 255, 255, 0.14);
    color: var(--sidebar-text);
}

[data-theme="dark"] .app-sidebar .icon-btn:hover,
.app-sidebar .icon-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .icon-btn {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: rgba(238, 242, 255, 0.85);
}

[data-theme="dark"] .header-search {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .header-search svg {
    color: rgba(238, 242, 255, 0.55);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    font-weight: 800;
    font-size: 14px;
    line-height: 1.1;
}

.user-role {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.dashboard-wrap {
    max-width: 1200px;
}

.stat-card {
    padding: 16px 16px 12px;
    border-radius: 16px;
}

.stat-card-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.stat-meta {
    flex: 1 1 auto;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #ffffff;
    flex: 0 0 auto;
}

.stat-icon svg {
    width: 18px;
    height: 18px;
}

/* Safety: prevent default 300x150 SVGs from exploding if a selector misses */
.app-header svg,
.app-sidebar svg,
.dashboard-wrap svg {
    max-width: 100%;
    height: auto;
}

.stat-icon--purple { background: #6c5ce7; }
.stat-icon--blue { background: #4f7cff; }
.stat-icon--red { background: #ff5a5f; }
.stat-icon--green { background: #22c55e; }

.stat-label {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-top: 4px;
}

.stat-foot {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.dashboard-card .card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.card-kicker {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    font-weight: 700;
}

.card-title {
    font-weight: 800;
    font-size: 16px;
    margin-top: 2px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border-color);
    color: rgba(17, 24, 39, 0.7);
    background: rgba(17, 24, 39, 0.03);
}

.chip--muted {
    color: rgba(17, 24, 39, 0.55);
}

.chip--link {
    color: #ffffff;
    border: none;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
}

.chart-wrap {
    padding: 6px 2px 0;
}

.chart-wrap--donut {
    display: grid;
    place-items: center;
    padding-top: 14px;
}

.mini-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.mini-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot--blue { background: #4f7cff; }
.dot--purple { background: #6c5ce7; }
.dot--orange { background: #f59e0b; }
.dot--green { background: #22c55e; }

.dashboard-table thead th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    font-weight: 800;
    border-top: none;
}

.dashboard-table tbody td {
    padding-top: 12px;
    padding-bottom: 12px;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.pill--paid {
    background: rgba(34, 197, 94, 0.14);
    color: #16a34a;
}

.pill--pending {
    background: rgba(245, 158, 11, 0.14);
    color: #d97706;
}

.pill--cancel {
    background: rgba(239, 68, 68, 0.14);
    color: #dc2626;
}

.stock-summary {
    padding: 8px 2px 2px;
    display: grid;
    gap: 2px;
}

.stock-value {
    font-size: 42px;
    font-weight: 900;
    letter-spacing: -0.03em;
}

.stock-label {
    color: var(--text-secondary);
    font-weight: 700;
}

.quick-links {
    display: grid;
    gap: 10px;
    margin-top: 8px;
}

.quick-link {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(17, 24, 39, 0.02);
    color: rgba(17, 24, 39, 0.75);
    font-weight: 700;
}

.quick-link:hover {
    background: rgba(17, 24, 39, 0.05);
}

.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 2px;
}

.table-responsive .table {
    margin-bottom: 0;
}

.table-responsive .table th,
.table-responsive .table td {
    white-space: nowrap;
}

[data-theme="dark"] .table {
    --bs-table-bg: var(--bg-surface);
    --bs-table-color: var(--text-primary);
    --bs-table-striped-color: var(--text-primary);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-color: var(--text-primary);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
    --bs-table-border-color: var(--border-color);
    color: var(--text-primary);
    background-color: var(--bg-surface);
}

[data-theme="dark"] .table thead th {
    color: var(--text-primary);
}

[data-theme="dark"] .table-responsive .table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .table-responsive {
    background: var(--bg-surface);
}

[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .badge {
    color: var(--text-primary);
}

[data-theme="dark"] .dataTables_wrapper {
    color: var(--text-primary);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background-color: #1a2338;
    color: var(--text-primary);
    border-color: #32405f;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input::placeholder {
    color: var(--text-secondary);
}

[data-theme="dark"] .page-link {
    background: #1a2338;
    border-color: #32405f;
    color: var(--text-primary);
}

[data-theme="dark"] .page-link:hover {
    background: #23304a;
    color: var(--text-primary);
}

[data-theme="dark"] .page-item.disabled .page-link {
    color: rgba(238, 242, 255, 0.4);
    background: rgba(26, 35, 56, 0.6);
    border-color: #32405f;
}

[data-theme="dark"] .page-item.active .page-link {
    background: var(--accent-2);
    border-color: var(--accent-2);
    color: #ffffff;
}

[data-theme="dark"] .btn-outline-secondary {
    color: var(--text-primary);
    border-color: #475569;
}

[data-theme="dark"] .btn-outline-secondary:hover {
    background: #1f2937;
    color: var(--text-primary);
}

[data-theme="dark"] .bg-light {
    background-color: #1a2338 !important;
    color: var(--text-primary);
}

[data-theme="dark"] .bg-light .form-label,
[data-theme="dark"] .bg-light .text-muted {
    color: var(--text-secondary) !important;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 15;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

@media (max-width: 1199px) {
    .app-sidebar {
        width: 240px;
    }
}

@media (max-width: 991px) {
    .app-header {
        padding: 12px 16px;
        height: 70px;
    }
    .app-shell {
        position: relative;
        min-height: calc(100vh - 70px);
    }
    .app-sidebar {
        position: fixed;
        top: 70px;
        left: 0;
        height: calc(100vh - 70px);
        transform: translateX(-120%);
        transition: transform 0.3s ease;
        z-index: 20;
        width: min(82vw, 280px);
        box-shadow: var(--shadow-soft);
        border-radius: 0 16px 16px 0;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-content {
        padding: 18px;
    }
    .scene-grid {
        grid-template-columns: 1fr;
        gap: 26px;
        text-align: center;
    }
    .auth-panel {
        margin: 0 auto;
    }
}

@media (max-width: 767px) {
    .app-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .card,
    .login-card {
        padding: 18px;
    }
    .metric-value {
        font-size: 24px;
    }
    .table-responsive {
        margin: 0 -4px;
        padding: 4px;
    }
    .table-responsive .table {
        min-width: 520px;
    }
    .login-tablet {
        padding: 28px;
    }
}

@media (max-width: 575px) {
    .app-header .h5 {
        font-size: 1.05rem;
    }
    .app-header .fw-bold.text-uppercase {
        font-size: 0.65rem;
    }
    .btn,
    .btn-accent,
    .form-control,
    .form-select {
        font-size: 0.95rem;
    }
    .input-group .btn {
        min-width: 72px;
    }
    .login-card {
        width: min(520px, 94vw);
    }
    .login-surface {
        padding: 18px;
    }
    .login-tablet {
        border-radius: 18px;
    }
}
