/* Predictive Damage — minimal SaaS dashboard
   Inspired by Autosend / Mobbin reference. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #ececec;
  --border-strong: #d9d9d9;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-faint: #9a9a9a;
  --accent: #1a1a1a;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --chip-bg: #f4f4f3;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 0 rgba(0,0,0,0.02);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 12px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 14px; border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, #1a1a1a, #3d3d3d);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
  letter-spacing: -0.02em;
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.workspace {
  margin-top: 12px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
.workspace-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: #111; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.workspace-name { font-weight: 500; font-size: 13px; }
.workspace-caret { margin-left: auto; color: var(--text-faint); }

.nav { margin-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px;
  cursor: pointer;
}
.nav-item:hover { background: var(--chip-bg); color: var(--text); }
.nav-item.active { background: var(--chip-bg); color: var(--text); font-weight: 500; }
.nav-item .ico { width: 16px; height: 16px; opacity: 0.8; }
.nav-item .badge {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  background: var(--surface); border: 1px solid var(--border); padding: 1px 6px; border-radius: 999px;
}
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot .nav-item { color: var(--text-muted); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; font-weight: 600; }
.topbar .crumb { color: var(--text-faint); font-size: 13px; }
.topbar .actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 500;
}
.btn:hover { border-color: #bcbcbc; }
.btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn.primary:hover { background: #000; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--chip-bg); }
.btn .caret { color: var(--text-faint); }

/* ---------- Email automation toggle (topbar) ---------- */
.auto-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 13px; color: var(--text); cursor: pointer; user-select: none;
}
.auto-toggle:hover { border-color: #bcbcbc; }
.auto-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.auto-toggle .auto-toggle-lbl { color: var(--text-muted); font-size: 12px; }
.auto-toggle .auto-toggle-state { font-weight: 500; min-width: 22px; }
.auto-toggle .switch {
  position: relative; width: 30px; height: 16px;
  background: #d6d6d4; border-radius: 999px; transition: background 160ms ease;
}
.auto-toggle .switch .knob {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.18);
  transition: transform 160ms ease;
}
.auto-toggle input:checked + .switch { background: var(--green); }
.auto-toggle input:checked + .switch .knob { transform: translateX(14px); }

