/* PitFlow shack UI — high contrast, big targets, designed for a desktop monitor in a noisy environment. */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  background: #0f1419;
  color: #e6edf3;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: #8b95a1; font-weight: normal; }
.error { color: #ff7070; margin-top: 8px; min-height: 1.2em; font-size: 0.95em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Login ---------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
#login-form {
  background: #161b22;
  padding: 32px;
  border-radius: 12px;
  border: 1px solid #30363d;
  width: 360px;
}
#login-form h1 { margin: 0 0 4px; }
.login-logo { display: block; width: 300px; max-width: 100%; height: auto; margin: 4px auto 28px; border-radius: 18px; }
#login-form label { display: block; margin-top: 16px; font-size: 0.9em; color: #8b95a1; }
#login-form input { width: 100%; margin-top: 4px; padding: 10px; font-size: 1em; background: #0d1117; color: #e6edf3; border: 1px solid #30363d; border-radius: 6px; }
#login-form button { width: 100%; margin-top: 20px; }

/* ---------- App shell ---------- */
#app-view { display: flex; flex-direction: column; height: 100vh; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px 16px;
  flex-wrap: wrap;            /* on a phone, wrap the actions rather than hiding them off the right edge */
  padding: 10px 18px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}
/* PitFlow wordmark at the far left of every app header (matches FieldFlow's nav
   config). The word carries the brand; a small muted tag names the portal. */
