:root {
  --cream: #f4ecdc;
  --paper: #fbf7ee;
  --paper-edge: #e6dcc6;
  --green: #1f3d2b;
  --green-2: #2c5a3f;
  --green-ink: #163020;
  --orange: #f26b1d;
  --orange-dark: #c9520d;
  --ink: #23221d;
  --muted: #6d675a;
  --line: #d9ceb6;
  --red: #b3261e;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(rgba(31, 61, 43, 0.05) 1px, transparent 1px);
  background-size: 6px 6px;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--green);
  color: var(--cream);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 5px solid var(--orange);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  background: var(--orange); color: var(--green-ink);
  border-radius: 4px;
  font-family: var(--display); font-weight: 800; font-size: 1.15rem; letter-spacing: 0.02em;
}
.brand-name {
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  font-size: 1.6rem; letter-spacing: 0.04em; line-height: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: 0.8rem; opacity: 0.75; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 3px; }
.topbar .spacer { flex: 1; }
.clock { font-family: var(--display); font-size: 1.5rem; font-weight: 600; letter-spacing: 0.05em; opacity: 0.9; }
.link-btn {
  background: none; border: 0; color: var(--cream); opacity: 0.75; cursor: pointer;
  font-size: 0.9rem; text-decoration: underline; text-underline-offset: 3px; padding: 0.25rem;
}
.link-btn:hover { opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 0; border-radius: var(--radius); cursor: pointer;
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  font-size: 1.1rem; padding: 0.7rem 1.2rem; line-height: 1;
  transition: transform 0.06s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--orange); color: #1b1208; box-shadow: 0 3px 0 var(--orange-dark); }
