/* ZeitBlick – Dashboard Styles (Auto Light/Dark) */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.10);
  --accent: #4f8cff;
  --accent-rgb: 79, 140, 255;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #0f1728;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="light"] {
  --bg: #f1f5f9; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a;
  --muted: #64748b; --border: rgba(15, 23, 42, 0.10);
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #131c2e; --surface-2: #0f1728; --text: #e2e8f0;
  --muted: #94a3b8; --border: rgba(255,255,255,.09);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}
h1, h2 { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px; width: 100%; max-width: 380px;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand h1 { font-size: 1.5rem; }
.brand p { margin: 2px 0 0; font-size: .85rem; }
#auth-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--muted); font-weight: 600; }
input, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid rgba(var(--accent-rgb), .5); border-color: transparent; }
input[type="color"] { padding: 4px; height: 42px; width: 52px; cursor: pointer; }
.btn {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 11px 14px;
  border: 1px solid transparent; cursor: pointer; transition: transform .05s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn.small { padding: 8px 12px; font-size: .85rem; background: var(--accent); color: #fff; }
.error { color: #ef4444; font-size: .85rem; }
.info { color: var(--accent); font-size: .85rem; }

/* ---------- Topbar / Nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.range-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.range-tabs button {
  font: inherit; font-weight: 600; font-size: .85rem; border: 0; background: transparent;
  color: var(--muted); padding: 6px 14px; border-radius: 9px; cursor: pointer;
}
.range-tabs button.active { background: var(--accent); color: #fff; }
.range-label { font-size: .85rem; color: var(--muted); min-width: 90px; text-align: center; }
.icon-btn {
  font: inherit; font-size: 1rem; line-height: 1; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
.tabbar {
  display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tabbar button {
  font: inherit; font-weight: 600; font-size: .9rem; border: 0; background: transparent;
  color: var(--muted); padding: 8px 12px; border-radius: 10px 10px 0 0; cursor: pointer; white-space: nowrap;
}
.tabbar button.active { color: var(--text); border-bottom: 2px solid var(--accent); }

.device-filter { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px 0; max-width: 1100px; margin: 0 auto; }
.dev-chip {
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 6px 14px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
}
.dev-chip.on { background: var(--accent); color: #fff; border-color: transparent; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.tab { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 340px; }

/* ---------- KPIs ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; }
.kpi .sub { font-size: .78rem; color: var(--muted); }

/* ---------- Goals strip ---------- */
.goals-strip { display: flex; flex-direction: column; gap: 8px; }
.goal-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); }
.goal-head { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 6px; }
.goal-bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.goal-bar > span { display: block; height: 100%; border-radius: 6px; }

/* ---------- Rank lists ---------- */
.ranklist { display: flex; flex-direction: column; gap: 10px; }
.rank {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  font-size: .9rem; position: relative;
}
.rank .rname { display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.rank .rtime { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.rank .rbar { grid-column: 1 / -1; height: 6px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.rank .rbar > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }

/* ---------- Legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; }
.legend .li { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Timeline (eine Spur pro Gerät) ---------- */
.timeline { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.tl-lane { display: flex; align-items: center; gap: 8px; }
.tl-label { width: 72px; flex: none; font-size: .74rem; color: var(--muted); font-weight: 600; }
.tl-track {
  position: relative; flex: 1; height: 30px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); overflow: hidden;
}
.tl-track .blk { position: absolute; top: 2px; bottom: 2px; border-radius: 3px; opacity: .9; }
.tl-track .blk:hover { opacity: 1; outline: 2px solid var(--text); z-index: 2; }
.tl-track .hour { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); }
.tl-axis { display: flex; justify-content: space-between; font-size: .68rem; color: var(--muted); margin-left: 80px; }

/* ---------- Manage ---------- */
.manage-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.mrow .mname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.mrow .mkind { font-size: .68rem; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.mrow .mtime { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.mrow select { width: auto; padding: 6px 8px; }
.manage-cats, .manage-goals { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.mcat { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.mcat .dot { width: 14px; height: 14px; border-radius: 4px; }
.mcat button, .mgoal button { margin-left: auto; }
.mgoal { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; text-decoration: underline; }
.cmp-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.compare-controls { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.compare-controls label { flex-direction: row; align-items: center; gap: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; z-index: 60;
  background: color-mix(in srgb, var(--bg) 55%, transparent); }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { font-size: 1.1rem; }
.modal-card .sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------- Loading ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 60%, transparent); z-index: 50; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .cmp-totals { grid-template-columns: 1fr 1fr; }
  .topbar { gap: 8px; }
  .range-label { min-width: 70px; }
  main { padding: 12px; }
}
@media (max-width: 420px) {
  .topbar-left strong { display: none; }
}
