/* ═══════════════════════════════════════════════════════════
   COMPONENTS — Buttons, Cards, Tables, Forms, Badges, Modals
   ═══════════════════════════════════════════════════════════ */

/* ── Brand Block ────────────────────────────────────────── */
.brand-block {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-2);
    text-decoration: none;
    color: var(--text-primary);
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-primary);
    color: #fff;
    font-weight: 800;
    font-size: var(--text-sm);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    letter-spacing: -0.5px;
    box-shadow: 0 4px 14px hsl(var(--accent-primary-hsl) / 0.35);
    overflow: hidden;
}

html[data-theme="light"] .brand-mark {
    background: linear-gradient(145deg, hsl(198.17deg 63.7% 67.69%), hsl(0deg 0% 100%) 45%, hsl(199deg 48.22% 54.96%));
    box-shadow:
        0 6px 18px hsl(221 83% 48% / 0.3),
        inset 0 1px 0 hsl(210 100% 100% / 0.28);
}

.brand-mark-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.sidebar.collapsed .brand-block > div:not(.brand-mark) {
    display: none;
}
.sidebar.collapsed .brand-block {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.brand-name {
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.2;
}

/* ── Sidebar Nav ────────────────────────────────────────── */
.nav-section {
    padding: 6px var(--space-4) 2px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 var(--space-2);
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 var(--space-3);
}

.side-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 9px var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
}

.side-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.side-link.active {
    background: var(--accent-subtle);
    color: var(--accent-primary);
    font-weight: 600;
}

.side-link .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.side-link.active .nav-icon { opacity: 1; }

.sidebar-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-3) var(--space-4);
}

.sidebar-footer {
    margin-top: auto;
    padding: var(--space-3) var(--space-3);
    border-top: 1px solid var(--border-subtle);
}

/* ── Topbar Elements ────────────────────────────────────── */
.topbar-title {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.topbar-context {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 5px var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.topbar-context:hover {
    border-color: var(--border-strong);
    background: var(--bg-hover);
}

.topbar-tenant-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 6px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1;
}

.topbar-tenant-logo-wrap {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: hsl(var(--bg-surface-hsl) / 0.96);
    border: 1px solid hsl(var(--border-subtle-hsl) / 0.7);
    flex-shrink: 0;
}

.topbar-tenant-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.topbar-tenant-text {
    white-space: nowrap;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.user-pill {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 5px var(--space-3) 5px 5px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-primary);
}

.user-pill:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-full);
    background: var(--accent-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background var(--transition-fast), border-color var(--transition-fast),
                color var(--transition-fast), box-shadow var(--transition-fast),
                transform var(--transition-fast);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 6px 20px hsl(var(--accent-primary-hsl) / 0.32);
}

.btn-secondary {
    background: var(--bg-surface);
    border-color: var(--border-strong);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

/* Invoice Detail */
.invoice-detail-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.invoice-toolbar,
.invoice-layout {
    display: grid;
    gap: 1.5rem;
}

.invoice-toolbar {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
}

.invoice-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.invoice-kicker {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.invoice-screen-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(2rem, 3vw, 2.7rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--text-primary);
}

.invoice-screen-meta {
    margin: 0.65rem 0 0;
    color: var(--text-secondary);
    font-size: 0.98rem;
}

.invoice-layout {
    grid-template-columns: minmax(0, 1fr);
}

.invoice-paper {
    position: relative;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem;
    border: 1px solid rgb(var(--border-subtle));
    border-radius: 1.4rem;
    background: #fff;
    color: #1f2937;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.invoice-paper-accent {
    position: absolute;
    inset: 0;
    border: 4px solid #7bbf53;
    border-radius: 1.4rem;
    pointer-events: none;
}

.invoice-paper-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    padding: 0.5rem 0 1.75rem;
}

.invoice-school-mark {
    width: 78px;
    height: 78px;
    border-radius: 999px;
    border: 2px dashed #7bbf53;
    display: grid;
    place-items: center;
    color: #3f6d2e;
    font-size: 1.7rem;
    font-weight: 700;
    background: rgba(123, 191, 83, 0.08);
    overflow: hidden;
}

