:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #16202a;
  --muted: #6b7785;
  --line: #e2e8ee;
  --accent: #00897b;        /* Makita-ish teal */
  --accent-ink: #ffffff;
  --good: #2e9e5b;
  --warn: #c77700;
  --bad: #d23b3b;
  --shadow: 0 1px 3px rgba(16, 32, 42, .08), 0 6px 18px rgba(16, 32, 42, .05);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  background: #102027; color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.logo { font-size: 20px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  color: #cfd8dd; text-decoration: none; padding: 6px 14px; border-radius: 8px; font-weight: 550;
}
.tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
.tabs a.active { background: var(--accent); color: #fff; }
.conn { display: flex; align-items: center; gap: 10px; }

/* Buttons */
.btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 14px; border-radius: 8px; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: #c4ced6; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: #00766a; border-color: #00766a; }
.topbar .btn { border-color: transparent; }

/* Connection pill */
.pill { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-idle { background: #37474f; color: #cfd8dd; }
.pill-connecting { background: #b78a00; color: #fff; }
.pill-connected { background: var(--good); color: #fff; }
.pill-reconnecting { background: #8a6d00; color: #fff; }
.pill-error { background: var(--bad); color: #fff; }

/* Layout */
main { max-width: 1000px; margin: 0 auto; padding: 22px 20px 60px; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.empty { text-align: center; padding: 60px 20px; color: var(--ink); }
.empty .muted { margin-top: 4px; }

/* Battery live card */
.battery-card .bc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.battery-card .bc-model { font-size: 22px; font-weight: 680; }
.battery-card .bc-rom { font-family: ui-monospace, monospace; color: var(--muted); font-size: 13px; }
.bc-volts { display: flex; align-items: flex-end; gap: 6px; margin: 18px 0 6px; }
.bc-volts .v { font-size: 44px; font-weight: 720; line-height: 1; }
.bc-volts .u { color: var(--muted); font-size: 18px; margin-bottom: 5px; }
.cells { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 10px; margin: 16px 0; }
.cell { background: #f7fafb; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.cell .bar { height: 56px; display: flex; align-items: flex-end; }
.cell .bar > span { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; transition: height .3s; }
.cell.imbalanced .bar > span { background: var(--warn); }
.cell .mv { font-size: 13px; font-weight: 600; margin-top: 6px; }
.cell .lbl { font-size: 11px; color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 8px; }
.metric { background: #f7fafb; border-radius: 8px; padding: 10px 12px; }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .val { font-size: 18px; font-weight: 640; }

/* Badges */
.badge { font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; }
.badge-in-use { background: #e2f3ea; color: var(--good); }
.badge-retired { background: #eceff1; color: #607d8b; }
.badge-faulty { background: #fbe3e3; color: var(--bad); }
.banner { padding: 10px 14px; border-radius: 8px; font-weight: 600; margin: 14px 0; }
.banner-bad { background: #fbe3e3; color: var(--bad); }

/* Inventory */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.inv-list { display: grid; gap: 10px; }
.inv-row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  cursor: pointer; box-shadow: var(--shadow); text-decoration: none; color: inherit;
}
.inv-row:hover { border-color: #c4ced6; }
.inv-row .name { font-weight: 640; }
.inv-row .sub { font-family: ui-monospace, monospace; font-size: 12.5px; color: var(--muted); }
.inv-row .stats { display: flex; gap: 16px; align-items: center; font-size: 13.5px; }
.inv-row .stats b { font-weight: 640; }

/* Detail */
.back { display: inline-block; margin-bottom: 12px; color: var(--accent); text-decoration: none; font-weight: 550; }
.detail-grid { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }
#meta-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
#meta-form input, #meta-form select, #meta-form textarea { width: 100%; margin-top: 4px; color: var(--ink); }
.form-actions { display: flex; align-items: center; gap: 12px; }
.chart { width: 100%; height: 150px; margin-bottom: 10px; }
.scan-history { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #102027; color: #fff; padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 550; z-index: 50;
}
.toast.toast-bad { background: var(--bad); }
