/* Design-Tokens: Beim Einbau in die Werkzeugverwaltung nur diesen Block an deren Farben/Schrift anpassen. */
:root {
  --brand: #1d4ed8;
  --brand-600: #1e40af;
  --brand-50: #eff6ff;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --ok: #15803d; --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --crit: #b91c1c; --crit-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --text: #e5e7eb; --text-2: #9ca3af; --muted: #6b7280;
    --brand-50: #172554; --ok-bg: #052e16; --warn-bg: #422006; --crit-bg: #450a0a; --info-bg: #172554;
    --ok: #4ade80; --warn: #fbbf24; --crit: #f87171; --info: #93c5fd; --sidebar: #030712;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --text: #e5e7eb; --text-2: #9ca3af; --muted: #6b7280;
  --brand-50: #172554; --ok-bg: #052e16; --warn-bg: #422006; --crit-bg: #450a0a; --info-bg: #172554;
  --ok: #4ade80; --warn: #fbbf24; --crit: #f87171; --info: #93c5fd; --sidebar: #030712;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }

/* Layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; color: #fff; font-weight: 650; font-size: 15px; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .badge { margin-left: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 10px 6px; }
.sidebar .user { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar .user button { margin-top: 8px; }
.main { min-width: 0; padding: 22px 28px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; }

/* Karten / Grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: 1.6fr 1fr; }
.grid.half { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--text-2); }
.kpi.warn .value { color: var(--warn); }
.kpi.crit .value { color: var(--crit); }
a.kpi:hover { text-decoration: none; border-color: var(--brand); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .sub { display: block; color: var(--text-2); font-size: 12px; margin-top: 2px; }
.empty { padding: 32px; text-align: center; color: var(--text-2); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.crit { background: var(--crit-bg); color: var(--crit); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.faehrt { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.2); }
.dot.motor_an { background: #f59e0b; }
.dot.steht { background: #3b82f6; }
.dot.offline, .dot.keine_daten { background: #94a3b8; }

/* Buttons & Formulare */
button, .btn { font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-600); }
button.danger { color: var(--crit); }
button.ghost { background: transparent; border-color: transparent; }
button.small, .btn.small { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 550; color: var(--text-2); }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label.field { min-width: 150px; }
.hint { font-size: 12px; color: var(--text-2); line-height: 1.45; }
.callout { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.callout.warn { background: var(--warn-bg); border-color: transparent; color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 12px; color: var(--text-2); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Karte */
.map { height: 420px; border-radius: var(--radius); z-index: 0; }
.map.tall { height: calc(100vh - 120px); min-height: 420px; }
.live-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.vlist { max-height: calc(100vh - 120px); overflow-y: auto; }
.vitem { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.vitem:hover, .vitem.sel { background: var(--surface-2); }
.vitem .dot { margin-top: 5px; }
.vitem .meta { font-size: 12px; color: var(--text-2); margin-top: 3px; line-height: 1.5; }
.vmarker { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; }
.vmarker.offline { filter: grayscale(1) opacity(.7); }
.leaflet-popup-content { font-family: var(--font); font-size: 13px; }

/* Werte-Liste */
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
dl.props dt { color: var(--text-2); }
dl.props dd { margin: 0; font-weight: 550; }
.gauge { height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; }
.gauge > span { display: block; height: 100%; background: var(--ok); }
.gauge.low > span { background: var(--crit); }
.gauge.mid > span { background: #f59e0b; }

/* Balkendiagramm */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar-track span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 1000; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal header h2 { margin: 0; }
.modal header button { margin-left: auto; }
.modal .body { padding: 18px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); position: sticky; bottom: 0; }
.error-msg { color: var(--crit); font-size: 13px; margin-right: auto; align-self: center; }

/* Toast */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; animation: in .2s ease-out; }
.toast.crit { background: var(--crit); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.login .brand { color: var(--text); padding: 0 0 18px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }

@media (max-width: 1100px) {
  .grid.two, .grid.half, .live-layout { grid-template-columns: 1fr; }
  .vlist { max-height: 300px; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 1500; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 14px 16px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 90px 1fr 70px; }
  .map.tall { height: 60vh; }
}
@media print {
  .sidebar, .page-head .actions, .filters, .no-print { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; color: #000; font-size: 11px; }
  th { position: static; }
}
