:root {
  --bg: #f4f6f9; --surface: #fff; --surface-2: #eef1f6; --border: #dde2ea;
  --text: #1a2233; --text-dim: #5c6577; --accent: #a3140f; --accent-2: #c0201a;
  --green: #16794f; --red: #c0362c; --radius: 12px;
  --shadow: 0 1px 2px rgba(20,25,40,0.06), 0 4px 16px rgba(20,25,40,0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 340px; width: 100%; box-shadow: var(--shadow); text-align: center; }
.login-card input { width: 100%; margin: 14px 0; }
.muted { color: var(--text-dim); font-size: 14px; }
.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 6px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.brand-mark { font-size: 22px; }
nav.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; flex-wrap: wrap; }
nav.tabs button { border: none; background: transparent; color: var(--text-dim); padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
nav.tabs button.active { background: var(--accent); color: #fff; }
main { max-width: 1150px; margin: 0 auto; padding: 20px; }
.view { display: none; } .view.active { display: block; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card .label { font-size: 12px; text-transform: uppercase; color: var(--text-dim); font-weight: 700; }
.card .value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.card.green .value { color: var(--green); } .card.red .value { color: var(--red); }

.section-title { font-size: 15px; font-weight: 800; margin: 22px 0 10px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.btn { border: none; background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

select, input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 10px; border-radius: 8px; font-size: 14px; font-family: inherit;
}
textarea { width: 100%; resize: vertical; min-height: 50px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { overflow-x: auto; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.pill { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--text-dim); }
.empty { padding: 34px 20px; text-align: center; color: var(--text-dim); }
.bar-row { display: grid; grid-template-columns: 150px 1fr 80px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 6px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,12,18,0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow); }
.modal.wide { max-width: 800px; }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; } .field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px 16px; text-align: center; color: var(--text-dim); cursor: pointer; font-size: 14px; }
.status-line { font-size: 13px; color: var(--text-dim); margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { color: var(--accent-2); font-size: 12px; text-decoration: none; background: none; border: none; cursor: pointer; padding: 0; font-weight: 600; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }
@media (max-width: 640px) { th, td { padding: 6px 7px; font-size: 12px; } .card .value { font-size: 20px; } }

/* ---- Phone optimization: this app is mostly used one-handed, standing at the truck ---- */
select, input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], textarea {
  font-size: 16px; /* prevents iOS Safari from zooming in on focus */
}
.btn, nav.tabs button, .link-btn { min-height: 40px; }
.btn { min-height: 46px; }

@media (max-width: 680px) {
  header { padding: 10px 12px; gap: 8px; }
  main { padding: 12px; }
  nav.tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; scrollbar-width: none; }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button { flex: 0 0 auto; padding: 10px 14px; }
  .row { flex-direction: column; align-items: stretch; }
  .row > .field { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > * { width: 100%; }
  .btn { width: 100%; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn, .modal-actions button { width: 100%; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .upload-zone { padding: 34px 16px; font-size: 15px; }
  .grid-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 12px 14px; }
  table { font-size: 12.5px; }
}