.brand { display: inline-flex; align-items: center; }
.brand-wm { height: 22px; width: auto; display: block; }
.brand-sub { margin-left: 10px; font-size: 0.68em; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #8b95a1; }
.meta { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 0.95em; }
.meta-item { display: inline-flex; gap: 6px; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #6b7280; }
.dot.online { background: #3fb950; }
.dot.offline { background: #f85149; }
.dot.syncing { background: #d29922; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  flex: 1;
  min-height: 0;
}

/* ---------- Open pane ---------- */
.open-pane {
  border-right: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane-title { padding: 14px 18px; font-weight: 700; border-bottom: 1px solid #30363d; }
.open-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.open-list li {
  padding: 14px 18px;
  border-bottom: 1px solid #21262d;
  cursor: pointer;
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 12px;
  align-items: center;
}
.open-list li:hover { background: #1c2128; }
.open-list li.local { background: #2a1f12; opacity: 0.85; }
.open-list li.local:hover { background: #3a2a18; }
.open-list .unit { font-weight: 700; }
.open-list .since { color: #8b95a1; font-size: 0.9em; }
.empty { padding: 18px; }

/* ---------- Form pane ---------- */
.form-pane {
  padding: 22px 28px;
  overflow-y: auto;
}
.form-title { font-weight: 700; font-size: 1.1em; margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.entry-form label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.9em;
  color: #8b95a1;
  font-weight: 600;
}
.entry-form input {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 1.15em;
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 6px;
}
.entry-form input:focus { outline: none; border-color: #58a6ff; }
.entry-form small { display: block; margin-top: 4px; font-weight: normal; }

/* ---------- Buttons ---------- */
button { font: inherit; cursor: pointer; }
button.primary {
  background: #238636;
  color: white;
  border: 0;
  padding: 12px 18px;
  font-weight: 700;
  border-radius: 6px;
}
button.primary:hover { background: #2ea043; }
button.primary.big { width: 100%; padding: 18px; font-size: 1.1em; letter-spacing: 0.05em; }
button.ghost {
  background: transparent;
  color: #58a6ff;
  border: 1px solid #30363d;
  padding: 8px 14px;
  border-radius: 6px;
}
button.ghost:disabled { color: #4d5566; cursor: not-allowed; }
.link, a.link, button.link {
  background: transparent;
  color: #c9d1d9;
  border: 0;
  padding: 4px 8px;
  font-size: 0.9em;
  text-decoration: none;
  cursor: pointer;
}
.link:hover, a.link:hover, button.link:hover { color: #fff; text-decoration: underline; }

.app-footer {
  padding: 10px 18px;
  border-top: 1px solid #30363d;
  display: flex;
  justify-content: flex-end;
  background: #161b22;
}

/* hint colors */
small.ok { color: #3fb950; }
small.warn { color: #d29922; }
small.bad { color: #f85149; }

/* RETURN view */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0 18px; }
.kv > div { background: #161b22; border: 1px solid #30363d; padding: 10px 14px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.kv .muted { font-size: 0.85em; }
.kv b { font-size: 1.15em; }
.kv-big b { font-size: 1.4em; }

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.product-tile {
  padding: 16px 12px;
  background: #161b22;
  color: #e6edf3;
  border: 2px solid #30363d;
  border-radius: 8px;
  font-size: 1em;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.product-tile:hover { border-color: #58a6ff; }
.product-tile.selected { border-color: #3fb950; background: #1c2a1f; }
.product-tile small { display: block; font-weight: normal; color: #8b95a1; font-size: 0.85em; margin-top: 4px; }
.product-tile.no-rate { opacity: 0.55; }

/* ---------- Office / Admin pages ---------- */
body { overflow: auto; }
.office-main, .admin-main { padding: 24px 28px; max-width: 1200px; margin: 0 auto; overflow-y: auto; }

.banner {
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 22px;
  font-size: 0.95em;
  line-height: 1.45;
}
.banner code {
  background: rgba(255,255,255,0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}
.banner-info {
  background: #1c2530;
  border: 1px solid #2f4565;
  color: #c7d2dd;
}
.banner-info strong { color: #58a6ff; }
.banner-warning {
  background: #2a2410;
  border: 1px solid #6b5a1f;
  color: #f0d98a;
}
.banner-error {
  background: #2a1818;
  border: 1px solid #6b2f2f;
  color: #f5a5a5;
}
@media print { .banner { display: none; } }

/* Dark form controls — global backfill so inputs never fall through to the
   browser's white default against the dark UI. Specific rules (.entry-form,
   #login-form, .cab-form, date pickers) still win where they exist. */
input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 1em;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #58a6ff; }
input[type=checkbox] { accent-color: #58a6ff; }

/* Typeahead (search box with a filtered suggestion menu) */
.typeahead { position: relative; display: inline-block; }
.typeahead-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  min-width: 100%; max-height: 260px; overflow-y: auto;
  background: #161b22; border: 1px solid #30363d; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.typeahead-menu.hidden { display: none; }
.ta-opt { padding: 8px 12px; cursor: pointer; white-space: nowrap; color: #e6edf3; }
.ta-opt:hover, .ta-opt.active { background: #1c2128; }

.office-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 14px;
}
.office-controls .spacer { flex: 1; }
.chips { display: inline-flex; gap: 4px; margin-left: 8px; }
.chip {
  background: #21262d;
  color: #c7d2dd;
  border: 1px solid #30363d;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9em;
  cursor: pointer;
}
.chip:hover { border-color: #58a6ff; }
.chip.active { background: #1c2a3a; color: #e6edf3; border-color: #58a6ff; }
.office-controls input[type=date] {
  background: #0d1117; color: #e6edf3; border: 1px solid #30363d;
  padding: 8px 10px; border-radius: 6px; font-size: 1em; margin-left: 8px;
}
.office-controls label { font-size: 0.95em; color: #8b95a1; }

.office-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.kv-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kv-card b { font-size: 1.4em; }

.customer-block {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  margin-bottom: 18px;
  overflow: hidden;
}
.customer-header {
  display: flex;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid #30363d;
  background: #1c2128;
}
.customer-header h3 { margin: 0; font-size: 1.05em; }
.customer-total { font-weight: 700; font-size: 1.1em; }

table.lines { width: 100%; border-collapse: collapse; }
table.lines th, table.lines td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #21262d;
  font-size: 0.95em;
}
table.lines th { color: #8b95a1; font-weight: 600; font-size: 0.85em; }
table.lines td.num, table.lines th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lines td.small { font-size: 0.85em; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 24px 28px;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  width: 90%;
}
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-card label { display: block; margin: 14px 0; color: #8b95a1; font-size: 0.9em; }
.modal-card input, .modal-card select {
  width: 100%; margin-top: 4px; padding: 10px;
  background: #0d1117; color: #e6edf3; border: 1px solid #30363d; border-radius: 6px;
  font-size: 1em;
}

.invoice-card {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 12px 14px;
  margin: 10px 0;
}
.invoice-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 1.05em; }
.invoice-card ul { margin: 0; padding-left: 18px; font-size: 0.92em; }

/* Admin tabs */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid #30363d; }
.admin-tabs .tab {
  background: transparent; color: #8b95a1; border: 0; padding: 10px 18px;
  font-size: 1em; border-bottom: 2px solid transparent; cursor: pointer;
}
.admin-tabs .tab.active { color: #e6edf3; border-bottom-color: #58a6ff; }

.rate-block {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 14px;
}
.rate-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.rate-block-head h3 { margin: 0; font-size: 1.05em; }
.rate-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #21262d;
}
.rate-row:last-child { border-bottom: 0; }
.rate-row.default { background: #1c2128; padding: 10px 12px; border-radius: 6px; margin-bottom: 8px; border-bottom: 0; }
.rate-row.add { padding-top: 12px; }

button.small { font-size: 0.88em; padding: 6px 12px; }

/* ---------- Mode chooser ---------- */
.chooser-main { padding: 36px 28px; max-width: 900px; margin: 0 auto; text-align: center; }
.chooser-main h1 { margin-top: 0; }
.chooser-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 28px;
}
.chooser-tile {
  background: #161b22;
  color: #e6edf3;
  border: 2px solid #30363d;
  border-radius: 12px;
  padding: 28px 22px;
  cursor: pointer;
  text-align: center;
  transition: border-color 120ms ease, transform 120ms ease;
}
.chooser-tile:hover { border-color: #58a6ff; transform: translateY(-1px); }
.chooser-tile .big { font-size: 56px; margin-bottom: 10px; }
.chooser-tile .title { font-size: 1.2em; font-weight: 700; margin-bottom: 6px; }
.chooser-tile .muted { font-size: 0.92em; }
@media (max-width: 640px) { .chooser-grid { grid-template-columns: 1fr; } }

/* ---------- Cab (Solo Mode) ---------- */
.cab-main {
  padding: 18px 22px;
  max-width: 720px;
  margin: 0 auto;
  overflow-y: auto;
}
.cab-form { display: flex; flex-direction: column; gap: 8px; }
.cab-form label { font-size: 1em; color: #8b95a1; margin-top: 8px; }
.cab-form input {
  width: 100%;
  margin-top: 6px;
  padding: 16px 18px;        /* taller for gloves */
  font-size: 1.3em;          /* bigger so the operator can read at arm's length */
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 8px;
}
.cab-form input:focus { outline: none; border-color: #58a6ff; }
.product-grid.cab-products {
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 6px 0 14px;
}
.product-grid.cab-products .product-tile {
  padding: 22px 14px;
  font-size: 1.1em;
}
.cab-print { padding: 22px; font-size: 1.25em; letter-spacing: 0.06em; }

.cab-recent {
  margin-top: 22px;
  border-top: 1px solid #30363d;
  padding-top: 8px;
}
.cab-recent .pane-title { padding-left: 0; }
.cab-recent .open-list li { grid-template-columns: 110px 1fr auto; }

/* ---------- Scale-readout camera (Solo mode) ---------- */
.cam-panel {
  margin-bottom: 18px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 10px;
}
.cam-panel.cam-offline { opacity: 0.65; }
.cam-frame-wrap {
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cam-frame-wrap img { display: block; width: 100%; height: auto; max-height: 320px; object-fit: contain; }
.cam-status {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 0.75em;
  background: rgba(0,0,0,0.6);
  color: #e6edf3;
  padding: 2px 8px;
  border-radius: 999px;
}
.cam-panel.cam-offline .cam-status { color: #f85149; }
.cam-read {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.cam-read b { font-size: 1.25em; font-variant-numeric: tabular-nums; }
.cam-read .muted { font-size: 0.85em; }
.cam-read #cam-use { margin-left: auto; }

/* Small ghost button variants (Solo camera + office row actions) */
button.ghost.small { padding: 4px 10px; font-size: 0.85em; }
button.ghost.danger { color: #f85149; border-color: #6e2b2b; }
button.ghost.danger:hover { background: #2a1818; }
.row-actions { display: flex; gap: 6px; }

/* Manual (cash / walk-in) mode — discreet button + mode indicator */
.manual-btn {
  background: transparent;
  color: #8b95a1;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 3px 12px;
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.manual-btn:hover { color: #e6edf3; border-color: #58a6ff; }
.manual-btn.active { color: #f0b429; border-color: #f0b429; }
.cab-form .form-title { font-weight: 700; font-size: 1.05em; margin-bottom: 6px; }
/* Amber left-edge tint so it's obvious you're on a manual/cash ticket */
.entry-form.manual-mode, .cab-form.manual-mode {
  box-shadow: inset 4px 0 0 #f0b429;
  padding-left: 12px;
  border-radius: 6px;
}

/* Print CSS for office summary */
@media print {
  body { background: white; color: black; }
  .app-header, .office-controls, .admin-tabs, .meta, button { display: none !important; }
  .customer-block { background: white; border: 1px solid #999; page-break-inside: avoid; }
  .customer-header { background: #eee; color: black; }
  table.lines th, table.lines td { color: black; border-color: #ccc; }
  .kv-card { background: white; color: black; border-color: #ccc; }
}
