*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4fb;
  --border: #dde3ee;
  --text: #1f2633;
  --muted: #6b7486;
  --blue: #2e6be6;
  --blue-dark: #2457c2;
  --blue-soft: #eaf1fe;
  --green: #1a8a4d;
  --green-soft: #e6f6ed;
  --amber: #a15f00;
  --amber-soft: #fff3df;
  --red: #c03838;
  --red-soft: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 10px rgba(16, 24, 40, .04);
  --mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .04);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  min-height: 58px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--blue); color: #fff;
  display: grid; place-items: center; font-size: 15px; font-weight: 800;
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--blue-soft); color: var(--blue); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.spacer-flex { flex: 1; }
.brand-sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); line-height: 1.2; }
.who { font-size: 13px; color: var(--muted); }

/* ── Catalog intro ── */
.intro h1 { font-size: 22px; line-height: 1.3; }
.intro p { color: var(--muted); margin-top: 4px; max-width: 70ch; }

/* ── Badges, pills, chips ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--green-soft); color: var(--green); border-color: #bfe6cf; }
.badge.busy { background: var(--amber-soft); color: var(--amber); border-color: #f3d9a8; }
.badge.bad { background: var(--red-soft); color: var(--red); border-color: #f2c4c1; }

.pill {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .2px;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.pill.complete { background: var(--green-soft); color: var(--green); }
.pill.partial { background: var(--amber-soft); color: var(--amber); }
.pill.failed, .pill.error, .pill.interrupted { background: var(--red-soft); color: var(--red); }
.pill.pending, .pill.running { background: var(--blue-soft); color: var(--blue); }
.pill.ok { background: var(--green-soft); color: var(--green); }

.chip {
  display: inline-block; font-size: 12px;
  padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.chip.score { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.tag {
  display: inline-block; font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 16px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-secondary { background: var(--surface); color: var(--blue); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--blue-soft); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ── Layout ── */
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.panel { display: flex; flex-direction: column; gap: 20px; }
.notice {
  border-radius: var(--radius); padding: 12px 16px;
  background: var(--amber-soft); color: #6b4300; border: 1px solid #f3d9a8;
}
.notice.info { background: var(--blue-soft); color: #1d4596; border-color: #c9dafb; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 18px 20px; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; justify-content: space-between; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.25; }
.stat-sub { color: var(--muted); font-size: 13px; }
.stat-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.numbers { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; }
.numbers b { color: var(--text); }

/* ── Live log ── */
.log {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  padding: 12px 14px; max-height: 360px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
.log .info { color: #2552b8; }
.log .warn { color: var(--amber); }
.log .error { color: var(--red); }
.log .done { color: var(--green); font-weight: 700; }

/* ── Toolbar ── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar input[type="search"], .toolbar select {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  outline: none;
}
.toolbar input[type="search"] { flex: 1 1 220px; min-width: 0; }
.toolbar select { flex: 0 1 220px; min-width: 0; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46, 107, 230, .15); }
.toolbar .count { color: var(--muted); font-size: 13px; margin-left: auto; }

/* ── Car filters (dashboard and catalog) ── */
.filters {
  display: grid; gap: 10px; align-items: center;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
}
.filters input[type="search"], .filters select {
  width: 100%; height: 38px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); outline: none;
}
.filters input:focus, .filters select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46, 107, 230, .15); }
.filters .filter-wide { grid-column: span 2; }
.filters-end { display: flex; align-items: center; justify-content: flex-end; gap: 10px; grid-column: -2 / -1; }
.filters-end .count { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ── Customers (admin) ── */
.b12 { margin-bottom: 12px; }
.customer-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.form-msg { margin-top: 12px; font-size: 13px; min-height: 18px; word-break: break-word; }
.form-msg.ok { color: var(--green); }
.form-msg.bad { color: var(--red); }
.row-actions { text-align: right; display: flex; gap: 8px; justify-content: flex-end; }

/* ── Cars ── */
.day { display: flex; flex-direction: column; gap: 14px; }
.day-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.day-head h2 { font-size: 18px; }
.day-head .meta { color: var(--muted); font-size: 13px; }
.day-head .spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }

.car {
  display: flex; flex-direction: column; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; padding: 0;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.car:hover { transform: translateY(-2px); border-color: #c5d3ee; box-shadow: 0 6px 18px rgba(16, 24, 40, .08); }
.car-photo { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.car-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.car-photo .no-photo { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.car-photo .pill { position: absolute; top: 8px; left: 8px; box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.car-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.car-house { font-size: 12px; font-weight: 700; color: var(--blue); text-transform: uppercase; letter-spacing: .4px; }
.car-title { font-weight: 700; font-size: 14px; line-height: 1.35; }
.car-sub { color: var(--muted); font-size: 12px; }
.car-chips, .car-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.empty {
  text-align: center; color: var(--muted);
  padding: 48px 16px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 700;
  text-align: left; padding: 10px 12px; white-space: nowrap; border-bottom: 1px solid var(--border);
}
td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8faff; }
tr.clickable { cursor: pointer; }
tr.selected { background: var(--blue-soft) !important; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }

/* ── Car modal ── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 28, 45, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px 16px; overflow-y: auto;
}
.dialog {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 1100px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
}
.dialog-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 18px; line-height: 1.3; }
.dialog-head .car-sub { margin-top: 2px; }
.dialog-head .spacer { flex: 1; }
.dialog-body { padding: 20px 22px 24px; display: flex; flex-direction: column; gap: 20px; }
.split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }
.sheet { display: flex; flex-direction: column; gap: 10px; }
.sheet a { display: block; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.sheet img { width: 100%; display: block; }
.sheet .missing { padding: 40px 16px; text-align: center; color: var(--amber); background: var(--amber-soft); border-radius: 8px; }
.facts { width: 100%; }
.facts th { background: none; border: 0; padding: 6px 12px 6px 0; width: 40%; color: var(--muted); font-weight: 600; font-size: 13px; }
.facts td { border: 0; padding: 6px 0; white-space: normal; }
.facts tr { border-bottom: 1px solid var(--border); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.photos a { display: block; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.photos a:hover img { transform: scale(1.03); }
.section-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── Login page ── */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login-card .brand { justify-content: center; font-size: 18px; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.field input {
  height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; background: var(--surface);
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46, 107, 230, .15); }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff;
  animation: spin .7s linear infinite;
}

/* ── Small screens ── */
@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters-end { grid-column: 1 / -1; }
  .customer-form { grid-template-columns: 1fr; }
  .topbar-inner { gap: 8px 12px; padding-top: 8px; padding-bottom: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
  .stats { grid-template-columns: 1fr; }
  main { padding-top: 16px; }
  .modal { padding: 0; }
  .dialog { border-radius: 0; min-height: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0s !important; }
}