.invoice-school-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.invoice-school-name {
    margin: 0;
    font-size: clamp(1.8rem, 2.8vw, 2.4rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    text-transform: uppercase;
    color: #315627;
}

.invoice-school-meta {
    color: #6b7280;
    font-size: 0.95rem;
    line-height: 1.55;
}

.invoice-school-meta p {
    margin: 0;
}

.invoice-billband {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    border-top: 1px solid #d9e2d3;
    border-bottom: 1px solid #d9e2d3;
}

.invoice-bill-meta,
.invoice-title-wrap {
    padding: 1.35rem 1.4rem;
}

.invoice-bill-meta {
    display: grid;
    gap: 0.9rem;
}

.invoice-title-wrap {
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-left: 1px solid #d9e2d3;
    text-align: center;
}

.invoice-keyval {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    gap: 0.75rem;
    align-items: center;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid #edf2ea;
}

.invoice-keyval span,
.invoice-type-label {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7280;
}

.invoice-keyval strong {
    font-size: 0.98rem;
    font-weight: 600;
    color: #1f2937;
}

.invoice-title {
    margin: 0.35rem 0 0;
    font-size: clamp(2rem, 3.5vw, 3rem);
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: #315627;
}

.invoice-party-grid,
.invoice-footer-grid,
.invoice-signoff {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.invoice-party-grid {
    border-bottom: 1px solid #d9e2d3;
}

.invoice-party-card {
    padding: 1.25rem 1.4rem 1.45rem;
}

.invoice-party-card + .invoice-party-card {
    border-left: 1px solid #d9e2d3;
}

.invoice-party-card h4,
.invoice-note-block h4,
.invoice-sidecard h3 {
    margin: 0 0 1rem;
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.invoice-party-card dl,
.invoice-summary-list {
    display: grid;
    gap: 0.7rem;
}

.invoice-party-card dl div,
.invoice-summary-list div {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 0.75rem;
}

.invoice-party-card dt,
.invoice-summary-list dt {
    font-weight: 700;
    color: #4b5563;
}

.invoice-party-card dd,
.invoice-summary-list dd {
    margin: 0;
    color: #1f2937;
}

.invoice-table-wrap {
    padding: 1rem 0 0;
}

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

.invoice-table th,
.invoice-table td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid #e5ece0;
    font-size: 0.96rem;
}

.invoice-table th {
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
    text-align: left;
}

.invoice-table .is-number {
    text-align: right;
    white-space: nowrap;
}

.invoice-empty,
.invoice-empty-side {
    color: #6b7280;
    text-align: center;
}

.invoice-footer-grid {
    gap: 1.5rem;
    padding: 1.3rem 0 0;
    align-items: start;
}

.invoice-note-block {
    padding-right: 1rem;
}

.invoice-note-block p {
    margin: 0;
    color: #6b7280;
    font-size: 0.93rem;
    line-height: 1.6;
}

.invoice-guardian-line {
    margin-top: 0.85rem !important;
    color: #374151 !important;
    font-weight: 600;
}

.invoice-total-card {
    margin-left: auto;
    width: min(100%, 320px);
}

.invoice-total-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid #e5ece0;
    font-size: 0.96rem;
}

.invoice-total-row span {
    color: #4b5563;
}

.invoice-total-row strong {
    white-space: nowrap;
    color: #111827;
}

.invoice-total-row.is-grand {
    margin-top: 0.25rem;
    font-size: 1.08rem;
    font-weight: 800;
}

.invoice-total-row.is-balance {
    font-size: 1.08rem;
    font-weight: 800;
    color: #315627;
}

.invoice-total-row.is-balance strong,
.invoice-total-row.is-balance span {
    color: #315627;
}

.invoice-signoff {
    gap: 2rem;
    padding-top: 4.5rem;
}

.invoice-signature {
    border-top: 1px solid #9ca3af;
    padding-top: 0.5rem;
    text-align: center;
    font-size: 0.88rem;
    font-weight: 700;
    color: #374151;
}

.invoice-sidepanel {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.invoice-sidecard {
    padding: 1.35rem;
}

.invoice-status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    background: rgba(123, 191, 83, 0.14);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.invoice-summary-list {
    margin-top: 1rem;
}

.invoice-summary-list dd {
    text-align: right;
    font-weight: 700;
}

.invoice-payments-list {
    display: grid;
    gap: 0.85rem;
}

.invoice-payment-item {
    border: 1px solid rgb(var(--border-subtle));
    border-radius: 0.9rem;
    padding: 0.9rem 1rem;
}

.invoice-payment-item p {
    margin: 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-weight: 700;
}

.invoice-payment-item p span {
    color: var(--text-secondary);
    font-weight: 600;
}

html[data-theme="dark"] .invoice-sidecard h3,
html[data-theme="dark"] .invoice-sidecard .invoice-status-pill,
html[data-theme="dark"] .invoice-sidecard .invoice-summary-list dd,
html[data-theme="dark"] .invoice-sidecard .invoice-payment-item p {
    color: var(--text-primary);
}

html[data-theme="dark"] .invoice-sidecard .invoice-summary-list dt,
html[data-theme="dark"] .invoice-sidecard .invoice-payment-item p span {
    color: var(--text-secondary);
}

.invoice-payment-item small {
    display: block;
    margin-top: 0.3rem;
    color: var(--text-muted);
}

@media (min-width: 1100px) {
    .invoice-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .invoice-toolbar-actions {
        justify-content: flex-end;
    }

    .invoice-layout {
        grid-template-columns: minmax(0, 1fr) 300px;
        align-items: start;
    }

    .invoice-paper {
        margin: 0;
    }
}

@media (max-width: 900px) {
    .invoice-paper {
        padding: 1.2rem;
    }

    .invoice-billband,
    .invoice-party-grid,
    .invoice-footer-grid,
    .invoice-signoff {
        grid-template-columns: minmax(0, 1fr);
    }

    .invoice-title-wrap,
    .invoice-party-card + .invoice-party-card {
        border-left: 0;
        border-top: 1px solid #d9e2d3;
    }

    .invoice-total-card {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .invoice-toolbar-actions {
        width: 100%;
    }

    .invoice-toolbar-actions > * {
        flex: 1 1 100%;
    }

    .invoice-keyval,
    .invoice-party-card dl div,
    .invoice-summary-list div {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.25rem;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 0.8rem 0.65rem;
        font-size: 0.88rem;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 8mm;
    }

    html,
    body {
        background: #fff !important;
        width: 210mm;
        height: auto;
    }

    body {
        margin: 0 !important;
        padding: 0 !important;
    }

    .app-atmosphere,
    .sidebar,
    .topbar,
    .toast-container,
    .invoice-toolbar,
    .invoice-sidepanel,
    .no-print {
        display: none !important;
    }

    .app-shell,
    .main-shell,
    .page-body,
    .invoice-detail-page,
    .invoice-layout {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .main-shell {
        margin-left: 0 !important;
    }

    .invoice-detail-page {
        gap: 0 !important;
    }

    .invoice-paper {
        width: 194mm !important;
        max-width: 194mm !important;
        margin: 0 auto !important;
        padding: 6mm 4.5mm 5mm !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
        color: #111827 !important;
        font-size: 11.5px !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .invoice-paper-accent {
        inset: 1mm !important;
        border-width: 2px !important;
        border-radius: 0 !important;
    }

    .invoice-paper-header {
        gap: 0.45rem !important;
        padding: 0.45rem 0 0.9rem !important;
    }

    .invoice-school-mark {
        width: 58px !important;
        height: 58px !important;
        font-size: 1.2rem !important;
        overflow: visible !important;
    }

    .invoice-school-name {
        font-size: 1.55rem !important;
    }

    .invoice-school-meta {
        font-size: 0.82rem !important;
        line-height: 1.35 !important;
    }

    .invoice-bill-meta,
    .invoice-title-wrap,
    .invoice-party-card {
        padding: 0.7rem 0.85rem !important;
    }

    .invoice-keyval,
    .invoice-party-card dl div {
        gap: 0.5rem !important;
    }

    .invoice-title {
        font-size: 2rem !important;
    }

    .invoice-party-card h4,
    .invoice-note-block h4 {
        margin-bottom: 0.55rem !important;
        font-size: 0.8rem !important;
    }

    .invoice-party-card dl,
    .invoice-summary-list {
        gap: 0.42rem !important;
    }

    .invoice-table-wrap {
        padding-top: 0.45rem !important;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 0.52rem 0.7rem !important;
        font-size: 0.82rem !important;
    }

    .invoice-footer-grid {
        gap: 0.55rem !important;
        padding-top: 0.45rem !important;
    }

    .invoice-note-block p {
        font-size: 0.74rem !important;
        line-height: 1.22 !important;
    }

    .invoice-total-card {
        width: 100% !important;
        max-width: 265px !important;
    }

    .invoice-total-row {
        padding: 0.18rem 0 !important;
        font-size: 0.78rem !important;
    }

    .invoice-total-row.is-grand,
    .invoice-total-row.is-balance {
        font-size: 0.86rem !important;
    }

    .invoice-signoff {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
        padding-top: 0.85rem !important;
        align-items: end !important;
    }

    .invoice-signature {
        padding-top: 0.32rem !important;
        font-size: 0.72rem !important;
        line-height: 1.2 !important;
        min-height: 0 !important;
        text-align: center !important;
        display: block !important;
        width: 100% !important;
    }

    .invoice-billband,
    .invoice-party-grid,
    .invoice-footer-grid,
    .invoice-signoff,
    .invoice-table,
    .invoice-table tr,
    .invoice-table td,
    .invoice-table th {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-sm {
    padding: 5px var(--space-3);
    font-size: var(--text-xs);
}

.btn-icon {
    padding: 8px;
    width: 34px;
    height: 34px;
    justify-content: center;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-base), border-color var(--transition-base),
                transform var(--transition-base);
}

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

html[data-theme="light"] .card {
    background: linear-gradient(
        155deg,
        hsl(210 80% 100% / 0.88) 0%,
        hsl(214 55% 99% / 0.72) 45%,
        hsl(218 48% 97.5% / 0.68) 100%
    );
    border: 1px solid hsl(214 45% 100% / 0.65);
    box-shadow:
        0 8px 32px hsl(225 35% 22% / 0.1),
        0 2px 8px hsl(220 50% 50% / 0.04),
        inset 0 1px 0 hsl(0 0% 100% / 0.95),
        inset 0 0 0 1px hsl(200 90% 98% / 0.35);
    backdrop-filter: blur(18px) saturate(1.18);
    -webkit-backdrop-filter: blur(18px) saturate(1.18);
}

html[data-theme="light"] .card:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.28);
    box-shadow:
        0 14px 44px hsl(225 40% 24% / 0.12),
        0 0 0 1px hsl(var(--accent-primary-hsl) / 0.1),
        inset 0 1px 0 hsl(0 0% 100% / 1);
}

.card-interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-body { padding: var(--space-5); }
.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.card-footer {
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.card-title {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Metric / KPI Cards ─────────────────────────────────── */
.metric-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-base), border-color var(--transition-base),
                transform var(--transition-base);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.metric-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

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

.metric-label {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.metric-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font-size: 16px;
}

.metric-value {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.5px;
}

.metric-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.metric-delta {
    font-size: var(--text-xs);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

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

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table thead {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
    padding: 10px var(--space-4);
    text-align: left;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}

.data-table td {
    padding: 11px var(--space-4);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.table-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

/* ── Forms ──────────────────────────────────────────────── */
.form-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}

.form-section {
    padding: var(--space-5);
}

.form-section + .form-section {
    border-top: 1px solid var(--border-subtle);
}

.form-section-title {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-full { grid-column: 1 / -1; }

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.field label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.field label .required {
    color: var(--danger);
    margin-left: 2px;
}

.field input,
.field select,
.field textarea {
    padding: 8px var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
    width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

.field input::placeholder,
.field textarea::placeholder {
    color: var(--text-muted);
}

.field textarea { resize: vertical; min-height: 90px; }

.field-help {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.field-error {
    font-size: var(--text-xs);
    color: var(--danger);
}

.field input.error,
.field select.error,
.field textarea.error {
    border-color: var(--danger);
}

/* Django form auto-render compatibility */
.field p { margin: 0; }
.field ul.errorlist {
    list-style: none;
    padding: 0;
    margin: 0;
}
.field ul.errorlist li {
    font-size: var(--text-xs);
    color: var(--danger);
}

/* ── Badges / Status Pills ──────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-default  { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-subtle); }
.badge-primary  { background: var(--accent-subtle); color: var(--accent-primary); }
.badge-success  { background: var(--success-subtle); color: var(--success); }
.badge-warning  { background: var(--warning-subtle); color: var(--warning); }
.badge-danger   { background: var(--danger-subtle); color: var(--danger); }
.badge-info     { background: var(--info-subtle); color: var(--info); }

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    border: 1px solid transparent;
}

.alert-success { background: var(--success-subtle); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-subtle); border-color: var(--warning); color: var(--warning); }
.alert-danger  { background: var(--danger-subtle);  border-color: var(--danger);  color: var(--danger); }
.alert-info    { background: var(--info-subtle);    border-color: var(--info);    color: var(--info); }

/* ── Dropdown ───────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--space-1);
    z-index: 200;
    display: none;
    animation: dropIn 140ms ease;
}

.dropdown-menu.open { display: block; }

@keyframes dropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px var(--space-3);
    border-radius: var(--radius-xs);
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-sans);
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border-subtle); margin: var(--space-1) 0; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 300;
    display: none;
    place-items: center;
    padding: var(--space-4);
}

.modal-backdrop.open { display: grid; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    animation: modalIn 180ms ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-size: var(--text-md); font-weight: 700; }
.modal-body  { padding: var(--space-5); }
.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* ── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.filter-bar input,
.filter-bar select {
    padding: 7px var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filter-bar input:focus,
.filter-bar select:focus {
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

.filter-bar input { min-width: 220px; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.page-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-link.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-9) var(--space-6);
    text-align: center;
    gap: var(--space-3);
}

.empty-icon {
    font-size: 2.5rem;
    opacity: 0.3;
}

.empty-title {
    font-size: var(--text-md);
    font-weight: 700;
    color: var(--text-primary);
}

.empty-desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    max-width: 320px;
}

/* ── Breadcrumb ─────────────────────────────────────────── */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb a:hover { color: var(--accent-primary); }
.breadcrumb-sep { opacity: 0.4; }
.breadcrumb-current { color: var(--text-secondary); font-weight: 500; }

/* ── Tabs ───────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-5);
}

.tab-link {
    padding: 9px var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition-fast), border-color var(--transition-fast);
    white-space: nowrap;
}

.tab-link:hover { color: var(--text-primary); }
.tab-link.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: 600;
}

/* ── Detail Row ─────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.detail-value {
    font-size: var(--text-sm);
    color: var(--text-primary);
    font-weight: 500;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    font-weight: 500;
    pointer-events: all;
    animation: toastIn 200ms ease;
    min-width: 260px;
    max-width: 380px;
}

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

/* ── Misc ───────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-subtle); margin: var(--space-5) 0; }

.text-muted    { color: var(--text-muted); }
.text-secondary{ color: var(--text-secondary); }
.text-primary  { color: var(--text-primary); }
.text-accent   { color: var(--accent-primary); }
.text-success  { color: var(--success); }
.text-warning  { color: var(--warning); }
.text-danger   { color: var(--danger); }

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.fs-xs  { font-size: var(--text-xs); }
.fs-sm  { font-size: var(--text-sm); }
.fs-md  { font-size: var(--text-md); }

/* ── Responsive form grid ───────────────────────────────── */
@media (max-width: 768px) {
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar input { min-width: unset; width: 100%; }
    .modal { max-width: 100%; }
}

/* ── Shared input class applied via Django widget attrs ─── */
.field-input,
input.field-input,
select.field-input,
textarea.field-input {
    display: block;
    width: 100%;
    padding: 9px var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    line-height: 1.5;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
                background var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

.field-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
    background: var(--bg-surface);
}

.field-input::placeholder { color: var(--text-muted); }

select.field-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}

textarea.field-input {
    resize: vertical;
    min-height: 90px;
}

/* Login page specific input */
.login-input {
    display: block;
    width: 100%;
    padding: 10px var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.login-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

.login-input::placeholder { color: var(--text-muted); }

/* Checkbox styling */
input[type="checkbox"].field-input {
    width: 16px;
    height: 16px;
    padding: 0;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* ── Sidebar Expand/Collapse Accordion ───────────────────── */
.side-nav-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.side-nav-wrapper.expanded {
    grid-template-rows: 1fr;
}
.side-nav-inner {
    overflow: hidden;
}
.nav-section-label-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px var(--space-2);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    transition: color 150ms ease;
    border-radius: var(--radius-sm);
}
.nav-section-label-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.nav-section-label-btn .chevron {
    width: 14px;
    height: 14px;
    transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.7;
}
.nav-section-label-btn[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}


/* ── Sidebar Collapsed Floating Nav ─────────────────────── */
.sidebar-scroll-area {
    overflow-y: auto;
    overflow-x: hidden;
    /* Hide scrollbar universally for elegance */
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.sidebar-scroll-area::-webkit-scrollbar {
    width: 0px;
    background: transparent;
    display: none;
}

/* Ensure no clipping in collapsed mode */
.sidebar.collapsed,
.sidebar.collapsed .sidebar-scroll-area {
    overflow: visible !important;
}

/* Expanded state icon alignments */
.nav-section-label-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    transition: all 150ms ease;
    margin-bottom: 2px;
}
.nav-section-label-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.nav-section-label-btn .section-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
}
/* Ensure the text expands to push chevron to the right */
.nav-section-label-btn span {
    flex: 1;
    text-align: left;
}

/* Collapsed state adjustments */
.sidebar.collapsed .nav-section-label-btn span {
    display: none;
}
.sidebar.collapsed .nav-section-label-btn .chevron {
    display: none;
}
.sidebar.collapsed .nav-section-label-btn {
    justify-content: center;
    padding: 12px;
}
.sidebar.collapsed .nav-section-label-btn .section-icon {
    width: 22px;
    height: 22px;
}

.sidebar.collapsed .nav-section {
    position: relative;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin: 4px 8px;
}

/* Floating Submenu (Triggered by .expanded class when clicked/pressed or hover) */
.sidebar.collapsed .side-nav-wrapper {
    position: absolute;
    left: calc(100% + 4px);
    top: 0;
    width: 240px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-8px);
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    /* Escape grid constraints */
    height: auto !important;
    grid-template-rows: none !important;
    display: block;
}

/* Activate popout exclusively on hover when collapsed */
.sidebar.collapsed .nav-section:hover .side-nav-wrapper {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
}

.sidebar.collapsed .side-nav-inner {
    padding: var(--space-2);
}
.sidebar.collapsed .side-nav-inner .side-link span {
    display: inline-block !important; /* Force text visible in popup */
}
.sidebar.collapsed .side-nav-inner .side-link {
    padding: 9px 12px;
    justify-content: flex-start;
}

/* Dashboard standalone button fixes */
.sidebar.collapsed .side-link {
    justify-content: center;
    padding: 12px;
    margin: 4px 8px;
}
.sidebar.collapsed .side-link span,
.sidebar.collapsed .nav-section-label {
    display: none;
}
.sidebar.collapsed .side-link .nav-icon {
    width: 22px;
    height: 22px;
    margin: 0;
}

/* Enterprise soft cards for admin-heavy screens */
.ui-card.soft-card,
.soft-panel {
    border: 0 !important;
    border-radius: var(--radius-lg);
    background: linear-gradient(
        160deg,
        hsl(var(--bg-surface-hsl) / 0.96),
        hsl(var(--bg-elevated-hsl) / 0.88)
    );
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}

.soft-panel {
    overflow: hidden;
}

.soft-divider {
    border-color: hsl(var(--border-subtle-hsl) / 0.45) !important;
}

.soft-filter .ui-input,
.soft-filter .field-input {
    border-color: hsl(var(--border-subtle-hsl) / 0.6);
    background: hsl(var(--bg-surface-hsl) / 0.72);
}

.soft-pill {
    border: 0 !important;
    background: hsl(var(--bg-elevated-hsl) / 0.8);
}

.soft-table {
    border: 0 !important;
    border-radius: var(--radius-lg);
    background: linear-gradient(
        165deg,
        hsl(var(--bg-surface-hsl) / 0.94),
        hsl(var(--bg-elevated-hsl) / 0.82)
    );
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
}

.soft-table table thead,
.soft-table .data-table thead {
    border-bottom: 0;
    background: hsl(var(--bg-elevated-hsl) / 0.52);
}

.soft-table table tbody tr,
.soft-table .data-table tbody tr {
    border-color: hsl(var(--border-subtle-hsl) / 0.4);
}

.soft-choice-tile {
    border: 0 !important;
    background: hsl(var(--bg-app-hsl) / 0.34);
    box-shadow: inset 0 0 0 1px hsl(var(--border-subtle-hsl) / 0.38);
}

.soft-choice-tile:hover {
    background: hsl(var(--bg-hover-hsl) / 0.5);
    box-shadow: inset 0 0 0 1px hsl(var(--accent-primary-hsl) / 0.35);
}    

/* Light theme UI overhaul — glossy glass panels */
html[data-theme="light"] .ui-card,
html[data-theme="light"] .ui-panel {
    border-radius: var(--radius-lg);
    border: 1px solid hsl(214 50% 100% / 0.55);
    background:
        linear-gradient(168deg, hsl(210 90% 100% / 0.82) 0%, hsl(214 65% 99% / 0.58) 42%, hsl(220 55% 97% / 0.52) 100%),
        linear-gradient(90deg, hsl(218 100% 70% / 0.06) 0%, transparent 55%);
    box-shadow:
        0 20px 50px hsl(225 38% 22% / 0.11),
        0 4px 16px hsl(220 60% 50% / 0.06),
        inset 0 1px 0 hsl(0 0% 100% / 0.98),
        inset 0 0 0 1px hsl(200 100% 99% / 0.45);
    backdrop-filter: blur(22px) saturate(1.22);
    -webkit-backdrop-filter: blur(22px) saturate(1.22);
    transition: border-color var(--transition-base), box-shadow var(--transition-base), transform var(--transition-base);
    padding: 25px var(--space-5);
}

html[data-theme="light"] .ui-card:hover,
html[data-theme="light"] .ui-panel:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.32);
    box-shadow:
        0 26px 60px hsl(225 42% 22% / 0.14),
        0 0 40px hsl(218 90% 58% / 0.08),
        inset 0 1px 0 hsl(0 0% 100% / 1),
        inset 0 0 0 1px hsl(214 80% 98% / 0.55);
}

html[data-theme="light"] .ui-card.soft-card,
html[data-theme="light"] .soft-panel {
    border: 1px solid hsl(214 60% 100% / 0.4) !important;
    background:
        linear-gradient(148deg, hsl(208 95% 100% / 0.88) 0%, hsl(214 85% 98% / 0.72) 40%, hsl(220 70% 96.5% / 0.65) 100%),
        radial-gradient(120% 80% at 100% 0%, hsl(218 100% 70% / 0.12), transparent 55%),
        radial-gradient(90% 60% at 0% 100%, hsl(198 90% 65% / 0.1), transparent 50%);
    box-shadow:
        0 24px 56px hsl(226 40% 22% / 0.12),
        inset 0 1px 0 hsl(0 0% 100% / 0.95),
        inset 0 0 0 1px hsl(210 100% 100% / 0.35);
    backdrop-filter: blur(24px) saturate(1.28);
    -webkit-backdrop-filter: blur(24px) saturate(1.28);
    margin-bottom: 1rem;
}

html[data-theme="light"] .soft-divider {
    border-color: hsl(var(--border-subtle-hsl) / 0.32) !important;
}

/* Dark theme UI — soft, muted card borders for a clean look */
html[data-theme="dark"] .ui-card,
html[data-theme="dark"] .ui-panel {
    border: 1px solid hsl(var(--border-subtle-hsl) / 0.45);
    box-shadow: 0 8px 24px hsl(222 50% 4% / 0.35);
}

html[data-theme="dark"] .ui-card:hover,
html[data-theme="dark"] .ui-panel:hover {
    border-color: hsl(var(--border-subtle-hsl) / 0.65);
    box-shadow: 0 12px 32px hsl(222 50% 4% / 0.45);
}

html[data-theme="dark"] .ui-card.soft-card,
html[data-theme="dark"] .soft-panel {
    border: 1px solid hsl(var(--border-subtle-hsl) / 0.3) !important;
    box-shadow: 0 16px 40px hsl(222 50% 4% / 0.4);
    margin-bottom: 1rem;
}

html[data-theme="dark"] .soft-divider {
    border-color: hsl(var(--border-subtle-hsl) / 0.3) !important;
}

html[data-theme="dark"] .soft-table {
    box-shadow: 0 14px 36px hsl(222 50% 4% / 0.35);
}

html[data-theme="light"] .ui-btn-primary {
    border: 1px solid hsl(215 85% 42% / 0.35);
    background: linear-gradient(
        145deg,
        hsl(204 95% 58%) 0%,
        hsl(214 90% 52%) 28%,
        hsl(var(--accent-primary-hsl)) 55%,
        hsl(228 75% 48%) 100%
    );
    box-shadow:
        0 12px 28px hsl(var(--accent-primary-hsl) / 0.38),
        0 4px 12px hsl(200 100% 50% / 0.15),
        inset 0 1px 0 hsl(0 0% 100% / 0.35),
        inset 0 -1px 0 hsl(230 60% 30% / 0.12);
}

html[data-theme="light"] .ui-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow:
        0 16px 38px hsl(var(--accent-primary-hsl) / 0.42),
        0 0 24px hsl(210 100% 60% / 0.2),
        inset 0 1px 0 hsl(0 0% 100% / 0.45);
}

html[data-theme="light"] .ui-btn-secondary {
    border: 1px solid hsl(214 35% 90% / 0.95);
    background: linear-gradient(
        185deg,
        hsl(210 80% 100% / 0.9) 0%,
        hsl(214 50% 98% / 0.75) 100%
    );
    color: var(--text-primary);
    box-shadow:
        0 6px 18px hsl(220 35% 25% / 0.07),
        inset 0 1px 0 hsl(0 0% 100% / 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

html[data-theme="light"] .ui-btn-secondary:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.38);
    color: hsl(var(--accent-primary-hsl));
    background: linear-gradient(185deg, hsl(214 100% 99.5% / 0.95), hsl(var(--accent-subtle-hsl) / 0.85));
    box-shadow:
        0 10px 24px hsl(218 50% 40% / 0.1),
        inset 0 1px 0 hsl(0 0% 100% / 1);
}

html[data-theme="light"] .ui-input,
html[data-theme="light"] .field-input {
    border-color: hsl(var(--border-subtle-hsl) / 0.78);
    background: linear-gradient(180deg, hsl(var(--bg-surface-hsl) / 0.9), hsl(var(--bg-elevated-hsl) / 0.86));
    box-shadow: inset 0 1px 0 hsl(0 0% 100% / 0.75);
}

html[data-theme="light"] .ui-input:focus,
html[data-theme="light"] .field-input:focus {
    border-color: hsl(var(--accent-primary-hsl) / 0.6);
    box-shadow:
        0 0 0 4px hsl(var(--accent-primary-hsl) / 0.14),
        inset 0 1px 0 hsl(0 0% 100% / 0.9);
}

html[data-theme="light"] .soft-filter .ui-input,
html[data-theme="light"] .soft-filter .field-input {
    border-color: hsl(var(--border-subtle-hsl) / 0.66);
    background: linear-gradient(180deg, hsl(var(--bg-surface-hsl) / 0.94), hsl(var(--bg-elevated-hsl) / 0.9));
}

html[data-theme="light"] .soft-table {
    border: 1px solid hsl(214 50% 100% / 0.5) !important;
    border-radius: var(--radius-lg);
    background:
        linear-gradient(162deg, hsl(210 85% 100% / 0.82) 0%, hsl(218 48% 97% / 0.62) 100%),
        radial-gradient(80% 50% at 100% 0%, hsl(218 90% 70% / 0.08), transparent 60%);
    box-shadow:
        0 22px 52px hsl(225 40% 22% / 0.11),
        inset 0 1px 0 hsl(0 0% 100% / 0.92);
    backdrop-filter: blur(22px) saturate(1.2);
    -webkit-backdrop-filter: blur(22px) saturate(1.2);
}

html[data-theme="light"] .soft-table table thead,
html[data-theme="light"] .soft-table .data-table thead {
    background: linear-gradient(180deg, hsl(214 55% 98% / 0.95), hsl(213 32% 96% / 0.92));
}

html[data-theme="light"] .soft-table table tbody tr,
html[data-theme="light"] .soft-table .data-table tbody tr {
    border-color: hsl(var(--border-subtle-hsl) / 0.4);
}

html[data-theme="light"] .soft-table table tbody tr:hover,
html[data-theme="light"] .soft-table .data-table tbody tr:hover {
    background: hsl(var(--accent-primary-hsl) / 0.05);
}

html[data-theme="light"] .icon-btn,
html[data-theme="light"] .topbar-context,
html[data-theme="light"] .topbar-tenant-badge,
html[data-theme="light"] .user-pill {
    border-color: hsl(214 40% 92% / 0.9);
    background: linear-gradient(
        165deg,
        hsl(210 70% 100% / 0.82) 0%,
        hsl(214 45% 98% / 0.65) 100%
    );
    box-shadow:
        0 4px 14px hsl(220 32% 22% / 0.07),
        inset 0 1px 0 hsl(0 0% 100% / 0.88);
    backdrop-filter: blur(12px) saturate(1.1);
    -webkit-backdrop-filter: blur(12px) saturate(1.1);
}

html[data-theme="light"] .icon-btn:hover,
html[data-theme="light"] .topbar-context:hover,
html[data-theme="light"] .topbar-tenant-badge:hover,
html[data-theme="light"] .user-pill:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.28);
    background: linear-gradient(165deg, hsl(214 90% 100% / 0.92), hsl(218 60% 98% / 0.78));
    box-shadow:
        0 8px 20px hsl(218 45% 35% / 0.1),
        inset 0 1px 0 hsl(0 0% 100% / 1);
}

html[data-theme="light"] .topbar-tenant-logo-wrap {
    background: linear-gradient(180deg, hsl(0 0% 100% / 0.96), hsl(214 30% 97% / 0.88));
    border-color: hsl(214 35% 88% / 0.8);
    box-shadow: inset 0 1px 0 hsl(0 0% 100% / 0.92);
}

html[data-theme="light"] .side-link.active {
    background: linear-gradient(
        95deg,
        hsl(var(--accent-primary-hsl) / 0.22) 0%,
        hsl(204 85% 52% / 0.1) 45%,
        hsl(var(--accent-primary-hsl) / 0.06) 100%
    );
    color: hsl(var(--accent-primary-hsl));
    box-shadow:
        inset 3px 0 0 hsl(var(--accent-primary-hsl)),
        inset 0 0 0 1px hsl(var(--accent-primary-hsl) / 0.16),
        inset 0 1px 0 hsl(0 0% 100% / 0.45);
}

/* ── Light mode — premium surfaces (forms, tables, modals, chrome) ── */
html[data-theme="light"] .btn-primary {
    border-color: hsl(var(--accent-primary-hsl) / 0.35);
    background: linear-gradient(
        135deg,
        hsl(210 88% 53%) 0%,
        hsl(var(--accent-primary-hsl)) 50%,
        hsl(226 76% 45%) 100%
    );
    box-shadow:
        0 8px 22px hsl(var(--accent-primary-hsl) / 0.28),
        inset 0 1px 0 hsl(0 0% 100% / 0.2);
}

html[data-theme="light"] .btn-primary:hover {
    box-shadow:
        0 12px 28px hsl(var(--accent-primary-hsl) / 0.34),
        inset 0 1px 0 hsl(0 0% 100% / 0.25);
}

html[data-theme="light"] .btn-secondary {
    border-color: hsl(var(--border-subtle-hsl) / 0.9);
    background: linear-gradient(180deg, hsl(var(--bg-surface-hsl)), hsl(var(--bg-elevated-hsl) / 0.98));
    box-shadow: var(--shadow-xs), inset 0 1px 0 hsl(0 0% 100% / 0.85);
}

html[data-theme="light"] .btn-secondary:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.35);
    color: hsl(var(--accent-primary-hsl));
}

