:root {
  color-scheme: light;
  --bg: #FBFBFA;
  --surface: #FFFFFF;
  --surface-alt: #F7F6F3;
  --border: #EAEAEA;
  --border-strong: #E3E2DE;
  --border-warn: #EADFC0;
  --border-danger: #F3D3D3;
  --text: #111111;
  --text-soft: #2F3437;
  --muted: #787774;

  --red-pale: #FDEBEC;
  --red: #9F2F2D;
  --blue-pale: #E1F3FE;
  --blue: #1F6C9F;
  --green-pale: #EDF3EC;
  --green: #346538;
  --yellow-pale: #FBF3DB;
  --yellow: #956400;
  --neutral-pale: #ECEBE8;

  --btn-primary-bg: #111111;
  --btn-primary-fg: #FFFFFF;
  --btn-primary-hover: #333333;

  --font-sans: 'Instrument Sans', 'SF Pro Display', 'Helvetica Neue', 'Switzer', system-ui, sans-serif;
  --font-serif: 'Instrument Serif', 'Lyon Text', 'Newsreader', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, Menlo, monospace;

  --radius: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141312;
  --surface: #1C1B19;
  --surface-alt: #23211E;
  --border: #2E2C28;
  --border-strong: #38352F;
  --border-warn: #4A3F22;
  --border-danger: #4E2A2A;
  --text: #ECEAE5;
  --text-soft: #C7C3BB;
  --muted: #8E8A81;

  --red-pale: #331D1E;
  --red: #E08C8A;
  --blue-pale: #182833;
  --blue: #85BEDF;
  --green-pale: #1D2A1E;
  --green: #93C397;
  --yellow-pale: #2E2715;
  --yellow: #D9AC55;
  --neutral-pale: #2B2925;

  --btn-primary-bg: #ECEAE5;
  --btn-primary-fg: #141312;
  --btn-primary-hover: #FFFFFF;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  font-family: var(--font-sans);
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(620px 420px at 12% -6%, rgba(120, 110, 92, 0.05), transparent 62%),
    radial-gradient(720px 520px at 100% 0%, rgba(120, 110, 92, 0.04), transparent 60%);
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--text-soft); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-alt);
  padding: 1px 6px;
}