.btn-primary:hover { background: #ff7a2b; }
.btn-green { background: var(--green); color: var(--cream); box-shadow: 0 3px 0 var(--green-ink); }
.btn-green:hover { background: var(--green-2); }
.btn-ghost { background: transparent; color: var(--green); border: 2px solid var(--line); }
.btn-ghost:hover { border-color: var(--green); }
.btn:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Summary strip ---------- */
.summary {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.75rem;
  padding: 1rem 1.5rem 0.25rem;
  font-family: var(--display); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-size: 1rem;
}
.summary b { color: var(--green); font-size: 1.5rem; margin-right: 0.3rem; font-weight: 700; }
.summary .warn b { color: var(--orange-dark); }
.summary .bad b { color: var(--red); }

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.1rem;
  padding: 1rem 1.5rem 2.5rem;
  align-items: start;
}
.column {
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid var(--line);
  border-radius: 8px;
  min-height: 240px;
}
.column-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 0.9rem;
  background: var(--green); color: var(--cream);
  border-radius: 6px 6px 0 0;
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; font-size: 1.15rem;
}
.column[data-status='waiting_parts'] .column-head { background: #5b5a3c; }
.column[data-status='ready'] .column-head { background: var(--orange); color: #1b1208; }
.count {
  min-width: 1.8rem; height: 1.8rem; padding: 0 0.4rem; border-radius: 99px;
  display: grid; place-items: center; font-size: 1rem;
  background: rgba(255, 255, 255, 0.18);
}
.column[data-status='ready'] .count { background: rgba(0, 0, 0, 0.12); }
.cards { display: flex; flex-direction: column; gap: 0.8rem; padding: 0.8rem; }
.empty { color: var(--muted); font-style: italic; text-align: center; padding: 1.5rem 0.5rem; font-size: 0.95rem; }

/* ---------- Ticket card ---------- */
.ticket {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-left: 6px solid var(--green);
  border-radius: 4px;
  padding: 0.8rem 0.9rem 0.75rem;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 4px 10px -6px rgba(40, 30, 10, 0.35);
  cursor: pointer;
  text-align: left; width: 100%;
  transition: transform 0.1s, box-shadow 0.15s;
}
.ticket:hover { transform: translateY(-2px); box-shadow: 0 8px 18px -8px rgba(40, 30, 10, 0.45); }
.ticket:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.ticket.due-today { border-left-color: var(--orange); }
.ticket.overdue { border-left-color: var(--red); }
.ticket-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.ticket-no { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; }
.due {
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  font-size: 0.85rem; padding: 0.15rem 0.45rem; border-radius: 3px;
  background: #e9e1cd; color: var(--green);
  white-space: nowrap;
}
.due-today .due { background: var(--orange); color: #1b1208; }
.overdue .due { background: var(--red); color: #fff; }
.vehicle {
  font-family: var(--display); font-weight: 700; font-size: 1.35rem; line-height: 1.1;
  margin: 0.35rem 0 0.1rem; color: var(--green-ink);
}
.vehicle .color { font-weight: 500; color: var(--muted); font-size: 1.05rem; }
.customer { font-weight: 600; font-size: 0.98rem; }
.work {
  margin-top: 0.35rem; color: #3f3b31; font-size: 0.93rem; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ticket-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px dashed var(--line);
  font-size: 0.85rem; color: var(--muted);
}
.tech { display: inline-flex; align-items: center; gap: 0.3rem; }
.tech::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green-2); }
.move {
  background: none; border: 1.5px solid var(--line); border-radius: 4px; cursor: pointer;
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  font-size: 0.8rem; padding: 0.25rem 0.5rem; color: var(--green);
}
.move:hover { border-color: var(--green); background: #efe6d1; }

/* ---------- Dialog / form ---------- */
dialog {
  border: 0; padding: 0; border-radius: 10px;
  width: min(640px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  background: var(--paper); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.55);
}
dialog::backdrop { background: rgba(22, 32, 24, 0.55); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green); color: var(--cream);
  padding: 0.95rem 1.25rem; border-bottom: 4px solid var(--orange);
}
.dialog-head h2 {
  margin: 0; font-family: var(--display); text-transform: uppercase; letter-spacing: 0.06em; font-size: 1.5rem;
}
.close-x { background: none; border: 0; color: var(--cream); font-size: 1.8rem; line-height: 1; cursor: pointer; opacity: 0.8; }
.form { padding: 1.1rem 1.25rem 1.25rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field.full { grid-column: 1 / -1; }
.field label {
  font-family: var(--display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 0.92rem; color: var(--green);
}
.field label .opt { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; font-family: var(--body); font-size: 0.82rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 0.65rem 0.75rem;
  border: 2px solid var(--line); border-radius: var(--radius); background: #fff;
  font-size: 1.05rem;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(242, 107, 29, 0.25); }
.quick-dates { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.15rem; }
.chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 99px; cursor: pointer;
  padding: 0.2rem 0.65rem; font-size: 0.85rem; font-weight: 600; color: var(--green);
}
.chip:hover { border-color: var(--green); }
.form-error { grid-column: 1 / -1; color: var(--red); font-weight: 600; margin: 0; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 0.75rem; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 0.25rem; }
.form-actions .right { display: flex; gap: 0.75rem; margin-left: auto; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--green); color: var(--cream); padding: 0.75rem 1.2rem; border-radius: 6px;
  border-left: 5px solid var(--orange); font-weight: 600; z-index: 20;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5);
}

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    repeating-linear-gradient(-45deg, var(--green) 0 22px, #234631 22px 44px);
}
.login-card {
  width: min(420px, 100%);
  background: var(--paper); border-radius: 10px; overflow: hidden;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.6);
}
.login-stripe {
  height: 14px;
  background: repeating-linear-gradient(-45deg, var(--orange) 0 14px, #1b1208 14px 28px);
}
.login-body { padding: 1.75rem 1.75rem 2rem; }
.login-body h1 {
  font-family: var(--display); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--green); font-size: 2.2rem; line-height: 1; margin: 0 0 0.35rem;
}
.login-body p.lead { margin: 0 0 1.4rem; color: var(--muted); }
.login-body .field { margin-bottom: 1rem; }
.pin-input { font-family: var(--mono) !important; font-size: 1.6rem !important; letter-spacing: 0.45em; text-align: center; }
.login-body .btn { width: 100%; margin-top: 0.4rem; font-size: 1.25rem; padding: 0.9rem; }
.login-error { color: var(--red); font-weight: 600; min-height: 1.4em; margin: 0.25rem 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem; gap: 0.75rem; flex-wrap: wrap; }
  .brand-name { font-size: 1.3rem; }
  .clock { display: none; }
  .topbar .btn-primary { order: 3; width: 100%; }
  .summary { padding: 0.9rem 1rem 0; gap: 0.25rem 1.1rem; }
  .board { grid-template-columns: 1fr; padding: 0.9rem 1rem 2rem; }
  .form { grid-template-columns: 1fr; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; margin: 0; }
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0.25rem; margin-left: 1rem; }
.tabs a {
  color: var(--cream); text-decoration: none; opacity: 0.7;
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 1.05rem; padding: 0.45rem 0.8rem; border-radius: 4px;
}
.tabs a:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.tabs a.active { opacity: 1; background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 -3px 0 var(--orange); }

