:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --chip: #f1f5f9;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f8fafc;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f172a, #1e3a8a); padding: 20px;
}
.login-card {
  background: var(--panel); border-radius: 16px; padding: 28px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card label { display: block; margin: 14px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { width: 100%; margin-top: 6px; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  background: var(--bg); color: #fff; padding: 10px 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav button {
  background: transparent; color: #cbd5e1; border: 0; padding: 8px 12px; border-radius: 8px;
  font-size: 14px; cursor: pointer; font-weight: 600;
}
.nav button:hover { background: var(--bg-soft); color: #fff; }
.nav button.active { background: var(--brand); color: #fff; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-box .muted { color: #94a3b8; font-size: 13px; }
.view { padding: 18px; max-width: 1100px; margin: 0 auto; }

/* ---------- Forms / inputs ---------- */
input, select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 160px; }

/* ---------- Toggle (Empty / Full) ---------- */
.toggle { display: inline-flex; gap: 8px; }
.toggle-btn {
  font: inherit; font-weight: 600; cursor: pointer; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.toggle-btn[data-val=empty].active { background: #dbeafe; border-color: #2563eb; color: #1d4ed8; }
.toggle-btn[data-val=full].active { background: #fef08a; border-color: #ca8a04; color: #854d0e; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; cursor: pointer; background: var(--chip); color: var(--ink);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: #334155; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 18px; }

/* ---------- Cards / panels ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 14px; font-size: 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }

/* ---------- Stat ---------- */
.stat { display: flex; align-items: baseline; gap: 12px; }
.stat .num { font-size: 52px; font-weight: 800; color: var(--brand); line-height: 1; }
.stat .lbl { color: var(--muted); font-weight: 600; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8fafc; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.on_yard { background: #dcfce7; color: #166534; }
.badge.left { background: #e2e8f0; color: #475569; }
.badge.load-empty { background: #dbeafe; color: #1d4ed8; }   /* blue */
.badge.load-full { background: #fef08a; color: #854d0e; }    /* yellow */
.badge.dock { background: #ede9fe; color: #6d28d9; }         /* purple */
.badge.unclaimed { background: #ffedd5; color: #c2410c; }    /* orange */
.badge.claimed { background: #ccfbf1; color: #0f766e; }      /* teal */

/* Dashboard row highlight by claim state. */
tr.clickable.row-unclaimed { background: #fff7ed; }
tr.clickable.row-unclaimed:hover { background: #ffedd5; }
tr.clickable.row-claimed { background: #f0fdfa; }
tr.clickable.row-claimed:hover { background: #ccfbf1; }

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Dock board ---------- */
.dock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.dock {
  border: 2px solid var(--line); border-radius: 12px; padding: 12px 10px; text-align: center;
  display: flex; flex-direction: column; gap: 6px; min-height: 96px; background: #fff;
}
.dock.available { border-color: #86efac; background: #f0fdf4; }
.dock.occupied { border-color: #fbbf24; background: #fffbeb; }
.dock .dlabel { font-weight: 700; font-size: 14px; }
.dock .dstate { color: #16a34a; font-weight: 600; font-size: 13px; margin-top: auto; }
.dock .occ { font-size: 13px; line-height: 1.4; }
.dock .release { margin-top: auto; }

.yard-load {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.yard-load:last-child { border-bottom: 0; }
.yl-info { display: flex; align-items: center; gap: 8px; }
.yl-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Photo checklist ---------- */
.progress { font-weight: 700; margin: 6px 0 14px; }
.progress.done { color: var(--ok); }
.progress.pending { color: var(--warn); }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.slot {
  border: 2px dashed var(--line); border-radius: 12px; padding: 10px; text-align: center; position: relative;
  display: flex; flex-direction: column; gap: 8px; background: #fff;
}
.slot.captured { border-style: solid; border-color: var(--ok); }
.slot .slot-label { font-weight: 700; font-size: 13px; }
.slot .req { font-size: 11px; font-weight: 700; }
.slot .req.required { color: var(--danger); }
.slot .req.optional { color: var(--muted); }
.slot .thumb { width: 100%; height: 96px; object-fit: cover; border-radius: 8px; background: #f1f5f9; }
.slot .ph { height: 96px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 28px; background: #f8fafc; border-radius: 8px; }
.slot input[type=file] { display: none; }
.slot .cap-btn { font-size: 13px; }

/* ---------- Photo detail grid ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.photo {
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; position: relative;
}
.photo img { width: 100%; height: 150px; object-fit: cover; display: block; cursor: zoom-in; background: #f1f5f9; }
.photo .cap { padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.photo.missing { border-style: dashed; }
.photo.missing .ph { height: 150px; display: flex; align-items: center; justify-content: center; color: var(--danger); font-weight: 700; font-size: 13px; text-align: center; padding: 8px; }
.photo .del { background: var(--danger); color: #fff; border: 0; border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; }
.flag { color: var(--danger); font-size: 12px; font-weight: 700; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,.8); }
.modal img { position: relative; max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 90vw;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kv { background: var(--chip); border-radius: 10px; padding: 10px 12px; }
.kv .k { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.kv .v { font-weight: 700; margin-top: 2px; }
.section-title { font-size: 15px; font-weight: 700; margin: 18px 0 10px; }
.back-link { background: none; border: 0; color: var(--brand); font-weight: 600; cursor: pointer; padding: 0; margin-bottom: 10px; }

@media (max-width: 640px) {
  .view { padding: 14px; }
  .nav button { padding: 7px 9px; font-size: 13px; }
  .brand { font-size: 16px; }
}