/* ── Layout ──────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--bg);
  color: var(--text);
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { display: flex; flex-direction: column; padding: 0 10px 24px; }
.brand-text {
  font-family: var(--font-serif);
  font-size: 24px;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand-badge {
  font-size: 10px;
  margin-top: 6px;
  color: var(--muted);
  background: var(--neutral-pale);
  padding: 3px 9px;
  border-radius: 999px;
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: block;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active {
  color: var(--text);
  background: var(--neutral-pale);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--text);
  border-radius: 2px;
}
.sidebar-tools { margin-top: 28px; }
.sidebar-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 8px;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.content {
  padding: 32px;
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  transition: box-shadow .2s ease;
}
.card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-header h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.card-actions { display: flex; gap: 8px; align-items: center; }

.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.two-col { grid-template-columns: 1fr; }
@media (min-width: 768px) { .two-col { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow .2s ease;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); }
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 30px;
  line-height: 1.1;
  margin-top: 6px;
  letter-spacing: -0.02em;
}
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Tables ──────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.card > .table, .card > form + .table { display: block; overflow-x: auto; white-space: nowrap; }
.table th, .table td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--border); }
.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--bg); }
.empty { color: var(--muted); text-align: center; padding: 28px !important; }
.delivery-row td { background: var(--bg); font-size: 12px; padding: 4px 12px 4px 28px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-pending, .badge.pending { background: var(--yellow-pale); color: var(--yellow); }
.badge-paid, .badge.paid { background: var(--green-pale); color: var(--green); }
.badge-expired, .badge.expired { background: var(--neutral-pale); color: var(--muted); }
.badge-cancelled, .badge.cancelled { background: var(--red-pale); color: var(--red); }
.badge-active, .badge.active { background: var(--green-pale); color: var(--green); }
.badge-inactive, .badge.inactive { background: var(--neutral-pale); color: var(--muted); }
.badge-warning { background: var(--yellow-pale); color: var(--yellow); }
.badge-reserved { background: var(--blue-pale); color: var(--blue); }
.badge-sold { background: var(--neutral-pale); color: var(--muted); }
.badge-success, .badge.success { background: var(--green-pale); color: var(--green); }
.badge-failed, .badge.failed { background: var(--red-pale); color: var(--red); }
.badge-dead { background: var(--neutral-pale); color: var(--muted); }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.alert-warning {
  background: var(--yellow-pale);
  border: 1px solid var(--border-warn);
  color: var(--yellow);
}
.alert-list { margin: 8px 0 0; padding-left: 20px; }
.alert-list li { margin: 4px 0; }
.alert-error {
  background: var(--red-pale);
  border: 1px solid var(--border-danger);
  color: var(--red);
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  text-align: left;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { cursor: wait; opacity: .58; transform: none; }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.btn-primary:hover { background: var(--btn-primary-hover); color: var(--btn-primary-fg); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-danger { background: var(--surface); border-color: var(--border-danger); color: var(--red); }
.btn-danger:hover { background: var(--red-pale); }
.btn-warning { background: var(--surface); border-color: var(--border-warn); color: var(--yellow); }
.btn-warning:hover { background: var(--yellow-pale); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-box { margin-top: 8px; }
.form-box h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin: 14px 0 5px;
  color: var(--text-soft);
}
input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--text);
}
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.form-row { display: flex; gap: 8px; align-items: center; }
.form-row input { flex: 1; }
.secret-field { display: flex; gap: 8px; align-items: end; }
.secret-field input { flex: 1; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 14px 14px; }
legend { font-size: 12px; font-weight: 600; color: var(--text-soft); padding: 0 6px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; font-weight: 400; }
.checkbox-row input { width: auto; }

/* ── Misc ────────────────────────────────────────────────── */
details > summary { cursor: pointer; font-size: 15px; }
details > summary:hover { color: var(--text); }
details[open] > summary { margin-bottom: 12px; }
details h3 { font-size: 13px; font-weight: 600; margin: 16px 0 6px; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.center { text-align: center; }
.credit-balance { font-family: var(--font-serif); font-size: 24px; margin-top: 8px; }
.total-row { display: flex; justify-content: space-between; padding: 4px 0; }
.total-row.total {
  font-weight: 600;
  font-size: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 8px;
}
.file-info { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}
.dropzone:hover { border-color: var(--text); background: var(--bg); }
.dropzone.dragover { border-color: var(--text); background: var(--bg); }
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}
.label-row label { margin: 0; }
.qr-preview {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}
.qr-preview img {
  max-width: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.qr-box { display: flex; justify-content: center; }
.qr-box img { max-width: 260px; }
.result-box, .preview-box, .template-preview {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.qty-input { width: 70px; text-align: center; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-chip {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.template-list { display: flex; flex-direction: column; gap: 12px; }
.template-item { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.template-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.template-preview { margin: 0; border: 0; background: var(--surface); border-radius: 0; }

.stock-counts { display: flex; gap: 8px; align-items: center; }

/* ── Login page ──────────────────────────────────────────── */
.card.center { text-align: center; }
.login-card {
  max-width: 420px;
  margin: 80px auto;
  padding: 32px;
}
.login-form { text-align: left; margin-top: 20px; }
.form-group { margin-top: 16px; }
.form-group:first-of-type { margin-top: 0; }
.login-submit { width: 100%; margin-top: 24px; }
.login-note { margin-top: 16px; font-size: 12px; }
@media (max-width: 768px) {
  .login-card { margin: 40px 16px; max-width: 100%; }
}

/* ── Legacy single-page tool (public/app.js) ─────────────── */
.result {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12px;
}
.result.error { border-color: var(--border-danger); color: var(--red); }
.hint { color: var(--muted); font-size: 13px; }
.hint.err { color: var(--red); }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }
.amount-big { font-family: var(--font-serif); font-size: 34px; letter-spacing: -0.02em; }
.qr-container { text-align: center; }
.qr-container img { max-width: 260px; }
.qr-string { width: 100%; margin-top: 8px; font-family: var(--font-mono); font-size: 12px; }
.qris-info { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.qris-info-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.qris-info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.qris-info-row:last-child { border-bottom: 0; }
.qris-info-row .label { color: var(--muted); }
.value.static { color: var(--blue); }
.value.dynamic { color: var(--green); }
.small.danger {
  border: 1px solid var(--border-danger);
  color: var(--red);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
.small.danger:hover { background: var(--red-pale); }

/* ── Dialog & theme toggle ──────────────────────────────── */
.theme-toggle {
  font: inherit;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.nav-logout { color: var(--red); }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); box-shadow: 0 4px 18px rgba(0,0,0,.08); animation: rise .2s ease; }
.toast.error { border-color: var(--border-danger); background: var(--red-pale); color: var(--red); }
.toast.success { border-color: var(--border-warn); background: var(--green-pale); color: var(--green); }

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  max-width: 380px;
  width: calc(100% - 40px);
}
.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.confirm-dialog[open] { animation: rise .25s cubic-bezier(0.16, 1, 0.3, 1); }
.confirm-msg { margin: 0 0 20px; font-size: 14px; font-weight: 500; }
.confirm-dialog .form-actions { margin-top: 0; justify-content: flex-end; }

/* ── Motion ──────────────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.content > * {
  animation: rise .5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.content > *:nth-child(2) { animation-delay: 40ms; }
.content > *:nth-child(3) { animation-delay: 80ms; }
.content > *:nth-child(4) { animation-delay: 120ms; }
.content > *:nth-child(5) { animation-delay: 160ms; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px;
    gap: 12px;
  }
  .sidebar-brand { padding: 0; }
  .brand-badge, .sidebar-label { display: none; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-tools { margin: 0; }
  .nav-item.active::before { display: none; }
  .content { padding: 20px; }
  .topbar { padding: 16px 20px; }
  .card { padding: 18px; }
  .card-header { align-items: flex-start; }
  .card-actions, .stock-counts { flex-wrap: wrap; }
  .secret-field { align-items: stretch; flex-wrap: wrap; }
  .secret-field input { flex-basis: 100%; }
  .toast-region { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
