/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
  --nav-h: 60px;
  --header-h: 56px;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: var(--nav-h);
}

/* ── Login screen ─────────────────────────────────────────────── */
#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
}
#login-screen h1 { color: #fff; font-size: 28px; margin-bottom: 8px; }
#login-screen p { color: rgba(255,255,255,.8); margin-bottom: 32px; }
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.pin-input {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}
.pin-digit {
  width: 54px; height: 54px;
  text-align: center;
  font-size: 24px; font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
  caret-color: var(--primary);
}
.pin-digit:focus { border-color: var(--primary); }

/* ── App shell ────────────────────────────────────────────────── */
#app { display: none; }
#app.active { display: block; }

/* ── Bottom navigation ────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  min-height: 44px;
  border: none;
  background: none;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; }

/* ── Pages ────────────────────────────────────────────────────── */
.page { display: none; padding-bottom: 24px; }
.page.active { display: block; }

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
  background: var(--surface);
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
}
.page-header h2 { font-size: 18px; font-weight: 700; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin: 12px 16px 0;
}
.card-sm { padding: 12px 16px; }

/* ── Dashboard ────────────────────────────────────────────────── */
.stock-hero {
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  border-radius: var(--radius);
  margin: 12px 16px 0;
  padding: 24px 20px;
  color: #fff;
  text-align: center;
}
.stock-hero .label { font-size: 14px; opacity: .85; margin-bottom: 8px; }
.stock-hero .value { font-size: 64px; font-weight: 800; line-height: 1; }
.stock-hero .unit { font-size: 18px; opacity: .8; margin-top: 4px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 16px 0; }
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }

/* ── List items ───────────────────────────────────────────────── */
.list-section { margin: 12px 16px 0; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  min-height: 60px;
  -webkit-tap-highlight-color: transparent;
}
.list-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list-item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.list-item:only-child { border-radius: var(--radius); }
.list-item-name { font-size: 16px; font-weight: 600; }
.list-item-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.badge {
  font-size: 14px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  background: #fef2f2;
  color: var(--danger);
}
.badge.zero { background: #f0fdf4; color: var(--success); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 20px;
  height: 44px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s;
}
.btn:active { opacity: .75; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; }
.btn-full { width: 100%; }
.btn-icon {
  width: 44px; height: 44px; padding: 0;
  background: var(--bg);
  border: none; border-radius: 10px;
  cursor: pointer; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.form-input, .form-select {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus { border-color: var(--primary); }
.form-input[type="number"] { -moz-appearance: textfield; }
.form-input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── Batch delivery rows ──────────────────────────────────────── */
#batch-rows { display: flex; flex-direction: column; gap: 10px; }
.batch-row {
  display: grid;
  grid-template-columns: 1fr 90px 44px;
  gap: 8px;
  align-items: center;
}
.batch-row .form-select, .batch-row .form-input { margin: 0; }

/* ── Modal / drawer ───────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px 32px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* ── Transaction list ─────────────────────────────────────────── */
.tx-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-qty { font-size: 17px; font-weight: 700; }
.tx-qty.positive { color: var(--danger); }
.tx-qty.negative { color: var(--success); }
.tx-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tx-note { font-size: 13px; color: var(--text-muted); }

/* ── Detail view (slide-in page) ──────────────────────────────── */
.detail-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s ease;
}
.detail-view.open { transform: translateX(0); }
.detail-header {
  background: var(--surface);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.back-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg);
  border: none; cursor: pointer; font-size: 20px;
}
.detail-title { font-size: 18px; font-weight: 700; }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Misc ─────────────────────────────────────────────────────── */
.section-title { font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 20px 16px 8px; text-transform: uppercase; letter-spacing: .05em; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.mt-3 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.linked-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 8px; border-radius: 99px;
  background: #f0fdf4; color: var(--success); font-weight: 600;
}
