:root {
    --ground: #F3EEE4;
    --surface: #FFFFFF;
    --surface-2: #FAF6EE;
    --sidebar: #2E2118;
    --sidebar-2: #241a12;
    --sidebar-ink: #E7DBC7;
    --sidebar-muted: #A38F76;
    --ink: #2A2118;
    --muted: #7C7264;
    --line: #E4DBC9;
    --line-strong: #D6C9AF;
    --leather: #6E4A2A;
    --leather-ink: #573920;
    --denim: #9A7A38;
    --ok: #3E7C4E;
    --ok-bg: #E6F0E5;
    --warn: #C68A22;
    --warn-bg: #F8EED6;
    --danger: #B23A2E;
    --danger-bg: #F6E1DD;
    --shadow: 0 1px 2px rgba(42,33,24,.06), 0 8px 24px rgba(42,33,24,.05);
    --radius: 12px;
    --radius-sm: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --serif: Georgia, "Times New Roman", serif;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --ground: #1B150E;
      --surface: #26201A;
      --surface-2: #2E2720;
      --sidebar: #161009;
      --sidebar-2: #100b06;
      --sidebar-ink: #E7DBC7;
      --sidebar-muted: #9c8a72;
      --ink: #ECE2D1;
      --muted: #A2957F;
      --line: #382f25;
      --line-strong: #46392b;
      --leather: #C89153;
      --leather-ink: #E6B44E;
      --denim: #D8B368;
      --ok: #6FB077; --ok-bg: #1f2e1f;
      --warn: #E0AB4B; --warn-bg: #332813;
      --danger: #E27266; --danger-bg: #3a1e1a;
      --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 28px rgba(0,0,0,.35);
    }
  }
  :root[data-theme="light"] {
    --ground:#F3EEE4;--surface:#FFFFFF;--surface-2:#FAF6EE;--ink:#2A2118;--muted:#7C7264;
    --line:#E4DBC9;--line-strong:#D6C9AF;--leather:#6E4A2A;--leather-ink:#573920;--denim:#9A7A38;
    --ok:#3E7C4E;--ok-bg:#E6F0E5;--warn:#C68A22;--warn-bg:#F8EED6;--danger:#B23A2E;--danger-bg:#F6E1DD;
    --sidebar:#2E2118;--sidebar-2:#241a12;--sidebar-ink:#E7DBC7;--sidebar-muted:#A38F76;
    --shadow:0 1px 2px rgba(42,33,24,.06), 0 8px 24px rgba(42,33,24,.05);
  }
  :root[data-theme="dark"] {
    --ground:#1B150E;--surface:#26201A;--surface-2:#2E2720;--ink:#ECE2D1;--muted:#A2957F;
    --line:#382f25;--line-strong:#46392b;--leather:#C89153;--leather-ink:#E6B44E;--denim:#D8B368;
    --ok:#6FB077;--ok-bg:#1f2e1f;--warn:#E0AB4B;--warn-bg:#332813;--danger:#E27266;--danger-bg:#3a1e1a;
    --sidebar:#161009;--sidebar-2:#100b06;--sidebar-ink:#E7DBC7;--sidebar-muted:#9c8a72;
    --shadow:0 1px 2px rgba(0,0,0,.3), 0 10px 28px rgba(0,0,0,.35);
  }

  * { box-sizing: border-box; }
  body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  h1,h2,h3,h4 { margin: 0; text-wrap: balance; }
  button { font-family: inherit; cursor: pointer; }
  a { color: inherit; }
  .tnum { font-variant-numeric: tabular-nums; }

  .app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

  /* Sidebar */
  .sidebar { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
  .brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; gap: 12px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(150deg, var(--leather), #573920); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; color: #fff; font-size: 20px; flex: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.25); }
  .brand-name { font-family: var(--serif); font-size: 16px; letter-spacing: .04em; line-height: 1.15; }
  .brand-name small { display:block; font-family: var(--font); font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--sidebar-muted); margin-top: 2px; }
  .nav { padding: 12px 12px 20px; overflow-y: auto; flex: 1; }
  .nav-group { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--sidebar-muted); padding: 14px 12px 6px; }
  .nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--sidebar-ink); text-decoration: none; font-size: 13.5px; font-weight: 500; border: none; background: none; width: 100%; text-align: left; }
  .nav-item .ic { width: 18px; height: 18px; flex: none; opacity: .82; }
  .nav-item:hover { background: rgba(255,255,255,.06); }
  .nav-item.active { background: linear-gradient(90deg, rgba(214,163,30,.30), rgba(214,163,30,.10)); color: #fff; box-shadow: inset 2px 0 0 var(--gold); }
  .nav-item.active .ic { opacity: 1; }
  .nav-badge { margin-left: auto; font-size: 11px; background: var(--danger); color: #fff; border-radius: 999px; padding: 1px 7px; font-variant-numeric: tabular-nums; }

  /* Main */
  .main { display: flex; flex-direction: column; min-width: 0; }
  .topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--ground) 82%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 12px 24px; }
  .topbar h1 { font-size: 18px; font-weight: 650; }
  .topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
  .top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
  .icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); position: relative; }
  .icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
  .icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; background: var(--danger); border-radius: 50%; border: 2px solid var(--surface); }
  .user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
  .avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(150deg, var(--denim), #4A3016); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 12px; }
  .user-chip b { font-size: 13px; font-weight: 600; }
  .user-chip span { font-size: 11px; color: var(--muted); display: block; }

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

  .btn { border: 1px solid transparent; border-radius: 10px; padding: 9px 15px; font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; background: var(--surface); color: var(--ink); border-color: var(--line); }
  .btn:hover { border-color: var(--line-strong); }
  .btn-primary { background: var(--leather); color: #fff; border-color: var(--leather); box-shadow: 0 1px 2px rgba(138,90,32,.3); }
  .btn-primary:hover { background: var(--leather-ink); border-color: var(--leather-ink); }
  .btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
  .btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
  .btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }

  /* Cards */
  .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  .card-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
  .card-head h3 { font-size: 15px; font-weight: 650; }
  .card-head .btn { margin-left: auto; }
  .card-body { padding: 18px; }

  .grid { display: grid; gap: 16px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .cols-2 { grid-template-columns: 1.6fr 1fr; }
  .cols-3 { grid-template-columns: repeat(3,1fr); }

  .kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
  .kpi::before { content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background: var(--accent, var(--leather)); }
  .kpi .k-top { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
  .kpi .k-ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-bg, var(--warn-bg)); color: var(--accent, var(--leather)); flex:none; }
  .kpi .k-val { font-size: 25px; font-weight: 700; margin-top: 10px; letter-spacing: -.01em; }
  .kpi .k-val small { font-size: 14px; font-weight: 600; color: var(--muted); }
  .kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 4px; display:flex; align-items:center; gap:5px; }
  .up { color: var(--ok); font-weight: 600; }
  .down { color: var(--danger); font-weight: 600; }

  /* Table */
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; }
  th { text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
  td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
  tr:last-child td { border-bottom: none; }
  tbody tr:hover { background: var(--surface-2); }
  .t-strong { font-weight: 600; }
  .t-mut { color: var(--muted); font-size: 12.5px; }
  .money { font-variant-numeric: tabular-nums; font-weight: 600; }
  .right { text-align: right; }

  .pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
  .pill::before { content:""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity:.9; }
  .pill.ok { background: var(--ok-bg); color: var(--ok); }
  .pill.warn { background: var(--warn-bg); color: var(--warn); }
  .pill.danger { background: var(--danger-bg); color: var(--danger); }
  .pill.info { background: color-mix(in srgb, var(--denim) 14%, transparent); color: var(--denim); }
  .pill.mut { background: var(--surface-2); color: var(--muted); }
  .pill.plain::before { display:none; }

  .avatar-sm { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); border:1px solid var(--line); display:inline-grid; place-items:center; font-weight:600; font-size:12px; color: var(--leather-ink); }
  .cell-flex { display: flex; align-items: center; gap: 10px; }

  .bar-track { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 90px; }
  .bar-fill { height: 100%; border-radius: 99px; background: var(--leather); }

  .alert { display: flex; gap: 11px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; }
  .alert .a-ic { flex: none; margin-top:1px; }
  .alert.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: var(--warn-bg); color: color-mix(in srgb, var(--warn) 70%, var(--ink)); }
  .alert.danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); background: var(--danger-bg); color: color-mix(in srgb, var(--danger) 72%, var(--ink)); }
  .alert.info { border-color: color-mix(in srgb, var(--denim) 35%, var(--line)); background: color-mix(in srgb, var(--denim) 8%, var(--surface)); }
  .alert b { display:block; }

  .toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
  .search { flex: 1; min-width: 200px; display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
  .search input { border: none; background: none; outline: none; padding: 10px 0; font-size: 13.5px; color: var(--ink); width: 100%; font-family: inherit; }
  .search .ic { color: var(--muted); flex:none; }
  .seg { display: inline-flex; background: var(--surface-2); border:1px solid var(--line); border-radius: 10px; padding: 3px; gap:2px; }
  .seg button { border: none; background: none; padding: 6px 13px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

  .empty { text-align: center; color: var(--muted); padding: 40px; }

  /* Barcode */
  .barcode { display:inline-flex; flex-direction: column; align-items: center; gap: 4px; font-family: var(--font); }
  .barcode .bars { height: 34px; display: flex; align-items: stretch; gap: 1px; }
  .barcode .bars i { display: block; background: var(--ink); }
  .barcode .num { font-size: 11px; letter-spacing: .22em; color: var(--muted); font-variant-numeric: tabular-nums; }

  /* PDV */
  .pdv { display: grid; grid-template-columns: 1fr 380px; gap: 18px; align-items: start; }
  .scan-box { display:flex; align-items:center; gap:12px; background: var(--surface); border: 2px dashed var(--line-strong); border-radius: 12px; padding: 14px 16px; }
  .scan-box .pulse { width: 42px; height:42px; border-radius: 10px; background: var(--warn-bg); color: var(--leather); display:grid; place-items:center; flex:none; }
  .scan-box input { flex:1; border:none; background:none; outline:none; font-size:16px; font-family:inherit; color: var(--ink); }
  .cart-line { display:flex; align-items:center; gap:12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
  .cart-line:last-child { border-bottom: none; }
  .qty { display:inline-flex; align-items:center; border:1px solid var(--line); border-radius: 8px; overflow:hidden; }
  .qty button { width:26px; height:26px; border:none; background: var(--surface-2); color: var(--ink); font-size: 15px; line-height:1; }
  .qty span { width: 30px; text-align:center; font-weight:600; font-size:13px; }
  .totrow { display:flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
  .totrow.big { font-size: 20px; font-weight: 700; border-top: 1px solid var(--line); margin-top:6px; padding-top: 12px; }
  .pay-opts { display:grid; grid-template-columns: repeat(2,1fr); gap: 8px; }
  .pay { border:1px solid var(--line); border-radius: 10px; padding: 11px; display:flex; flex-direction:column; align-items:center; gap:6px; font-size:12px; font-weight:600; color: var(--muted); background: var(--surface); }
  .pay.on { border-color: var(--leather); color: var(--leather-ink); background: var(--warn-bg); }

  /* Modal */
  .modal-scrim { position: fixed; inset: 0; background: rgba(30,22,14,.5); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 20px; }
  .modal { background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); width: 100%; max-width: 460px; overflow: hidden; border: 1px solid var(--line); }
  .modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display:flex; align-items:center; gap: 12px; }
  .modal-head h3 { font-size: 16px; }
  .modal-body { padding: 20px; display: grid; gap: 14px; max-height: 62vh; overflow-y: auto; }
  .modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); }
  .field label { font-size: 12px; font-weight: 600; color: var(--muted); display:block; margin-bottom: 5px; }
  .field input, .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font-size: 14px; font-family: inherit; outline: none; }
  .field input:focus, .field select:focus { border-color: var(--leather); box-shadow: 0 0 0 3px color-mix(in srgb, var(--leather) 18%, transparent); }
  .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

  .mini-chart { display:flex; align-items:flex-end; gap: 8px; height: 130px; padding-top: 8px; }
  .mini-chart .col { flex:1; display:flex; flex-direction:column; align-items:center; gap:7px; }
  .mini-chart .col .b { width: 100%; max-width: 34px; background: linear-gradient(var(--leather), #caa06a); border-radius: 6px 6px 0 0; }
  .mini-chart .col .b.alt { background: linear-gradient(var(--denim), #b98f4a); }
  .mini-chart .col small { font-size: 11px; color: var(--muted); }

  .list-split { display:flex; align-items:center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .list-split:last-child { border-bottom:none; }
  .rank { width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2); display:grid; place-items:center; font-weight:700; font-size:12px; color: var(--muted); flex:none; }

  .mobile-only { display:none; }
  @media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; top:0; bottom:0; width: 250px; z-index: 60; transform: translateX(-100%); transition: transform .22s ease; }
    .sidebar.open { transform: none; }
    .scrim { position: fixed; inset:0; background: rgba(0,0,0,.4); z-index: 50; display:none; }
    .scrim.show { display:block; }
    .mobile-only { display: grid; }
    .kpis { grid-template-columns: repeat(2,1fr); }
    .cols-2, .cols-3, .pdv { grid-template-columns: 1fr; }
  }
  @media (max-width: 560px) {
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .kpis { grid-template-columns: 1fr; }
    .user-chip .who { display:none; }
  }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* ===== App real: login, toast, offline, loading ===== */
.auth-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--leather) 16%, var(--ground)), var(--ground)); z-index: 200; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.auth-head { padding: 26px 26px 6px; text-align: center; }
.auth-logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 12px; background: linear-gradient(150deg, var(--leather), #573920); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; color:#fff; font-size: 28px; box-shadow: inset 0 1px 0 rgba(255,255,255,.25); }
.auth-head h2 { font-family: var(--serif); font-size: 21px; letter-spacing: .01em; }
.auth-head p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.auth-tabs { display: flex; gap: 4px; padding: 16px 26px 0; }
.auth-tabs button { flex:1; border:none; background: var(--surface-2); color: var(--muted); font-weight:600; font-size:13px; padding: 9px; border-radius: 9px 9px 0 0; }
.auth-tabs button.on { background: transparent; color: var(--ink); box-shadow: inset 0 -2px 0 var(--leather); }
.auth-body { padding: 18px 26px 26px; display: grid; gap: 13px; }
.auth-err { background: var(--danger-bg); color: color-mix(in srgb, var(--danger) 75%, var(--ink)); font-size: 12.5px; padding: 9px 12px; border-radius: 9px; display:none; }
.auth-err.show { display:block; }
.link-btn { background:none; border:none; color: var(--leather-ink); font-weight:600; font-size:12.5px; text-decoration: underline; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display:flex; flex-direction:column; gap:8px; align-items:center; }
.toast { background: var(--ink); color: var(--ground); padding: 11px 18px; border-radius: 10px; font-size: 13.5px; font-weight:500; box-shadow: 0 8px 24px rgba(0,0,0,.25); display:flex; align-items:center; gap:9px; animation: toastin .2s ease; max-width: 90vw; }
.toast.ok { background: var(--ok); color:#fff; }
.toast.err { background: var(--danger); color:#fff; }
@keyframes toastin { from { opacity:0; transform: translateY(8px);} to {opacity:1; transform:none;} }

.offline-banner { display:none; align-items:center; gap:8px; justify-content:center; background: var(--warn-bg); color: color-mix(in srgb, var(--warn) 78%, var(--ink)); font-size:12.5px; font-weight:600; padding: 6px; }
body.is-offline .offline-banner { display:flex; }

.loading { display:grid; place-items:center; padding: 50px; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--leather); border-radius:50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { color: transparent !important; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; border-radius: 6px; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .spinner,.skeleton { animation: none; } }


/* ===== Cor dourada da marca (PAVAN) ===== */
:root { --gold:#D6A31E; --gold-ink:#A87D16; --gold-bg:#FBF1D6; }
@media (prefers-color-scheme: dark){ :root { --gold:#E6B93A; --gold-ink:#F0CB6A; --gold-bg:#33280F; } }
:root[data-theme="light"]{ --gold:#D6A31E; --gold-ink:#A87D16; --gold-bg:#FBF1D6; }
:root[data-theme="dark"]{ --gold:#E6B93A; --gold-ink:#F0CB6A; --gold-bg:#33280F; }

/* Logo */
.brand-logo, .auth-logo-img { display:block; object-fit:contain; }
.brand-chip { width:44px; height:44px; border-radius:11px; background:#fff; display:grid; place-items:center; flex:none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.05); overflow:hidden; }
.brand-chip img { width:100%; height:100%; object-fit:contain; }
.auth-logo-wrap img { width:150px; height:auto; margin:0 auto 6px; display:block; }
.pill.gold { background: var(--gold-bg); color: var(--gold-ink); }
.btn-gold { background: var(--gold); color:#3a2a10; border-color: var(--gold); }
.btn-gold:hover { background: var(--gold-ink); color:#fff; }

/* Overlay do menu (mobile): fora do fluxo do grid por padrão */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: none; }
.scrim.show { display: block; }
