:root {
  --navy: #1b3a5c;
  --navy-dark: #142c46;
  --accent: #2e7d32;
  --accent-dark: #256428;
  --bg: #eef1f4;
  --panel: #ffffff;
  --border: #d5dce3;
  --text: #1f2933;
  --muted: #64748b;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; opacity: 0.8; }

.totals { display: flex; gap: 14px; align-items: center; }

.total-box {
  background: var(--navy-dark);
  border-radius: 8px;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  min-width: 120px;
}

.total-label { font-size: 11px; opacity: 0.75; }
.total-value { font-size: 20px; font-weight: 700; }
.total-sub { font-size: 12px; opacity: 0.85; }

.factor-box input {
  width: 70px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
}

.top-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn {
  font-size: 15px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary { background: var(--navy); color: #fff; }
.btn-secondary:hover { background: var(--navy-dark); }

.btn-ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

.panel .btn-ghost { color: var(--navy); border-color: var(--border); }
.panel .btn-ghost:hover { background: #f1f5f9; }

.btn-small { font-size: 13px; padding: 5px 10px; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  font-size: 18px;
  padding: 4px 8px;
}
.btn-danger:hover { background: #fdecea; }

button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Layout */
main { max-width: 1100px; margin: 18px auto 80px; padding: 0 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel h2 { margin: 0; font-size: 18px; color: var(--navy); }

/* Checklist */
.checklist { background: #fffbe9; border-color: #e7d9a0; }
.checklist ol { margin: 6px 0 4px; padding-left: 24px; }
.checklist li { margin-bottom: 7px; line-height: 1.45; }

/* Move details */
.details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 16px;
}

label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; color: var(--muted); gap: 4px; }

input[type="text"], input[type="date"], input[type="number"], textarea, select {
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  color: var(--text);
}

input:focus, textarea:focus, select:focus { outline: 2px solid var(--navy); outline-offset: 0; }

.notes-label { margin-top: 14px; }

/* Origin and destination access */
.sub-head { margin: 18px 0 8px; font-size: 15px; color: var(--navy); }
.access-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.access-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7f9fb;
}
.access-col h3 { margin: 0; font-size: 14px; color: var(--navy); }
select { background: #fff; }

/* Room adding */
.room-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.room-chip {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
  color: var(--navy);
}
.room-chip:hover { background: var(--navy); color: #fff; }

.custom-room { display: flex; gap: 8px; margin-bottom: 16px; }
.custom-room input { flex: 0 1 320px; }

.hint { color: var(--muted); font-size: 14px; }

/* Room cards */
.room-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}

.room-card.active { border-color: var(--navy); box-shadow: 0 0 0 1px var(--navy); }

.room-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f7f9fb;
  cursor: pointer;
}

.room-title { font-weight: 700; font-size: 17px; color: var(--navy); flex: 1; }

.room-stats { color: var(--muted); font-size: 14px; white-space: nowrap; }

.room-body { padding: 12px 14px 16px; }

.room-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

.analyzing {
  display: flex; align-items: center; gap: 10px;
  color: var(--navy); font-weight: 600; margin: 8px 0;
}

.spinner {
  width: 18px; height: 18px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Items table */
table.items { width: 100%; border-collapse: collapse; }

table.items th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
}

table.items td { padding: 5px 8px; border-bottom: 1px solid #edf1f5; vertical-align: middle; }

table.items input[type="text"] { width: 100%; padding: 8px 10px; }
table.items input[type="number"] { width: 90px; padding: 8px 10px; }

.items-wrap { overflow-x: auto; }
table.items select { padding: 8px 6px; font-size: 14px; max-width: 170px; }
table.items td:first-child input { min-width: 170px; }
table.items tr.flagged td { background: #fff7e6; }
table.items td.packing select { max-width: 130px; }
table.items tr.flagged td:first-child { box-shadow: inset 3px 0 0 #b45309; }

td.line-total { font-weight: 700; text-align: right; white-space: nowrap; }
th.num, td.num { text-align: right; }

.room-empty { color: var(--muted); font-size: 14px; padding: 8px 4px; }

/* Photo tray */
.photo-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 10px;
  padding: 10px;
  background: #f7f9fb;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.photo-thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-thumb .thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(179, 38, 30, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.tray-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.tray-count { color: var(--muted); font-size: 14px; }

/* Live capture widget */
.capture-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 280px;
  background: var(--navy-dark);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  z-index: 90;
  padding: 10px;
}

.cw-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cw-title { font-weight: 700; font-size: 14px; }
.cw-live { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: 0.85; }
.cw-dot { width: 9px; height: 9px; border-radius: 50%; background: #e53935; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.capture-widget video {
  width: 100%;
  border-radius: 8px;
  background: #000;
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.cw-target { font-size: 12px; margin: 8px 0; opacity: 0.9; }
.cw-target strong { color: #ffd166; }

.cw-actions { display: flex; gap: 8px; }
.cw-actions .btn { flex: 1; padding: 9px 10px; font-size: 14px; }
.capture-widget .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.4); }
.capture-widget .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

.btn.connected { background: var(--accent); border-color: var(--accent); }

/* Restore bar: shown only when unsaved work from the last session exists */
.restore-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: #fff6d6;
  border: 1px solid #e8d48a;
  border-radius: 8px;
  font-size: 14px;
}
.restore-bar[hidden] { display: none; }
.restore-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Modals: settings and survey library */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 20px 22px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}
.modal-wide { width: min(820px, 100%); }
.login-modal { width: min(420px, 100%); }
.login-field { display: block; font-weight: 600; font-size: 14px; }
.login-field input { display: block; width: 100%; margin-top: 6px; font-size: 16px; padding: 10px 12px; }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-help { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.details-grid .span2 { grid-column: 1 / -1; }

.lib-list { display: flex; flex-direction: column; gap: 8px; }
.lib-empty { color: var(--muted); padding: 12px 4px; }
.lib-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}
.lib-row.current { border-color: var(--accent); background: #eef6f1; }
.lib-info strong { font-size: 15px; }
.lib-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.lib-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-dark);
  color: #fff;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 15px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .details-grid { grid-template-columns: 1fr; }
  .access-grid { grid-template-columns: 1fr; }
  .topbar { gap: 10px; }
}
