:root {
    --sidebar-w: 250px;
    /* THETCGAPP red & black theme (v2.0.1).
       NOTE (v2.7.2): base.html emits a :root override AFTER this stylesheet
       with the colours saved in Settings → Branding (including derived
       --brand-dark/--brand-soft/--brand-glow via color-mix). The values below
       are only fallbacks for pages rendered without base.html. */
    --brand: #e11d2a;         /* primary red */
    --brand-dark: #8f0f18;    /* deep red */
    --brand-2: #c11722;       /* accent red (was Shopify green) */
    --brand-soft: rgba(225,29,42,.20);
    --brand-softer: rgba(225,29,42,.12);
    --brand-glow: rgba(225,29,42,.15);
    --ink-black: #14151a;     /* near-black */
    --bg: #f4f5f7;
    --card-radius: 14px;
    --ink: #1c1e26;
    --muted: #6b7280;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}

a { text-decoration: none; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--ink-black) 0%, var(--brand-dark) 70%, var(--brand) 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-logo {
    width: 56px; height: 56px; border-radius: 14px;
    background: linear-gradient(135deg, var(--brand), var(--ink-black));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 28px; margin-bottom: 18px;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg, var(--ink-black));
    color: var(--sidebar-text, #cdd2e4);
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    transition: transform .25s ease;
    z-index: 1000;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    color: #fff; font-weight: 700; font-size: 17px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--ink-black));
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.nav-section { padding: 12px 0; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 20px; color: #aab0cf; font-weight: 500;
    border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-link.active {
    background: var(--brand-soft, rgba(225,29,42,.20));
    color: #fff; border-left-color: var(--brand);
}
.nav-link i { width: 18px; height: 18px; }

/* v2.16.0 / fixed v2.17.0: collapsible nav groups.
   NOTE: the header is a <button>, so we must FULLY reset the user-agent button
   styling (appearance/background/border/margin/box-sizing) — otherwise the
   browser draws a white rounded pill that overflows the sidebar's left edge. */
.nav-group { display: block; width: 100%; }
.nav-group-head {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    box-sizing: border-box;
    display: flex; align-items: center; gap: 12px;
    width: 100%; margin: 0;
    padding: 11px 20px;
    color: #aab0cf; font-weight: 600; font-size: 13.5px;
    background: transparent; background-color: transparent;
    border: 0; border-left: 3px solid transparent; border-radius: 0;
    box-shadow: none; outline: none;
    cursor: pointer; text-align: left; font-family: inherit; line-height: 1.3;
}
.nav-group-head:hover { background-color: rgba(255,255,255,.05); color: #fff; }
.nav-group-head:focus { outline: none; }
.nav-group-head .grp-icon { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-group-head .grp-label { flex: 1 1 auto; min-width: 0; }
.nav-group-head .grp-chev { width: 15px; height: 15px; flex: 0 0 15px; transition: transform .18s ease; opacity: .7; }
.nav-group.has-active > .nav-group-head { color: #fff; }
.nav-group.open > .nav-group-head .grp-chev { transform: rotate(90deg); }
.nav-group-items { overflow: hidden; max-height: 0; transition: max-height .22s ease; }
.nav-group.open > .nav-group-items { max-height: 720px; }
.nav-group-items .nav-link { padding-left: 44px; font-size: 13px; }
.nav-group-items .nav-link i { width: 16px; height: 16px; }
.nav-group .grp-count {
    flex: 0 0 auto;
    font-size: 10px; background-color: rgba(255,255,255,.12); color: #c7cbe0;
    border-radius: 999px; padding: 1px 7px; font-weight: 700;
}

.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex; flex-direction: column;
    min-width: 0;
}
.topbar {
    background: #fff;
    height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid #e4e7ec;
    position: sticky; top: 0; z-index: 500;
}
.topbar h2 { font-size: 18px; margin: 0; }
.content { padding: 24px; flex: 1; }

.hamburger { display: none; background: none; border: none; font-size: 22px; }

/* ---------- Cards ---------- */
.card {
    background: #fff;
    border-radius: var(--card-radius);
    border: 1px solid #e6e9ee;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid #eef1f5;
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600;
}
.card-body { padding: 20px; }

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px; margin-bottom: 20px;
}
.stat {
    background: #fff; border-radius: var(--card-radius); padding: 20px;
    border: 1px solid #e6e9ee; display: flex; justify-content: space-between; align-items: flex-start;
}
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat .icon {
    width: 44px; height: 44px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; color: #fff;
}
.icon.blue { background: var(--brand); }
.icon.green { background: var(--brand-2); }
.icon.orange { background: #e8871e; }
.icon.red { background: #d72c0d; }
.icon.purple { background: var(--ink-black); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid #eef1f5; }
table.tbl th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
table.tbl tbody tr:hover { background: #f9fafb; }
.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: #f0f1f3; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
    font-weight: 600; cursor: pointer; font-size: 13px; background: #eceef2; color: var(--ink);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-success { background: var(--brand-2); color: #fff; }
.btn-danger { background: #d72c0d; color: #fff; }
.btn-light { background: #fff; border-color: #d2d7de; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn i { width: 15px; height: 15px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-active, .badge-success, .badge-synced { background: #e3f1df; color: #108043; }
.badge-draft { background: #eef1f5; color: #637381; }
.badge-error, .badge-cancelled { background: #fbeae5; color: #bf0711; }
.badge-ordered, .badge-pending { background: #fff4e4; color: #8a6116; }
.badge-received, .badge-inactive { background: #ebf5fa; color: #0b6b83; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 10px 12px; border: 1px solid #c9cfd6; border-radius: 9px;
    font-size: 14px; background: #fff; font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow, rgba(225,29,42,.15)); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(20,25,45,.55);
    display: none; align-items: flex-start; justify-content: center; z-index: 2000; padding: 40px 16px; overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; }
.modal-box.lg { max-width: 800px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid #eef1f5; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid #eef1f5; display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty i { width: 48px; height: 48px; margin-bottom: 12px; }
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.text-end { text-align: right; }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.mt-2 { margin-top: 12px; }
.gap { gap: 10px; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .grow { flex: 1; }
.pill { background: #eef1f5; border-radius: 20px; padding: 4px 12px; font-size: 12px; font-weight: 600; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.alert-warning { background: #fff4e4; color: #8a6116; }
.alert-danger { background: #fbeae5; color: #bf0711; }
.alert-success { background: #e3f1df; color: #108043; }
.progress { height: 10px; background: #eef1f5; border-radius: 10px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand-2); width: 0; transition: width .3s; }
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span { padding: 7px 12px; border-radius: 8px; border: 1px solid #d2d7de; background: #fff; }
.pagination .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

#toast {
    position: fixed; bottom: 24px; right: 24px; z-index: 3000;
    background: #212b36; color: #fff; padding: 14px 20px; border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,.3); display: none; max-width: 340px;
}
#toast.show { display: block; }
#toast.ok { background: #108043; }
#toast.err { background: #bf0711; }

/* ============================================================
   RESPONSIVE — iPad / iPhone optimisation (v2.1.0)
   ============================================================ */

/* Tablet & below: collapsible sidebar with slide-in + dark overlay */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 2px 0 18px rgba(0,0,0,.25);
        z-index: 1500;
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .hamburger { display: inline-flex; align-items: center; justify-content: center; }
    /* dark overlay behind the open drawer */
    .sidebar-overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45);
        z-index: 1400;
    }
    .sidebar-overlay.show { display: block; }
    .row2, .row3 { grid-template-columns: 1fr; }
}

/* Phones & small tablets */
@media (max-width: 768px) {
    .content { padding: 14px; }
    .topbar { padding: 0 12px; position: sticky; top: 0; z-index: 900; }
    .topbar h2 { font-size: 16px; }

    /* Toolbars / filter bars wrap and go full width */
    .toolbar, .filters { flex-wrap: wrap; gap: 8px; }
    .toolbar .form-control, .filters .form-control,
    .toolbar select, .filters select,
    .toolbar input, .filters input { flex: 1 1 100%; min-width: 0; }
    .toolbar .btn, .filters .btn { flex: 1 1 auto; }

    /* Touch-friendly controls; 16px inputs stop iOS auto-zoom */
    .btn { min-height: 42px; padding: 10px 14px; }
    .form-control, input, select, textarea { font-size: 16px; min-height: 42px; }
    .nav-link { padding: 12px 16px; }

    /* Cards / headers tighten up */
    .card-header { padding: 13px 15px; }
    .card-body { padding: 15px; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 14px; }
    .stat .value { font-size: 20px; }

    /* Tables: allow horizontal scroll with momentum */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.tbl { min-width: 640px; }
    table.tbl th, table.tbl td { padding: 9px 10px; font-size: 13px; }

    /* Modals fill the screen sensibly */
    .modal-backdrop { padding: 12px; align-items: flex-start; }
    .modal-box, .modal-box.lg { max-width: 100%; }
    .modal-body { padding: 16px; }
    .modal-header, .modal-footer { padding: 14px 16px; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer .btn { flex: 1 1 auto; }

    /* Topbar actions stack under heading if needed */
    .topbar-actions { flex-wrap: wrap; gap: 6px; }
}

/* Very small phones */
@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
    .topbar-actions .btn { flex: 1 1 100%; }
}

/* Respect notches / safe areas on iOS */
@supports (padding: max(0px)) {
    .sidebar { padding-left: env(safe-area-inset-left); }
    .topbar { padding-left: max(12px, env(safe-area-inset-left)); }
}

/* v2.12.0: unread messages badge in the sidebar */
.nav-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; margin-left: auto;
    background: var(--brand, #e11d2a); color: #fff;
    border-radius: 999px; font-size: 11px; font-weight: 800;
}
