:root {
  --bg: #0b1220;
  --surface: #121b2e;
  --surface-2: #1a2540;
  --border: #263559;
  --text: #e7ecf7;
  --text-muted: #93a0bd;
  --accent: #f59e0b;
  --accent-ink: #1a1305;
  --primary: #3b82f6;
  --danger: #ef4444;
  --danger-bg: #3a1418;
  --warn: #f59e0b;
  --warn-bg: #3a2a0c;
  --ok: #22c55e;
  --ok-bg: #0f2a1a;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font-family: inherit; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, #16213f 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 12px;
}
.brand h1 { font-size: 22px; }
.brand p { margin-top: 4px; font-size: 14px; }
#login-form label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
#login-form input {
  width: 100%; padding: 14px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 16px;
}
#login-form input:focus { outline: none; border-color: var(--primary); }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 14px;
  background: rgba(11,18,32,0.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 19px; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.content { flex: 1; padding: 16px 16px calc(96px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; width: 100%; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: rgba(11,18,32,0.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px 8px; font-size: 11px;
}
.tab-btn .tab-icon { font-size: 20px; }
.tab-btn.active { color: var(--accent); }

/* ---------- Cards / lists ---------- */
.summary-row { display: flex; gap: 10px; margin-bottom: 18px; }
.stat-card {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; text-align: center;
}
.stat-card .stat-num { font-size: 24px; font-weight: 700; }
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-card.warn .stat-num { color: var(--warn); }
.stat-card.ok .stat-num { color: var(--ok); }

.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 0; }

.search-bar {
  display: flex; gap: 8px; margin-bottom: 14px;
}
.search-bar input {
  flex: 1; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 15px;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.item-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.item-name { font-weight: 600; font-size: 16px; }
.item-sub { font-size: 13px; color: var(--text-muted); }
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

.item-meta-row { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-muted); }
.item-meta-row b { color: var(--text); font-weight: 600; }

.item-actions { display: flex; gap: 8px; margin-top: 8px; }
.item-actions button { flex: 1; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state .emoji { font-size: 40px; margin-bottom: 10px; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #5a1f24; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom)); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: none;
  font-size: 26px; box-shadow: 0 6px 18px rgba(245,158,11,0.35);
}

/* ---------- Modal (bottom sheet on mobile) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--border); border-bottom: none;
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; border-bottom: 1px solid var(--border); max-height: 80vh; }
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-sheet-handle {
  width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 0 auto 14px;
}
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 15px;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--primary); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}

/* ---------- Status pill selector (orders) ---------- */
.status-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.status-pill {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
  padding: 8px 12px; border-radius: 999px; font-size: 13px;
}
.status-pill.active { background: var(--primary); color: white; border-color: var(--primary); }

.link-btn { background: none; border: none; color: var(--primary); font-size: 14px; padding: 0; }

/* ---------- Demand review ---------- */
.demand-line-num { color: var(--accent); font-weight: 700; }