/* ---------- Manager view ---------- */
.mgr {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem;
  padding: 1.25rem 1.5rem 2.5rem; align-items: start;
}
.mgr-panel { background: var(--paper); border: 2px solid var(--line); border-radius: 8px; overflow: hidden; }
.mgr-panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 0.9rem; background: var(--green); color: var(--cream);
}
.mgr-panel[data-kind='late'] header { background: var(--red); }
.mgr-panel[data-kind='stuck'] header { background: #5b5a3c; }
.mgr-panel[data-kind='ready'] header { background: var(--orange); color: #1b1208; }
.mgr-panel h2 {
  margin: 0; font-family: var(--display); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; font-size: 1.2rem;
}
.mgr-panel[data-kind='ready'] .count { background: rgba(0, 0, 0, 0.12); }
.hint { margin: 0; padding: 0.6rem 0.9rem; color: var(--muted); font-size: 0.9rem; border-bottom: 1px dashed var(--line); }
.rows, .techs { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 1rem;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid #eee4cf;
}
.rows li:last-child, .techs li:last-child { border-bottom: 0; }
.rows .what { font-family: var(--display); font-weight: 700; font-size: 1.2rem; color: var(--green-ink); line-height: 1.15; }
.rows .what .tno { font-family: var(--mono); font-weight: 500; font-size: 0.78rem; color: var(--muted); margin-right: 0.35rem; }
.rows .who { color: #3f3b31; font-size: 0.93rem; grid-column: 1; }
.rows .tag {
  grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right;
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.95rem;
}
.rows .tag small { display: block; font-family: var(--body); font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 0.82rem; }
.mgr-panel[data-kind='late'] .tag { color: var(--red); }
.mgr-panel[data-kind='ready'] .tag { color: var(--orange-dark); }
.rows .none, .techs .none { display: block; color: var(--muted); font-style: italic; padding: 1.1rem 0.9rem; }
.techs li { display: grid; grid-template-columns: 8rem 1fr 2.5rem; align-items: center; gap: 0.75rem; padding: 0.65rem 0.9rem; border-bottom: 1px solid #eee4cf; }
.techs .name { font-weight: 600; }
.techs .name.unassigned { color: var(--muted); font-style: italic; font-weight: 500; }
.techs .bar { height: 12px; background: #ece3cf; border-radius: 99px; overflow: hidden; }
.techs .bar span { display: block; height: 100%; background: var(--green-2); border-radius: 99px; }
.techs .num { font-family: var(--display); font-weight: 700; font-size: 1.25rem; text-align: right; color: var(--green); }

@media (max-width: 900px) {
  .mgr { grid-template-columns: 1fr; padding: 1rem; }
}
@media (max-width: 640px) {
  .tabs { margin-left: 0; order: 2; }
  .techs li { grid-template-columns: 6rem 1fr 2rem; }
}
