:root {
  --bg: #101014;
  --panel: #18181f;
  --panel-2: #20202a;
  --panel-3: #272735;
  --text: #f5f5f7;
  --muted: #aaaab8;
  --line: rgba(255,255,255,.08);
  --primary: #f6c64a;
  --primary-2: #ffe08a;
  --danger: #ff6678;
  --success: #62d486;
  --warning: #f4a261;
  --shadow: 0 24px 60px rgba(0,0,0,.35);
  --radius: 22px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top right, rgba(246,198,74,.14), transparent 36%), var(--bg); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
#appShell { min-height: 100vh; display: grid; grid-template-columns: 300px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 22px; border-left: 1px solid var(--line); background: rgba(16,16,20,.82); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); background: linear-gradient(145deg, rgba(246,198,74,.16), rgba(255,255,255,.03)); border-radius: 20px; }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 16px; background: var(--primary); color: #14110a; font-weight: 900; }
.brand strong { display: block; font-size: 18px; }
.brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
#nav { display: grid; gap: 8px; overflow: auto; padding-left: 4px; }
.nav-btn { width: 100%; border: 1px solid transparent; background: transparent; color: var(--muted); padding: 12px 14px; border-radius: 16px; text-align: right; display: flex; align-items: center; gap: 10px; }
.nav-btn:hover, .nav-btn.active { color: var(--text); background: var(--panel); border-color: var(--line); }
.nav-btn.active { box-shadow: inset 0 0 0 1px rgba(246,198,74,.2); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.main { min-width: 0; padding: 26px; }
.topbar { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 22px; }
h1 { margin: 0; font-size: clamp(26px, 4vw, 42px); letter-spacing: -.5px; }
p { margin: 0; color: var(--muted); line-height: 1.7; }
.top-actions { display: flex; gap: 10px; align-items: center; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 14px; padding: 12px 13px; outline: none; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(246,198,74,.58); box-shadow: 0 0 0 4px rgba(246,198,74,.08); }
input[type="date"] { color-scheme: dark; }
button, .import-label { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #151108; }
.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.danger { background: rgba(255,102,120,.12); color: var(--danger); border: 1px solid rgba(255,102,120,.28); }
.success { background: rgba(98,212,134,.12); color: var(--success); border: 1px solid rgba(98,212,134,.28); }
.full { width: 100%; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.015)); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 12px 36px rgba(0,0,0,.18); }
.card h2, .card h3 { margin: 0 0 14px; }
.card h2 { font-size: 21px; }
.card h3 { font-size: 17px; color: #eee; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-height: 118px; display: flex; flex-direction: column; justify-content: space-between; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { font-size: clamp(22px, 3vw, 32px); direction: ltr; text-align: right; }
.stat small { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field.full-field { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 700; background: rgba(255,255,255,.03); }
td { color: #f1f1f4; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; justify-content: center; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; border: 1px solid var(--line); color: var(--muted); }
.badge.green { color: var(--success); background: rgba(98,212,134,.1); border-color: rgba(98,212,134,.24); }
.badge.red { color: var(--danger); background: rgba(255,102,120,.1); border-color: rgba(255,102,120,.24); }
.badge.yellow { color: var(--primary); background: rgba(246,198,74,.1); border-color: rgba(246,198,74,.24); }
.muted { color: var(--muted); }
.mono { direction: ltr; unicode-bidi: embed; font-variant-numeric: tabular-nums; }
.notice { padding: 12px 14px; border: 1px dashed rgba(246,198,74,.35); border-radius: 16px; color: var(--primary-2); background: rgba(246,198,74,.07); line-height: 1.7; }
.debt-lines { display: grid; gap: 7px; min-width: 260px; }
.debt-line { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); line-height: 1.55; }
.debt-line strong { color: var(--primary-2); }
.debt-line span { color: var(--muted); font-size: 12px; }

.toast { position: fixed; left: 18px; bottom: 18px; max-width: min(420px, calc(100vw - 36px)); transform: translateY(120%); opacity: 0; transition: .25s ease; background: #f5f5f7; color: #111; padding: 14px 16px; border-radius: 16px; box-shadow: var(--shadow); z-index: 40; font-weight: 800; }
.toast.show { transform: translateY(0); opacity: 1; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.64); display: grid; place-items: center; padding: 18px; z-index: 30; }
.modal { width: min(760px, 100%); max-height: min(86vh, 900px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 20px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; }
.kpi-line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kpi-line:last-child { border-bottom: 0; }
.kpi-line strong { direction: ltr; unicode-bidi: embed; }
.report-box { white-space: pre-wrap; background: rgba(0,0,0,.22); border: 1px solid var(--line); border-radius: 18px; padding: 16px; line-height: 1.85; overflow: auto; }
@media (max-width: 980px) {
  #appShell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-left: 0; border-bottom: 1px solid var(--line); }
  #nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { width: 100%; }
  .grid.three, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .main, .sidebar { padding: 16px; }
  #nav { grid-template-columns: 1fr; }
  .grid.two, .grid.three, .grid.four, .form-grid { grid-template-columns: 1fr; }
  .top-actions { flex-direction: column; }
  .top-actions > * { width: 100%; }
  .actions button { width: 100%; }
  table { min-width: 640px; }
}
.cart-row { display: grid; grid-template-columns: 1.4fr .8fr .8fr .9fr 1fr; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.025); margin-bottom: 10px; }
button.mini { padding: 7px 10px; border-radius: 10px; font-size: 12px; margin: 2px; }
.danger-badge { color: var(--danger); border-color: rgba(255,102,120,.28); background: rgba(255,102,120,.12); }
@media (max-width: 900px) { .cart-row { grid-template-columns: 1fr; } }

/* v1.9 Cloudflare D1 sync */
.sync-status { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--muted); font-weight: 900; font-size: 12px; white-space: nowrap; }
.sync-status.good { color: #90f0b6; border-color: rgba(144,240,182,.35); background: rgba(144,240,182,.08); }
.sync-status.warn { color: #ffe49a; border-color: rgba(255,228,154,.35); background: rgba(255,228,154,.08); }
.sync-status.bad { color: #ff9a9a; border-color: rgba(255,154,154,.35); background: rgba(255,154,154,.08); }
.login-modal { max-width: 560px; }
.danger-text { color: #ff9a9a; font-weight: 900; margin: 0; }


/* v2.0 privacy lock: nothing behind PIN is visible until authenticated */
body.auth-locked {
  background: #000 !important;
  overflow: hidden;
}
body.auth-locked #appShell,
body.auth-locked #toast {
  display: none !important;
  visibility: hidden !important;
}
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #000;
  color: var(--text);
}
.auth-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(246,198,74,.16), transparent 34%), radial-gradient(circle at bottom left, rgba(255,255,255,.08), transparent 28%);
  pointer-events: none;
}
.auth-card {
  position: relative;
  width: min(520px, 100%);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 28px;
  background: rgba(15,15,18,.96);
  box-shadow: 0 28px 100px rgba(0,0,0,.8);
  padding: 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.auth-brand h2 { margin: 0; font-size: 26px; }
.auth-brand p, .auth-note { margin: 4px 0 0; color: var(--muted); line-height: 1.7; }
.auth-form { display: grid; gap: 12px; }
.auth-form label { color: var(--muted); font-size: 13px; font-weight: 800; }
.auth-form input {
  background: #08080a;
  border-color: rgba(246,198,74,.28);
  font-size: 22px;
  letter-spacing: 6px;
  direction: ltr;
  text-align: center;
}
.auth-form input:focus {
  border-color: rgba(246,198,74,.78);
  box-shadow: 0 0 0 4px rgba(246,198,74,.12);
}

.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }

.danger-zone {
  border-color: rgba(255, 83, 83, .35) !important;
  background: linear-gradient(135deg, rgba(255, 83, 83, .10), rgba(255,255,255,.03)) !important;
}
.danger-zone h2 { color: #ffb0b0; }
.danger-zone p { color: var(--muted); line-height: 1.8; }
