/* Truck Manager — dark theme.
   Desktop: full-screen layout, the table uses the whole viewport.
   Mobile:  readable on an iPhone 16 in landscape (852 x 393 CSS px) —
   the table scrolls horizontally inside a full-bleed shell. */

:root {
  --bg: #0b0d12;
  --surface: #151922;
  --surface-2: #1d2230;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-2: #28406e;
  --danger: #ff5c5c;
  --ok: #38d39f;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Shell: full-bleed, fills the viewport height. */
.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  padding: 14px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.app-header h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: 0.3px;
}

.header-nav { display: flex; align-items: center; gap: 14px; }
.header-nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 15px;
}

.header-form { margin: 0; }
.linkbtn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}
.linkbtn:active { opacity: 0.7; }

.content {
  flex: 1;
  padding: 16px 20px 28px;
}

h2 { font-size: 17px; margin: 20px 0 10px; }
p.muted, .muted { color: var(--muted); font-size: 14px; }

/* Buttons - plain, flat */
.btn {
  display: inline-block;
  padding: 13px 18px;
  margin: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn:active { background: #262c3b; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:active { background: #3d78e8; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 9px 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }

/* Toolbar above the table */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.table-toolbar .muted { margin: 0; }
.toolbar-actions { display: flex; gap: 10px; }
.btn-summary { background: #8b94a7; border-color: #8b94a7; color: #0b0d12; }
.btn-summary:active { background: #7a8396; }

/* The fleet table */
table.fleet {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
  font-size: 14px;
}

table.fleet th,
table.fleet td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.fleet thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  z-index: 2;
}

/* Make the table wrapper the scroll container so sticky headers work. */
.table-wrap {
  width: 100%;
  max-height: calc(100dvh - 160px);
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table.fleet tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
table.fleet tbody tr:hover { background: var(--accent-2); }
table.fleet tbody tr[data-edit-url] { cursor: pointer; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.calc { color: var(--ok); font-weight: 600; }
td.calc .danger { color: var(--danger); }
td.money { color: #ffd479; }
td.empty, .empty { color: var(--muted); }
td .danger, .danger { color: var(--danger); font-weight: 600; }

table.fleet tfoot th {
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
}
table.fleet tfoot .total-label { text-align: left; }
table.fleet tfoot .calc, table.fleet tfoot td.calc { color: var(--text); }

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

/* Summary table: compact, columns sized to content. */
table.summary-table { min-width: 0; width: 100%; }
table.summary-table th, table.summary-table td { padding: 9px 16px; }

/* Row actions */
td.actions { text-align: right; white-space: nowrap; }
.iconbtn {
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 28px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.iconbtn:active { background: #262c3b; }
.iconbtn.danger { color: var(--danger); border-color: var(--danger); }
.row-del { display: inline; margin: 0; }

/* Forms */
.form-card {
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px 16px;
}
.field { margin-top: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
input, select {
  width: 100%;
  padding: 12px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
.errorlist { color: var(--danger); font-size: 13px; list-style: none; padding: 0; margin: 6px 0 0; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.messages li {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}
.messages li.success { border-left: 3px solid var(--ok); }

/* Auth */
.auth-card {
  max-width: 380px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.auth-card h1 { font-size: 24px; margin: 0 0 4px; }
.auth-card .btn { width: 100%; margin-top: 18px; }
.qr { display: block; margin: 16px auto; width: 180px; height: 180px; background: #fff; border-radius: 12px; padding: 8px; }
code.secret { display: block; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; font-size: 13px; margin-top: 8px; }

/* ------------------------------------------------------------------
   iPhone 16 landscape (852 x 393): keep it readable.
   The shell is already full-bleed; we tighten the header, shrink the
   table font slightly, and let the table scroll horizontally so every
   column stays legible without squishing.
   ------------------------------------------------------------------ */
@media (max-width: 900px) and (orientation: landscape) {
  .app-header { padding: 10px 16px 8px; }
  .app-header h1 { font-size: 17px; }
  .content { padding: 10px 14px 16px; }
  .table-toolbar { margin-bottom: 8px; }
  .table-toolbar .muted { font-size: 12px; }
  table.fleet { font-size: 13px; min-width: 900px; }
  table.fleet th, table.fleet td { padding: 7px 8px; }
}

/* Portrait phones: same treatment. */
@media (max-width: 600px) and (orientation: portrait) {
  .app-header { padding: 10px 14px 8px; }
  .content { padding: 10px 12px 16px; }
  table.fleet { font-size: 13px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
