/*
 * myShopping IT admin design system.
 *
 * Structurally adapted from the sidebar-shell architecture proven in the
 * PSC Psychology admin (packages/myshoppingit/psych-vertical/resources/css/
 * psych-admin.css) — a two-variable token system (--color-primary /
 * --color-accent) with the entire tint/shade palette derived at load time
 * via color-mix(), so re-skinning only ever touches two values, never a
 * scattered set of hardcoded hex codes.
 *
 * Brand mapping (not a copy of PSC's palette): PSC's sidebar is teal
 * (their brand primary) with gold as the accent/active-state color.
 * myShopping IT's own design system is blue #032366 + near-black #1D1D1F —
 * mapped here as near-black sidebar (primary) with blue as the accent
 * used for active nav state, links, and primary actions.
 */
:root {
    --color-primary: #032366 ;
    --color-accent: #1D1D1F;
    --font-base: 'Inter', ui-sans-serif, system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    /* Sidebar tokens */
    --sb-width: 240px;
    --sb-bg: var(--color-primary);
    --sb-border: rgba(255, 255, 255, .08);
    --sb-text: rgba(255, 255, 255, .82);
    --sb-text-active: #ffffff;
    --sb-hover-bg: rgba(255, 255, 255, .06);
    --sb-active-bg: color-mix(in srgb, var(--color-accent) 24%, var(--color-primary));
    --sb-active-rule: var(--color-accent);

    /* Surface */
    --surface: #F5F6F8;
    --surface-card: #ffffff;
    --border-ui: #E5E7EA;

    /* Brand tints — all derived from --color-accent */
    --brand: var(--color-accent);
    --brand-mid: color-mix(in srgb, var(--color-accent) 85%, black);
    --brand-light: color-mix(in srgb, var(--color-accent) 15%, white);
    --brand-pale: color-mix(in srgb, var(--color-accent) 6%, white);

    --ink: #1D1D1F;
    --ink-muted: #55555A;
    --ink-faint: #9A9A9E;

    --success: #1E8A47;
    --success-pale: #E4F5EA;
    --warning: #A66A10;
    --warning-pale: #FDF3E3;
    --danger: #B13232;
    --danger-pale: #FBEAEA;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-base);
    background: var(--surface);
    margin: 0;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.mono {
    font-family: var(--font-mono);
}

a {
    color: var(--brand);
}

/* ════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sb-width);
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 1.25rem 1.25rem;
    border-bottom: 1px solid var(--sb-border);
    display: flex;
    align-items: center;
    gap: .625rem;
}

.sidebar-logo-mark {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    letter-spacing: -.01em;
}

.sidebar-logo-mark .braces {
    color: var(--color-accent);
}

.sidebar-logo-sub {
    font-size: .65rem;
    color: rgba(255, 255, 255, .4);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-top: 1px;
}

.sidebar-logo img {
    width: 58px;
    height: 58px;
    border-radius: 8px;
    object-fit: contain;
    background: rgb(255, 255, 255);
    padding: 3px;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: .75rem 0;
    flex: 1;
}

.nav-section {
    padding: 1rem 1.25rem .375rem;
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255, 255, 255, .3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5625rem 1.25rem;
    color: var(--sb-text);
    font-size: .8125rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
    position: relative;
}

.nav-item:hover {
    background: var(--sb-hover-bg);
    color: var(--sb-text-active);
    text-decoration: none;
}

.nav-item.active {
    background: var(--sb-active-bg);
    color: var(--sb-text-active);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--sb-active-rule);
}

.nav-item svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: .75;
}

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

.sidebar-footer {
    padding: .875rem 1.25rem;
    border-top: 1px solid var(--sb-border);
    font-size: .7rem;
    color: rgba(255, 255, 255, .3);
    line-height: 1.5;
}

/* ════════════════════════════════════════════════════
   MAIN WRAPPER
════════════════════════════════════════════════════ */
.main-wrap {
    margin-left: var(--sb-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--surface-card);
    border-bottom: 1px solid var(--border-ui);
    padding: 0 1.75rem;
    height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-title {
    font-size: .9375rem;
    font-weight: 600;
    color: var(--ink);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.topbar-meta {
    font-size: .75rem;
    color: var(--ink-faint);
}

.topbar-badge {
    font-size: .7rem;
    font-weight: 500;
    color: var(--brand);
    background: var(--brand-pale);
    border: 1px solid color-mix(in srgb, var(--color-accent) 15%, transparent);
    border-radius: 2rem;
    padding: .25rem .75rem;
}

.page-content {
    flex: 1;
    padding: 1.75rem;
    width: 100%;
}

.main-footer {
    background: var(--surface-card);
    border-top: 1px solid var(--border-ui);
    padding: .75rem 1.75rem;
    display: flex;
    justify-content: space-between;
    font-size: .6875rem;
    color: var(--ink-faint);
}

/* ════════════════════════════════════════════════════
   CARDS, STAT CARDS
════════════════════════════════════════════════════ */
.card {
    background: var(--surface-card);
    border: 1px solid var(--border-ui);
    border-radius: 10px;
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface-card);
    border: 1px solid var(--border-ui);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.stat-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-faint);
    font-weight: 600;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: .35rem;
}

.stat-sub {
    font-size: .78rem;
    color: var(--ink-faint);
    margin-top: .15rem;
}

/* ════════════════════════════════════════════════════
   TABLES
════════════════════════════════════════════════════ */
h1 {
    font-size: 1.375rem;
    margin: 0 0 1rem;
    color: var(--ink);
}

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

th, td {
    text-align: left;
    padding: .65rem .6rem;
    border-bottom: 1px solid var(--border-ui);
    font-size: .875rem;
}

th {
    color: var(--ink-faint);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

tbody tr:hover {
    background: var(--surface);
}

/* ════════════════════════════════════════════════════
   BUTTONS, BADGES, FORMS
════════════════════════════════════════════════════ */
.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: .55rem 1.1rem;
    font-family: var(--font-base);
    font-size: .875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: filter .15s;
}

.btn:hover {
    filter: brightness(.92);
    text-decoration: none;
}

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

.btn.secondary:hover {
    background: var(--brand-pale);
}

.status {
    background: var(--brand-pale);
    color: var(--brand);
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: .875rem;
}

.status.error {
    background: var(--danger-pale);
    color: var(--danger);
}

.badge {
    display: inline-block;
    padding: .18rem .65rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-draft { background: #ECECEE; color: #55555A; }
.badge-sent { background: var(--brand-pale); color: var(--brand); }
.badge-paid { background: var(--success-pale); color: var(--success); }
.badge-partially_paid { background: var(--warning-pale); color: var(--warning); }
.badge-overdue { background: var(--danger-pale); color: var(--danger); }
.badge-void { background: #ECECEE; color: #9A9A9E; }

label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: .3rem;
    color: var(--ink-muted);
}

input, textarea, select {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border-ui);
    border-radius: 7px;
    font-family: inherit;
    font-size: .9rem;
    margin-bottom: 1rem;
    background: #fff;
    color: var(--ink);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--color-accent) 55%, transparent);
    box-shadow: 0 0 0 3px var(--brand-pale);
}

.row {
    display: flex;
    gap: 1rem;
}

.row > * {
    flex: 1;
}

.item-row {
    display: grid;
    grid-template-columns: 1fr 90px 120px 110px 32px;
    gap: .6rem;
    align-items: start;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: .375rem;
    border-radius: 6px;
    color: var(--ink-muted);
}

.sidebar-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

.sidebar-toggle:hover {
    background: var(--surface);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 45;
}

.sidebar-overlay.open {
    display: block;
}

/* ════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrap {
        margin-left: 0;
    }

    .page-content {
        padding: 1rem;
    }

    .topbar {
        padding: 0 1rem;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 901px) {
    .sidebar-overlay {
        display: none !important;
    }
}