html[data-theme="light"] .form-card {
    border: 1px solid hsl(214 45% 100% / 0.55);
    background: linear-gradient(
        168deg,
        hsl(210 85% 100% / 0.85) 0%,
        hsl(214 55% 98.5% / 0.7) 100%
    );
    box-shadow:
        0 12px 36px hsl(225 36% 22% / 0.09),
        inset 0 1px 0 hsl(0 0% 100% / 0.92);
    backdrop-filter: blur(20px) saturate(1.15);
    -webkit-backdrop-filter: blur(20px) saturate(1.15);
}

html[data-theme="light"] .table-wrap {
    border: 1px solid hsl(214 45% 100% / 0.5);
    background: linear-gradient(
        175deg,
        hsl(210 80% 100% / 0.86) 0%,
        hsl(216 50% 98% / 0.68) 100%
    );
    box-shadow:
        0 14px 40px hsl(225 38% 22% / 0.1),
        inset 0 1px 0 hsl(0 0% 100% / 0.9);
    backdrop-filter: blur(20px) saturate(1.18);
    -webkit-backdrop-filter: blur(20px) saturate(1.18);
}

html[data-theme="light"] .data-table thead {
    background: linear-gradient(180deg, hsl(214 50% 98% / 0.96), hsl(213 30% 96% / 0.93));
    border-bottom: 1px solid hsl(var(--border-subtle-hsl) / 0.65);
}

