/* Weekly Closure System — extracted from approved v5 prototype */
:root {
    --navy: #1F3864;
    --navy-deep: #142646;
    --navy-soft: #2D4D88;
    --ink: #0B1426;
    --paper: #FAFAF7;
    --paper-warm: #F4F2EC;
    --rule: #E5E2D9;
    --rule-soft: #EFEDE6;
    --muted: #6B6F76;
    --muted-soft: #9BA0A8;
    --gold: #B8964A;
    --gold-soft: #F0E6C8;
    --green: #2F7D5B;
    --green-soft: #DCE9DF;
    --amber: #B8731F;
    --amber-soft: #F4E4C8;
    --red: #A8332E;
    --red-soft: #F4D8D6;
    --shadow-soft: 0 1px 2px rgba(11,20,38,.04), 0 4px 12px rgba(11,20,38,.04);
    --shadow-card: 0 1px 3px rgba(11,20,38,.06), 0 8px 24px rgba(11,20,38,.05);
  }

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

  html, body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    font-weight: 400;
    line-height: 1.55;
    font-feature-settings: "kern", "liga";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
  }

  /* ========== TOP BAR ========== */
  .topbar {
    background: var(--navy-deep);
    color: var(--paper);
    padding: 18px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .brand { display: flex; align-items: center; gap: 14px; }
  .brand-mark {
    width: 36px; height: 36px;
    border: 1.5px solid var(--gold);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif;
    font-weight: 600;
    color: var(--gold);
    font-size: 18px;
  }
  .brand-text { display: flex; flex-direction: column; }
  .brand-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 17px;
  }
  .brand-sub {
    font-size: 11px;
    color: var(--muted-soft);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    margin-top: 2px;
  }
  .topbar-meta {
    display: flex;
    gap: 28px;
    align-items: center;
    font-size: 13px;
    color: rgba(255,255,255,.7);
  }
  .topbar-meta strong { color: var(--paper); font-weight: 500; }
  .topbar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 14px 6px 6px;
    background: rgba(255,255,255,.06);
    border-radius: 999px;
  }
  .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), #8C6A2E);
    color: var(--navy-deep);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
  }
  /* ===== Login screen ===== */
  .login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 100%);
    padding: 20px;
  }
  .login-card {
    background: var(--paper);
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 44px 40px 32px;
    width: 100%;
    max-width: 420px;
  }
  .login-brand { text-align: center; margin-bottom: 28px; }
  .login-brand h1 {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 23px;
    color: var(--navy-deep);
    margin-bottom: 4px;
  }
  .login-brand p {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 1.5px;
  }
  .login-error {
    background: var(--red-soft);
    color: var(--red);
    padding: 10px 14px;
    border-radius: 3px;
    font-size: 13px;
    margin-bottom: 12px;
  }
  .login-hint {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px dashed var(--rule);
  }
  .login-hint-title {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .5px;
    margin-bottom: 10px;
    text-align: center;
  }
  .login-hint-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12px;
    color: var(--muted);
    padding: 4px 0;
  }
  .login-hint-row code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    background: var(--paper-warm);
    padding: 2px 8px;
    border-radius: 3px;
    color: var(--navy-deep);
    direction: ltr;
  }

  /* ===== Profile menu ===== */
  .profile-wrap { position: relative; }
  .profile-btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: rgba(255,255,255,.85);
  }
  .profile-btn .chev { font-size: 10px; color: var(--muted-soft); margin-right: 2px; }
  .profile-btn:hover { background: rgba(255,255,255,.12); }
  .profile-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    box-shadow: var(--shadow-card);
    min-width: 230px;
    z-index: 200;
    overflow: hidden;
  }
  .profile-menu.show { display: block; }
  .profile-menu-head {
    padding: 14px 18px;
    background: var(--paper-warm);
    border-bottom: 1px solid var(--rule);
    font-size: 14px;
    font-weight: 600;
    color: var(--navy-deep);
  }
  .profile-menu-head .pm-role {
    font-size: 11px;
    color: var(--gold);
    font-weight: 500;
    margin-top: 2px;
    letter-spacing: .5px;
  }
  .profile-menu-item {
    display: block;
    width: 100%;
    text-align: right;
    background: white;
    border: none;
    padding: 13px 18px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
    border-bottom: 1px solid var(--rule-soft);
  }
  .profile-menu-item:last-child { border-bottom: none; }
  .profile-menu-item:hover { background: var(--paper); }
  .profile-menu-item.danger { color: var(--red); }
  /* Branch-manager mode: hide admin-only report tabs */
  body.role-manager .tab.admin-only { display: none; }
  body.role-manager .manager-note { display: block; }
  .manager-note {
    display: none;
    background: var(--gold-soft);
    border-right: 3px solid var(--gold);
    padding: 14px 20px;
    border-radius: 3px;
    font-size: 13px;
    color: var(--amber);
    margin-bottom: 24px;
  }

  /* ========== TABS ========== */
  .tabs {
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    padding: 0 40px;
    display: flex;
    gap: 4px;
    position: sticky;
    top: 0;
    z-index: 50;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  .tab {
    padding: 18px 20px 16px;
    cursor: pointer;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color .2s, border-color .2s;
    user-select: none;
    display: flex; align-items: center; gap: 8px;
    white-space: nowrap;
  }
  .tab:hover { color: var(--ink); }
  .tab.active {
    color: var(--navy);
    border-bottom-color: var(--gold);
  }
  .tab-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--muted-soft);
    font-weight: 400;
  }
  .tab.active .tab-num { color: var(--gold); }

  /* ========== PAGE ========== */
  .page { display: none; padding: 40px; max-width: 1400px; margin: 0 auto; }
  .page.active { display: block; }

  .page-head {
    margin-bottom: 36px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--rule);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
  }
  .page-head-left { display: flex; flex-direction: column; gap: 6px; }
  .eyebrow {
    font-size: 11px;
    color: var(--gold);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 600;
  }
  .page-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 32px;
    color: var(--navy-deep);
    line-height: 1.2;
    letter-spacing: -.3px;
  }
  .page-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

  /* ========== FORM ========== */
  .form-grid { display: flex; flex-direction: column; gap: 28px; }

  .card {
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    box-shadow: var(--shadow-soft);
    overflow: hidden;
  }
  .card-head {
    padding: 18px 28px;
    border-bottom: 1px solid var(--rule);
    background: var(--paper-warm);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .card-head-title { display: flex; align-items: baseline; gap: 12px; }
  .section-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--gold);
    letter-spacing: .5px;
  }
  .card-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 18px;
    color: var(--navy-deep);
  }
  .card-hint { font-size: 12px; color: var(--muted); }
  .card-body { padding: 24px 28px; }

  .row { display: flex; gap: 24px; align-items: stretch; }
  .row + .row { margin-top: 16px; }

  .field { flex: 1; display: flex; flex-direction: column; gap: 6px; }
  .field label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
  }
  .field label .code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    background: var(--paper-warm);
    color: var(--navy);
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 6px;
    font-weight: 500;
  }
  .field input, .field select, .field textarea {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    transition: border-color .15s, background .15s;
  }
  .field input, .field select { height: 40px; }
  .field textarea {
    padding: 12px 14px;
    min-height: 80px;
    resize: vertical;
    line-height: 1.6;
  }
  .field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--navy);
    background: white;
    box-shadow: 0 0 0 3px rgba(31,56,100,.08);
  }
  .field input[type="number"], .field input.money {
    font-family: 'JetBrains Mono', monospace;
    text-align: left;
    direction: ltr;
  }

  /* Sales KPI hero */
  .sales-hero {
    background: linear-gradient(135deg, var(--gold) 0%, #967028 100%);
    border-radius: 4px;
    padding: 32px 36px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-card);
  }
  .sales-hero .hero-left { display: flex; flex-direction: column; gap: 8px; }
  .sales-hero .hero-eyebrow {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    opacity: .9;
    font-weight: 500;
  }
  .sales-hero .hero-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 22px;
  }
  .sales-hero .hero-sub { font-size: 13px; opacity: .85; margin-top: 4px; }
  .sales-hero-input {
    display: flex;
    align-items: baseline;
    gap: 10px;
  }
  .sales-hero-input input {
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.3);
    color: white;
    height: 56px;
    padding: 0 20px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 500;
    border-radius: 4px;
    width: 220px;
    text-align: left;
    direction: ltr;
  }
  .sales-hero-input input::placeholder { color: rgba(255,255,255,.5); }
  .sales-hero-input input:focus {
    outline: none;
    background: rgba(255,255,255,.25);
    border-color: white;
  }
  .sales-hero-input .unit { font-size: 16px; opacity: .9; font-weight: 400; }

  /* ERP Balance card */
  .erp-card {
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 32px 36px;
    box-shadow: var(--shadow-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .erp-card .erp-left { display: flex; flex-direction: column; gap: 6px; }
  .erp-card .erp-eyebrow {
    font-size: 11px;
    color: var(--gold);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 600;
  }
  .erp-card .erp-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 22px;
    color: var(--navy-deep);
  }
  .erp-card .erp-sub {
    font-size: 13px;
    color: var(--muted);
    margin-top: 4px;
  }
  .erp-input-wrap {
    display: flex;
    align-items: baseline;
    gap: 12px;
  }
  .erp-input-wrap input {
    height: 56px;
    padding: 0 20px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 500;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 4px;
    width: 240px;
    text-align: left;
    direction: ltr;
    color: var(--navy-deep);
  }
  .erp-input-wrap input:focus {
    outline: none;
    background: white;
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(31,56,100,.08);
  }
  .erp-input-wrap .unit { font-size: 16px; color: var(--muted); }

  /* Balance analysis table */
  .analysis-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }
  .analysis-table th, .analysis-table td {
    padding: 14px 18px;
    text-align: right;
    font-size: 14px;
    border-bottom: 1px solid var(--rule-soft);
  }
  .analysis-table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 11px;
    letter-spacing: .5px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--rule);
  }
  .analysis-table .code-cell {
    width: 60px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--gold);
    font-size: 13px;
  }
  .analysis-table .money-cell {
    font-family: 'JetBrains Mono', monospace;
    text-align: left;
    direction: ltr;
    width: 220px;
  }
  .analysis-table input {
    width: 100%;
    background: var(--paper);
    border: 1px solid var(--rule);
    padding: 10px 12px;
    font-family: 'JetBrains Mono', monospace;
    text-align: left;
    direction: ltr;
    font-size: 15px;
    color: var(--ink);
    transition: all .15s;
    border-radius: 3px;
    font-weight: 500;
  }
  .analysis-table input:focus {
    outline: none;
    border-color: var(--navy);
    background: white;
    box-shadow: 0 0 0 3px rgba(31,56,100,.08);
  }
  .analysis-table tr.subtotal td { background: var(--paper-warm); font-weight: 600; color: var(--navy-deep); }
  .analysis-table tr.subtotal .money-cell {
    font-size: 16px;
    padding: 16px 18px;
  }

  /* Match indicator */
  /* Line-item repeaters */
  .repeater { display: flex; flex-direction: column; gap: 8px; }
  .repeater-row {
    display: grid;
    grid-template-columns: 2.2fr 1.2fr auto;
    gap: 12px;
    align-items: center;
  }
  .repeater-row input, .repeater-row select {
    height: 38px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0 12px;
    font-size: 13px;
    font-family: inherit;
  }
  .repeater-row input.money {
    font-family: 'JetBrains Mono', monospace;
    direction: ltr;
    text-align: left;
    font-weight: 500;
  }
  .repeater-row input:focus, .repeater-row select:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(31,56,100,.08);
    background: white;
  }
  .btn-icon {
    width: 38px; height: 38px;
    border: 1px solid var(--rule);
    background: var(--paper);
    border-radius: 3px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted);
    transition: all .15s;
    font-size: 14px;
  }
  .btn-icon:hover { color: var(--red); border-color: var(--red); background: white; }
  .add-row-btn {
    align-self: flex-start;
    background: transparent;
    border: 1px dashed var(--rule);
    color: var(--muted);
    padding: 8px 14px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
    margin-top: 6px;
  }
  .add-row-btn:hover { border-color: var(--navy); color: var(--navy); border-style: solid; }
  .subtotal-bar {
    margin-top: 14px;
    padding: 14px 18px;
    background: var(--paper-warm);
    border-radius: 3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .subtotal-bar .label {
    font-size: 13px;
    color: var(--navy-deep);
    font-weight: 500;
  }
  .subtotal-bar .label .code-inline {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--gold);
    margin-left: 6px;
  }
  .subtotal-bar .value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 600;
    color: var(--navy-deep);
    direction: ltr;
  }
  .comp-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--gold);
    background: var(--gold-soft);
    padding: 3px 9px;
    border-radius: 3px;
  }

  /* ===== Trend analysis ===== */
  .trend-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 900px;
    background: white;
  }
  .trend-table th, .trend-table td {
    padding: 12px 14px;
    text-align: center;
    border-bottom: 1px solid var(--rule-soft);
    font-size: 13px;
  }
  .trend-table th {
    background: var(--paper-warm);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .5px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--rule);
  }
  .trend-table th.week-col, .trend-table td.week-col {
    text-align: right;
    padding-right: 20px;
    white-space: nowrap;
    font-weight: 500;
    color: var(--navy-deep);
  }
  .trend-table td .tval {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--navy-deep);
    direction: ltr;
    display: block;
  }
  .trend-table td .tchg {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    direction: ltr;
    display: block;
    margin-top: 2px;
    color: var(--muted-soft);
  }
  .trend-table td.flag-up { background: rgba(168, 51, 46, .07); }
  .trend-table td.flag-up .tchg { color: var(--red); font-weight: 600; }
  .trend-table td.flag-down { background: rgba(184, 115, 31, .08); }
  .trend-table td.flag-down .tchg { color: var(--amber); font-weight: 600; }
  .trend-table td.flag-streak { box-shadow: inset 0 -2px 0 var(--red); }
  .trend-table tr.missing-row td { color: var(--muted-soft); background: var(--paper); font-style: italic; }

  .trend-alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
  .trend-alert {
    padding: 14px 20px;
    border-radius: 3px;
    font-size: 13px;
    border-right: 3px solid;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
  }
  .trend-alert.warn { background: var(--red-soft); border-color: var(--red); color: var(--red); }
  .trend-alert.info { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }
  .trend-alert.ok { background: var(--green-soft); border-color: var(--green); color: var(--green); }
  .trend-alert .num { font-family: 'JetBrains Mono', monospace; direction: ltr; font-weight: 600; }

  .chg-chip {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 600;
  }
  .chg-chip.up-big { background: var(--red-soft); color: var(--red); }
  .chg-chip.down-big { background: var(--amber-soft); color: var(--amber); }
  .chg-chip.streak { background: var(--red-soft); color: var(--red); border-bottom: 2px solid var(--red); }

  /* ===== Review workflow ===== */
  .review-box {
    margin-top: 20px;
    padding: 16px 20px;
    background: var(--paper-warm);
    border-radius: 3px;
    border-right: 3px solid var(--gold);
  }
  .review-box .review-head {
    font-size: 12px;
    font-weight: 600;
    color: var(--navy-deep);
    letter-spacing: .5px;
    margin-bottom: 10px;
  }
  .review-done {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 13px;
    color: var(--green);
  }
  .review-done .remark { color: var(--muted); font-size: 12px; }
  .review-form { display: flex; gap: 10px; align-items: center; }
  .review-form input[type="text"] {
    flex: 1;
    height: 36px;
    background: white;
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0 12px;
    font-size: 13px;
    font-family: inherit;
  }
  .review-form input:focus { outline: none; border-color: var(--navy); }
  .btn-review {
    background: var(--green);
    color: white;
    border: none;
    padding: 9px 18px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    white-space: nowrap;
  }
  .btn-review:hover { background: #246548; }

  /* reviewed marker inside matrix dots */
  .dot.reviewed::after {
    content: '✓';
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .match-indicator {
    margin-top: 24px;
    padding: 28px 32px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--paper-warm);
    color: var(--muted);
    transition: all .3s;
  }
  .match-indicator.pass {
    background: linear-gradient(135deg, var(--green) 0%, #246548 100%);
    color: white;
  }
  .match-indicator.fail {
    background: linear-gradient(135deg, var(--red) 0%, #8C2A26 100%);
    color: white;
  }
  .match-title { display: flex; flex-direction: column; gap: 6px; }
  .match-eyebrow {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    opacity: .85;
    font-weight: 500;
  }
  .match-status {
    font-family: 'Fraunces', serif;
    font-size: 26px;
    font-weight: 500;
    letter-spacing: .2px;
  }
  .match-detail {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    opacity: .9;
    direction: ltr;
    margin-top: 4px;
  }
  .match-icon {
    width: 64px; height: 64px;
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px;
  }
  .match-indicator:not(.pass):not(.fail) .match-icon { border-color: var(--rule); }

  /* Variance reason */
  .variance-box {
    margin-top: 20px;
    padding: 20px 24px;
    background: var(--amber-soft);
    border-left: 3px solid var(--amber);
    border-radius: 3px;
    display: none;
  }
  .variance-box.show { display: block; }
  .variance-box label {
    display: block;
    font-size: 12px;
    color: var(--amber);
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: .5px;
    text-transform: uppercase;
  }
  .variance-box textarea {
    width: 100%;
    background: white;
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 12px 14px;
    font-size: 13px;
    font-family: inherit;
    min-height: 70px;
    resize: vertical;
    line-height: 1.6;
  }
  .variance-box textarea:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(184,115,31,.15);
  }

  /* Submit bar */
  .submit-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-top: 1px solid var(--rule);
    margin-top: 12px;
  }
  .btn-primary {
    background: var(--navy-deep);
    color: white;
    padding: 12px 32px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background .15s;
  }
  .btn-primary:hover:not(:disabled) { background: var(--navy); }
  .btn-primary:disabled { background: var(--muted-soft); cursor: not-allowed; }
  .btn-secondary {
    background: transparent;
    color: var(--navy-deep);
    padding: 12px 24px;
    border: 1px solid var(--rule);
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
  }
  .btn-secondary:hover { border-color: var(--navy); }

  /* ========== REPORTS ========== */
  /* Matrix */
  .matrix-wrap {
    overflow-x: auto;
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    box-shadow: var(--shadow-soft);
  }
  .matrix {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 900px;
  }
  .matrix th, .matrix td {
    padding: 0;
    text-align: center;
    border-bottom: 1px solid var(--rule-soft);
  }
  .matrix th {
    background: var(--paper-warm);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .3px;
    padding: 14px 8px;
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
  }
  .matrix th.branch-col {
    text-align: right;
    padding-right: 20px;
    width: 140px;
    position: sticky;
    right: 0;
    background: var(--paper-warm);
    z-index: 2;
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  .matrix th .wk-num {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 14px;
    color: var(--navy-deep);
    display: block;
    text-transform: none;
    letter-spacing: 0;
    line-height: 1;
    margin-bottom: 2px;
  }
  .matrix th .wk-range {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--muted);
    letter-spacing: .5px;
  }
  .matrix th.current { background: var(--navy-deep); }
  .matrix th.current .wk-num { color: white; }
  .matrix th.current .wk-range { color: var(--gold); }
  .matrix td.branch-cell {
    text-align: right;
    padding: 14px 20px;
    font-weight: 500;
    font-size: 13px;
    color: var(--navy-deep);
    background: white;
    position: sticky;
    right: 0;
    border-left: 1px solid var(--rule);
    z-index: 1;
  }
  .matrix td.cell { padding: 10px 6px; cursor: pointer; }
  .matrix .dot {
    width: 26px;
    height: 26px;
    border-radius: 3px;
    margin: 0 auto;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
  }
  .matrix .dot:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(11,20,38,.15);
    z-index: 5;
    position: relative;
  }
  .dot.clean { background: var(--green); }
  .dot.variance { background: var(--amber); }
  .dot.missing { background: var(--red-soft); border: 1px dashed var(--red); }
  .dot.future { background: var(--rule-soft); }

  .legend {
    display: flex;
    gap: 24px;
    align-items: center;
    margin-top: 20px;
    font-size: 12px;
    color: var(--muted);
    flex-wrap: wrap;
  }
  .legend-item { display: flex; align-items: center; gap: 8px; }
  .legend-item .dot { width: 14px; height: 14px; cursor: default; }
  .legend-item .dot:hover { transform: none; box-shadow: none; }

  /* Hero cards */
  .hero-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 32px;
  }
  .hero-card {
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 24px 28px;
    box-shadow: var(--shadow-soft);
  }
  .hero-card.dark {
    background: linear-gradient(135deg, var(--navy-deep) 0%, #0F1E37 100%);
    color: white;
    border-color: var(--navy-deep);
  }
  .hero-card .label {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 500;
    margin-bottom: 12px;
  }
  .hero-card.dark .label { color: var(--gold); }
  .hero-card .value {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 38px;
    color: var(--navy-deep);
    direction: ltr;
    text-align: left;
    line-height: 1.1;
    letter-spacing: -.5px;
  }
  .hero-card.dark .value { color: white; }
  .hero-card .unit { font-size: 14px; color: var(--muted); margin-right: 6px; font-weight: 400; }
  .hero-card .delta {
    margin-top: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--muted);
    direction: ltr;
    text-align: left;
  }
  .hero-card .delta.pos { color: var(--green); }
  .hero-card .delta.neg { color: var(--red); }
  .hero-card.dark .delta { color: rgba(255,255,255,.7); }

  /* Bars */
  .bars-card {
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 28px 32px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 24px;
  }
  .bars-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
  }
  .bars-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 18px;
    color: var(--navy-deep);
  }
  .bars-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
  .bar-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
  }
  .bar-row:last-child { margin-bottom: 0; }
  .bar-label {
    width: 80px;
    font-size: 13px;
    color: var(--navy-deep);
    font-weight: 500;
  }
  .bar-track {
    flex: 1;
    height: 28px;
    background: var(--paper);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--rule-soft);
  }
  .bar-fill {
    height: 100%;
    transition: width .6s ease;
    position: relative;
  }
  .bar-fill.navy { background: linear-gradient(90deg, var(--navy) 0%, var(--navy-soft) 100%); }
  .bar-fill.gold { background: linear-gradient(90deg, var(--gold) 0%, #967028 100%); }
  .bar-fill.green { background: linear-gradient(90deg, var(--green) 0%, #4A9973 100%); }
  .bar-fill.amber { background: linear-gradient(90deg, var(--amber) 0%, #D69042 100%); }
  .bar-fill.red { background: linear-gradient(90deg, var(--red) 0%, #C85752 100%); }
  .bar-value {
    width: 140px;
    font-family: 'JetBrains Mono', monospace;
    direction: ltr;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: var(--navy-deep);
  }

  /* Table list */
  .branch-list {
    background: white;
    border: 1px solid var(--rule);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
  }
  .branch-list table { width: 100%; border-collapse: separate; border-spacing: 0; }
  .branch-list th {
    background: var(--paper-warm);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .5px;
    text-align: right;
    padding: 14px 24px;
    border-bottom: 1px solid var(--rule);
  }
  .branch-list th.num { text-align: left; }
  .branch-list td {
    padding: 18px 24px;
    border-bottom: 1px solid var(--rule-soft);
    font-size: 14px;
    color: var(--ink);
  }
  .branch-list tr:last-child td { border-bottom: none; }
  .branch-list tr:hover td { background: var(--paper); }
  .branch-list td.num {
    font-family: 'JetBrains Mono', monospace;
    text-align: left;
    direction: ltr;
    font-weight: 500;
  }
  .branch-list .branch-name { font-weight: 500; color: var(--navy-deep); }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
  }
  .status-pill::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
  }
  .status-pill.clean { background: var(--green-soft); color: var(--green); }
  .status-pill.clean::before { background: var(--green); }
  .status-pill.variance { background: var(--amber-soft); color: var(--amber); }
  .status-pill.variance::before { background: var(--amber); }
  .status-pill.missing { background: var(--red-soft); color: var(--red); }
  .status-pill.missing::before { background: var(--red); }

  /* Split layout for pending reports */
  .split-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    margin-bottom: 24px;
  }
  .summary-panel {
    border-radius: 4px;
    padding: 32px;
    color: white;
    box-shadow: var(--shadow-card);
  }
  .summary-panel.navy {
    background: linear-gradient(160deg, var(--navy-deep) 0%, #0F1E37 100%);
  }
  .summary-panel.gold {
    background: linear-gradient(160deg, var(--gold) 0%, #755425 100%);
  }
  .summary-panel.green {
    background: linear-gradient(160deg, var(--green) 0%, #1F5B41 100%);
  }
  .summary-panel.amber {
    background: linear-gradient(160deg, var(--amber) 0%, #8A5217 100%);
  }
  .summary-panel.red {
    background: linear-gradient(160deg, var(--red) 0%, #7A2521 100%);
  }
  .summary-panel .eyebrow { color: rgba(255,255,255,.75); }
  .summary-panel .value {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 52px;
    line-height: 1;
    margin: 12px 0 8px;
    direction: ltr;
    text-align: left;
    letter-spacing: -1px;
  }
  .summary-panel .unit {
    font-size: 16px;
    color: rgba(255,255,255,.6);
    margin-right: 8px;
    font-weight: 400;
  }
  .summary-panel .breakdown {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid rgba(255,255,255,.15);
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .summary-panel .breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
  }
  .summary-panel .breakdown-row .label { color: rgba(255,255,255,.75); }
  .summary-panel .breakdown-row .num {
    font-family: 'JetBrains Mono', monospace;
    direction: ltr;
    font-weight: 500;
    color: white;
  }

  /* Modal */
  .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11,20,38,.5);
    backdrop-filter: blur(3px);
    z-index: 100;
    justify-content: center;
    align-items: center;
  }
  .modal-backdrop.show { display: flex; }
  .modal {
    background: var(--paper);
    border-radius: 4px;
    padding: 36px;
    max-width: 560px;
    width: calc(100% - 40px);
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
  }
  .modal h3 {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 22px;
    color: var(--navy-deep);
    margin-bottom: 6px;
  }
  .modal .sub { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
  .modal-status {
    margin: 12px 0 24px;
    padding: 12px 16px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: .3px;
  }
  .modal-status.clean { background: var(--green-soft); color: var(--green); }
  .modal-status.variance { background: var(--amber-soft); color: var(--amber); }
  .modal-status.missing { background: var(--red-soft); color: var(--red); }
  .modal-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--rule-soft);
  }
  .modal-row:last-of-type { border-bottom: none; }
  .modal-row .l { color: var(--muted); display: flex; align-items: baseline; gap: 8px; }
  .modal-row .l .code-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    background: var(--paper-warm);
    color: var(--navy);
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
  }
  .modal-row .v {
    font-family: 'JetBrains Mono', monospace;
    direction: ltr;
    color: var(--navy-deep);
    font-weight: 500;
  }
  .modal-row.total {
    border-top: 2px solid var(--navy-deep);
    border-bottom: none;
    margin-top: 4px;
    padding-top: 14px;
    font-weight: 600;
  }
  .modal-row.total .v { font-size: 15px; }
  .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
  }

  /* Responsive */
  @media (max-width: 1100px) {
    .hero-row { grid-template-columns: 1fr; }
    .split-grid { grid-template-columns: 1fr; }
    .sales-hero, .erp-card { flex-direction: column; align-items: flex-start; gap: 16px; }
  }
  @media (max-width: 768px) {
    .topbar, .tabs, .page { padding-left: 20px; padding-right: 20px; }
    .row { flex-direction: column; gap: 16px; }
    .topbar-meta { display: none; }
    .page-title { font-size: 24px; }
    .analysis-table .money-cell { width: 140px; }
    .sales-hero-input input, .erp-input-wrap input { width: 100%; }
  }