/* hero automation status line */
.hero-mode {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px !important; font-size: 12px; color: var(--text-muted);
  padding: 4px 10px; background: var(--chip-bg); border-radius: 999px;
  border: 1px solid var(--border);
}
.hero-mode .dot { width: 6px; height: 6px; border-radius: 50%; }
.hero-mode.off .dot { background: #c7c7c7; }
.hero-mode.off { color: var(--text-muted); }

/* ---------- Content ---------- */
.content { padding: 24px 28px 80px; display: flex; flex-direction: column; gap: 22px; max-width: 1280px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-title { font-weight: 600; font-size: 13px; letter-spacing: -0.005em; }
.card-sub { color: var(--text-faint); font-size: 12px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.card-body { padding: 6px 0; }
.card-body.padded { padding: 18px; }

/* ---------- Hero band ---------- */
.hero {
  padding: 22px 22px;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px;
}
.hero h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.hero p { color: var(--text-muted); margin: 4px 0 0; font-size: 13px; }
.hero .stat { text-align: right; }
.hero .stat .num { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.hero .stat .lbl { color: var(--text-faint); font-size: 12px; }

/* ---------- Alert rows ---------- */
.alert-row {
  display: grid;
  grid-template-columns: 1.4fr repeat(6, minmax(0,1fr)) auto;
  gap: 0; align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.alert-row:first-child { border-top: none; }
.alert-row:hover { background: #fcfcfb; }

.cust { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cust-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #f1f1f0; color: #444; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.cust-name { font-weight: 500; letter-spacing: -0.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cust-meta { color: var(--text-faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.metric { padding-right: 12px; }
.metric .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; gap: 6px; }
.metric .val { font-weight: 500; font-size: 14px; margin-top: 2px; letter-spacing: -0.005em; }
.metric.muted .val { color: var(--text-faint); }

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red   { background: var(--red); }
.dot.gray  { background: #c7c7c7; }

.risk-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--chip-bg); color: var(--text);
  border: 1px solid var(--border);
}

.row-cta { display: flex; gap: 8px; }

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--border);
}
.kpi {
  padding: 16px 18px; border-right: 1px solid var(--border);
}
.kpi:last-child { border-right: none; }
.kpi .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 22px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .delta { font-size: 12px; color: var(--green); margin-top: 2px; }
.kpi .delta.down { color: var(--red); }

/* ---------- Sparkline (KPI trend) ---------- */
.spark { padding: 16px 18px 4px; border-top: 1px solid var(--border); }
.spark-bars { display: flex; align-items: flex-end; gap: 8px; height: 60px; }
.spark-bar { flex: 1; background: #ededeb; border-radius: 3px 3px 0 0; position: relative; }
.spark-bar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: #1a1a1a; border-radius: 3px 3px 0 0; }
.spark-labels { display: flex; gap: 8px; padding: 6px 0 0; color: var(--text-faint); font-size: 11px; }
.spark-labels span { flex: 1; text-align: center; }

/* ---------- Diary ---------- */
.diary { display: grid; grid-template-columns: repeat(3, 1fr); }
.diary-day { padding: 14px 18px; border-right: 1px solid var(--border); }
.diary-day:last-child { border-right: none; }
.diary-day .day { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.diary-slot { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.diary-slot:last-child { border-bottom: none; }
.diary-slot .time { font-family: var(--font-mono); font-size: 12px; color: var(--text); width: 48px; }
.diary-slot .who { font-size: 13px; }
.diary-slot .op { font-size: 12px; color: var(--text-faint); }

/* ---------- Customer detail (drawer / panel) ---------- */
.detail-mask {
  position: fixed; inset: 0; background: rgba(20,20,20,0.32);
  display: none; z-index: 40;
}
.detail-mask.open { display: block; }
.detail {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(960px, 92vw);
  background: var(--bg); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 220ms ease;
  z-index: 50; display: flex; flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.06);
}
.detail.open { transform: translateX(0); }
.detail-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.detail-head .close { margin-left: auto; }
.detail-body { flex: 1; overflow: auto; padding: 22px; display: grid; grid-template-columns: 1.05fr 1fr; gap: 18px; }
.detail-vehicle {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.detail-vehicle .cell { padding: 14px 16px; border-right: 1px solid var(--border); }
.detail-vehicle .cell:last-child { border-right: none; }
.detail-vehicle .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.detail-vehicle .val { font-weight: 500; margin-top: 2px; letter-spacing: -0.005em; }

.timeline { padding: 4px 18px 18px; }
.timeline-entry { padding: 14px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 88px 1fr; gap: 14px; }
.timeline-entry:last-child { border-bottom: none; }
.timeline-date { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.timeline-mileage { color: var(--text-faint); font-size: 11px; margin-top: 2px; }
.timeline-ops { font-size: 13px; }
.timeline-parts { color: var(--text-faint); font-size: 12px; margin-top: 4px; }

.upload {
  margin: 14px 18px 4px; padding: 14px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: #fcfcfb; display: flex; align-items: center; gap: 12px;
}
.upload .ico { width: 28px; height: 28px; border-radius: 7px; background: var(--chip-bg); display: grid; place-items: center; }
.upload .txt { font-size: 13px; }
.upload .sub { color: var(--text-faint); font-size: 12px; }
.upload .btn { margin-left: auto; }

.predictions { padding: 6px 0; }
.pred {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr auto; gap: 12px;
}
.pred:last-child { border-bottom: none; }
.pred-name { font-weight: 500; letter-spacing: -0.005em; }
.pred-reason { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.pred-meta { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; }
.pred-meta .m { font-size: 12px; color: var(--text-muted); }
.pred-meta .m strong { color: var(--text); font-weight: 500; }

.prob {
  display: grid; grid-template-rows: auto auto auto; align-items: center; justify-items: end; gap: 4px;
}
.prob-num { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.prob-bar { width: 70px; height: 5px; background: var(--chip-bg); border-radius: 3px; overflow: hidden; }
.prob-bar .fill { height: 100%; background: var(--text); }
.prob-bar.amber .fill { background: var(--amber); }
.prob-bar.red .fill { background: var(--red); }
.prob-cost { font-size: 12px; color: var(--text-faint); }

.bundle {
  margin-top: 14px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
}
.bundle .cell { border-right: 1px solid var(--border); padding: 0 14px; }
.bundle .cell:first-child { padding-left: 0; }
.bundle .cell:last-child { border-right: none; padding-right: 0; }
.bundle .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.bundle .val { font-size: 18px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; }
.bundle .total .val { font-size: 22px; }

.detail-actions { padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; }
.detail-actions .spacer { flex: 1; }

/* ---------- Email composer drawer ---------- */
.composer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 220ms ease;
  z-index: 60; display: flex; flex-direction: column;
}
.composer.open { transform: translateX(0); }
.composer-head { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.composer-head .close { margin-left: auto; }
.composer-body { padding: 18px 22px; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.field input, .field textarea {
  font-family: inherit; font-size: 13px; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
  background: var(--surface); resize: vertical;
}
.field input:focus, .field textarea:focus { outline: 2px solid #e5e5e5; outline-offset: 0; border-color: var(--border-strong); }
.composer-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }

/* ---------- Section refs (footer / new) ---------- */
.footer-card { padding: 14px 18px; display: flex; align-items: center; gap: 12px; }
.footer-card .pill { font-size: 11px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-faint); }
.footer-card .txt { font-size: 13px; }
.footer-card .arrow { margin-left: auto; color: var(--text-faint); }

/* ---------- Utility ---------- */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.right { margin-left: auto; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.divider { height: 1px; background: var(--border); margin: 8px 0; }
.kbd { font-family: var(--font-mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); background: var(--surface); }

/* small screens */
@media (max-width: 1100px) {
  .alert-row { grid-template-columns: 1.2fr repeat(4, minmax(0,1fr)) auto; }
  .alert-row .metric.hide-md { display: none; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .detail-body { grid-template-columns: 1fr; }
}