html[data-theme="light"] .data-table th {
    color: hsl(var(--text-secondary-hsl) / 0.92);
    letter-spacing: 0.06em;
}

html[data-theme="light"] .data-table tbody tr:hover {
    background: linear-gradient(90deg, hsl(var(--accent-primary-hsl) / 0.07), hsl(204 70% 50% / 0.04));
}

html[data-theme="light"] .metric-card {
    border: 1px solid hsl(214 45% 100% / 0.5);
    background: linear-gradient(
        152deg,
        hsl(210 78% 100% / 0.9) 0%,
        hsl(216 52% 98.5% / 0.74) 100%
    );
    box-shadow:
        0 12px 36px hsl(225 36% 22% / 0.09),
        inset 0 1px 0 hsl(0 0% 100% / 0.92);
    backdrop-filter: blur(16px) saturate(1.18);
    -webkit-backdrop-filter: blur(16px) saturate(1.18);
}

html[data-theme="light"] .metric-card:hover {
    border-color: hsl(var(--accent-primary-hsl) / 0.28);
    box-shadow:
        0 18px 44px hsl(225 40% 22% / 0.12),
        0 0 28px hsl(218 90% 58% / 0.06),
        inset 0 1px 0 hsl(0 0% 100% / 1);
}

html[data-theme="light"] .metric-value {
    font-family: var(--font-display);
    letter-spacing: -0.03em;
}

