:root {
  --bg: #f1f4f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #6b7a8f;
  --line: #e2e8f0;
  --brand: #1e3a5f;
  --brand-2: #2f5d8a;
  --accent: #0e9f6e;
  --warn: #d97706;
  --danger: #dc2626;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 30, 54, 0.08), 0 4px 14px rgba(16, 30, 54, 0.06);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
h1, h2, h3 { margin: 0 0 10px; }
h2 { font-size: 22px; }

/* ---------- views ---------- */
.view { min-height: 100vh; }

/* ---------- login ---------- */
#login-view, #pw-view { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 36px 32px; width: 100%; max-width: 400px; text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h1 { margin: 8px 0 4px; font-size: 24px; }
.login-card form { text-align: left; margin-top: 18px; }

/* ---------- forms ---------- */
label { display: block; margin-bottom: 12px; font-weight: 500; font-size: 14px; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], select, textarea {
  width: 100%; padding: 9px 11px; margin-top: 4px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
textarea { resize: vertical; min-height: 70px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.check-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 500; }
.check-row label { margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: background 0.15s;
}
.btn:hover { background: #f1f5f9; }
.btn.active { background: var(--warn); border-color: var(--warn); color: #fff; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 60; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; margin-top: 2px; max-height: 220px;
  overflow-y: auto; box-shadow: 0 8px 24px rgba(15,23,42,.12); }
.ac-item { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.ac-item:hover, .ac-item.hi { background: #f1f5f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.success { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- alerts / toast ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert.ok { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
#toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 8px;
  box-shadow: var(--shadow); font-size: 14px; animation: slidein 0.2s ease-out; max-width: 340px;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--accent); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- app layout ---------- */
#app-view { display: flex; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--brand); color: #e8eef6;
  display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px; font-size: 19px; font-weight: 700; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; }
.nav-item {
  background: none; border: none; color: #c9d6e8; text-align: left; padding: 10px 12px;
  border-radius: 8px; font-size: 14.5px; cursor: pointer; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.16); color: #fff; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,0.14); }
.user-chip { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--brand-2); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.sidebar-foot .btn { color: var(--ink); }
#user-role { color: #aebdd2; text-transform: capitalize; }
.main { flex: 1; padding: 26px 30px; max-width: 1280px; min-width: 0; }
@media (max-width: 760px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; min-height: 0; position: static; }
  #nav { flex-direction: row; overflow-x: auto; padding: 0 10px 10px; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .main { padding: 16px; }
}

/* ---------- cards / stats ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-card .num { font-size: 30px; font-weight: 700; }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat-card.blue .num { color: var(--info); }
.stat-card.green .num { color: var(--accent); }
.stat-card.amber .num { color: var(--warn); }
.stat-card.red .num { color: var(--danger); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { font-size: 16px; margin-bottom: 12px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f8fafc; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f1f5f9; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  font-weight: 600; white-space: nowrap;
}
.badge.ordered { background: #dbeafe; color: #1d4ed8; }
.badge.partially_received { background: #fef3c7; color: #b45309; }
.badge.received { background: #d1fae5; color: #065f46; }
.badge.draft { background: #e2e8f0; color: #475569; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.not_required { background: #f1f5f9; color: var(--muted); }
.badge.pending { background: #fef3c7; color: #b45309; }
.badge.out_for_delivery { background: #dbeafe; color: #1d4ed8; }
.badge.loaded { background: #ccfbf1; color: #0f766e; }
.checklist-item { padding: 10px 0; border-top: 1px solid var(--border); }
.checklist-item:first-child { border-top: none; }
.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.badge.delivered { background: #d1fae5; color: #065f46; }
.badge.low { background: #fee2e2; color: #991b1b; }
.badge.stock { background: #e0e7ff; color: #3730a3; }
.badge.customer { background: #fce7f3; color: #9d174d; }
.badge.ok-stock { background: #d1fae5; color: #065f46; }
.badge.role-admin { background: #ede9fe; color: #5b21b6; }
.badge.role-manager { background: #dbeafe; color: #1d4ed8; }
.badge.role-staff { background: #e2e8f0; color: #475569; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.filters label { margin: 0; font-size: 13px; min-width: 140px; flex: 1; }
.filters .grow { flex: 2; min-width: 200px; }
.filters label.checkline { flex: 0 0 auto; min-width: 0; display: flex; align-items: center; gap: 6px; white-space: nowrap; padding-bottom: 10px; }
.filters label.checkline input { width: auto; margin: 0; }
.tabs { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.tab {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tab:not(.active):hover { border-color: var(--brand-2); color: var(--ink); }

/* ---------- order detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.item-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.item-card.insp-damaged { border-left: 4px solid #dc2626; }
.item-card.insp-short { border-left: 4px solid #d97706; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.photo-strip img {
  width: 84px; height: 84px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid var(--line);
}
.photo-strip img:hover { outline: 2px solid var(--brand-2); }
.insp-section { margin-top: 4px; }
.insp-group { margin: 12px 0 4px; }
.insp-label { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.req { color: var(--danger); }
.opt-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .opt-row { grid-template-columns: 1fr; } }
.opt-card {
  display: block; border: 2px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; margin: 0;
  transition: border-color .15s, background .15s;
}
.opt-card:hover { border-color: var(--brand-2); }
.opt-card input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.opt-card:has(input:checked) { border-color: var(--brand); background: #eff6ff; }
.opt-card:has(input:focus-visible) { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.opt-title { display: block; font-weight: 700; font-size: 14px; }
.opt-sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.missing-wrap { margin-top: 10px; }
.missing-wrap label { margin-bottom: 4px; }
.insp-error { margin: 10px 0 0; }
.insp-form .btn-row { margin-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.timeline li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .t { color: var(--muted); font-size: 12px; }

/* ---------- modal ---------- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 640px; box-shadow: var(--shadow); position: relative; }
.modal.wide { max-width: 860px; }
.modal-x { position: absolute; top: 8px; right: 10px; border: none; background: none;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; z-index: 5; }
.modal-x:hover { color: #0f172a; background: #f1f5f9; }
.modal.wide { max-width: 860px; }
.modal h2 { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.order-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: end; }
.order-total { text-align: right; font-size: 17px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.order-item-row label { margin: 0; font-size: 12px; }
@media (max-width: 640px) { .order-item-row { grid-template-columns: 1fr 1fr; } }

/* ---------- lightbox ---------- */
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.88); z-index: 300;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; padding: 20px;
}
#lightbox img { max-width: 92vw; max-height: 82vh; border-radius: 8px; }
#lightbox-close { align-self: flex-end; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); }