html[data-theme="light"] .modal-backdrop {
    background: hsl(226 32% 12% / 0.48);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

html[data-theme="light"] .modal {
    border: 1px solid hsl(214 50% 100% / 0.55);
    box-shadow:
        var(--shadow-lg),
        0 0 60px hsl(218 80% 55% / 0.08),
        inset 0 1px 0 hsl(0 0% 100% / 0.95);
    background: linear-gradient(
        175deg,
        hsl(210 85% 100% / 0.95) 0%,
        hsl(214 50% 98.5% / 0.92) 100%
    );
    backdrop-filter: blur(24px) saturate(1.15);
    -webkit-backdrop-filter: blur(24px) saturate(1.15);
}

html[data-theme="light"] .modal-title {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

html[data-theme="light"] .tabs {
    border-bottom-color: hsl(var(--border-subtle-hsl) / 0.75);
    gap: 4px;
}

html[data-theme="light"] .tab-link.active {
    color: hsl(var(--accent-primary-hsl));
    border-bottom-width: 3px;
    border-bottom-color: hsl(var(--accent-primary-hsl));
    font-weight: 600;
}

html[data-theme="light"] .badge-default {
    border: 1px solid hsl(var(--border-subtle-hsl) / 0.85);
    background: hsl(var(--bg-elevated-hsl) / 0.95);
}

html[data-theme="light"] .badge-primary {
    border: 1px solid hsl(var(--accent-primary-hsl) / 0.2);
}

html[data-theme="light"] .badge-success,
html[data-theme="light"] .badge-warning,
html[data-theme="light"] .badge-danger,
html[data-theme="light"] .badge-info {
    border: 1px solid hsl(var(--border-subtle-hsl) / 0.35);
}

html[data-theme="light"] .empty-state {
    border-radius: var(--radius-lg);
    border: 1px dashed hsl(var(--border-subtle-hsl) / 0.85);
    background: linear-gradient(165deg, hsl(var(--bg-surface-hsl) / 0.6), hsl(var(--accent-subtle-hsl) / 0.35));
}

html[data-theme="light"] .empty-icon {
    opacity: 0.55;
    filter: saturate(1.1);
}

html[data-theme="light"] .toast {
    border-color: hsl(var(--border-subtle-hsl) / 0.7);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(180deg, hsl(var(--bg-surface-hsl) / 0.98), hsl(var(--bg-elevated-hsl) / 0.96));
}

html[data-theme="light"] .user-avatar {
    background: linear-gradient(145deg, hsl(218 85% 51%), hsl(221 83% 46%) 55%, hsl(199 65% 40%));
    box-shadow: 0 4px 12px hsl(var(--accent-primary-hsl) / 0.28);
}

html[data-theme="light"] .dropdown-menu {
    border-color: hsl(var(--border-subtle-hsl) / 0.75);
    box-shadow: var(--shadow-md);
    background: linear-gradient(180deg, hsl(var(--bg-surface-hsl)), hsl(var(--bg-elevated-hsl) / 0.98));
}

html[data-theme="light"] .nav-section-label-btn:hover {
    color: hsl(var(--accent-primary-hsl));
}

html[data-theme="light"] .side-link:hover {
    background: hsl(var(--accent-primary-hsl) / 0.06);
}

html[data-theme="light"] .ui-skeleton {
    background-color: hsl(var(--bg-elevated-hsl));
}

html[data-theme="light"] .icon-btn:focus-visible,
html[data-theme="light"] .btn:focus-visible,
html[data-theme="light"] .side-link:focus-visible,
html[data-theme="light"] .nav-section-label-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

html[data-theme="light"] .card-title,
html[data-theme="light"] .form-section-title {
    font-family: var(--font-display);
    letter-spacing: -0.015em;
}
