:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e3e7ee;
  --text: #141a24;
  --muted: #6b7686;
  --accent: #2563eb;
  --accent-soft: #e6eefe;
  --ok: #16a34a;
  --ok-soft: #e3f6ea;
  --err: #dc2626;
  --err-soft: #fde8e8;
  --warn: #d97706;
  --warn-soft: #fdf1df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218;
    --surface: #161b23;
    --surface-2: #1d232d;
    --border: #262e3a;
    --text: #e8ecf2;
    --muted: #8b95a5;
    --accent: #4f8bff;
    --accent-soft: #1b2a47;
    --ok: #22c55e;
    --ok-soft: #12301f;
    --err: #f05252;
    --err-soft: #3a1717;
    --warn: #f59e0b;
    --warn-soft: #3a2a0f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 13px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2, h3 { margin: 0 0 8px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
[hidden] { display: none !important; }

/* Kopfzeile */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
.brand img, .customer-logo { max-height: 44px; max-width: 200px; display: block; object-fit: contain; }
.wordmark { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-right { display: flex; align-items: center; gap: 16px; }
.mainnav { max-width: 1240px; margin: 0 auto; padding: 0 12px; display: flex; gap: 2px; overflow-x: auto; }
.mainnav a { padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.mainnav a:hover { color: var(--text); text-decoration: none; }
.mainnav a.active { color: var(--text); border-bottom-color: var(--accent); }

.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.usermenu-pop { position: absolute; right: 0; top: 46px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); min-width: 200px; padding: 6px; }
.usermenu-name { padding: 8px 10px; font-weight: 600; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.usermenu-pop a, .usermenu-pop button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.usermenu-pop a:hover, .usermenu-pop button:hover { background: var(--surface-2); text-decoration: none; }

/* Layout */
.container { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 32px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card.empty { color: var(--muted); }
.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.table-card { padding: 0; overflow-x: auto; }
.table-card.scroll { max-height: 520px; overflow-y: auto; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn-danger:hover { background: var(--err-soft); }
.btn-block { width: 100%; }
.btn-open { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-close { background: var(--surface-2); }
.btn-open:hover { background: var(--ok); filter: brightness(1.08); }
.link-danger { background: none; border: 0; color: var(--err); cursor: pointer; font: inherit; padding: 0; }

/* Tags */
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600; border: 0; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-err { background: var(--err-soft); color: var(--err); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-btn { cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; }

/* Tabellen */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.dim td { opacity: .5; }
.card > .table th:first-child, .card > .table td:first-child { padding-left: 4px; }
.table-card .table th:first-child, .table-card .table td:first-child { padding-left: 20px; }
form.inline { display: inline; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 18px; }
.form.narrow { max-width: 460px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13.5px; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.check, span.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px 18px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 6px; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; margin: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.logo-preview { max-height: 56px; max-width: 220px; object-fit: contain; background: var(--surface-2); padding: 6px; border-radius: 8px; align-self: flex-start; }
.codebox { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.codebox code { background: none; padding: 0; white-space: nowrap; }
.danger-zone { margin-top: 24px; display: flex; justify-content: flex-end; }

/* Zeitpläne */
.day { display: inline-block; width: 28px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); opacity: .4; }
.day.on { opacity: 1; color: var(--accent); }
.schedule-add { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.schedule-add input[type=time], .schedule-add select { width: auto; }
.days-pick { display: flex; gap: 4px; }
.day-check { flex-direction: row; cursor: pointer; }
.day-check input { position: absolute; opacity: 0; pointer-events: none; }
.day-check span { display: inline-block; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border); font-weight: 600; font-size: 13px; min-width: 38px; text-align: center; color: var(--muted); }
.day-check input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.day-check input:focus-visible + span { outline: 2px solid var(--accent); }

/* Meldungen */
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 500; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-err { background: var(--err-soft); color: var(--err); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); z-index: 100; max-width: calc(100% - 32px); }
.toast.err { background: var(--err); color: #fff; }

/* Login */
.login-wrap { min-height: calc(100vh - 200px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 32px; }
.login-card p { margin: -8px 0 6px; }

/* Dashboard */
.conn { font-size: 13px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok::before { background: var(--ok); }
.conn.err { color: var(--err); }
.conn.err::before { background: var(--err); }

.barrier { display: flex; flex-direction: column; gap: 16px; position: relative; overflow: hidden; }
.barrier::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--border); }
.barrier.state-open::before { background: var(--ok); }
.barrier.state-closed::before { background: var(--err); }
.barrier.state-moving::before { background: var(--warn); }
.barrier.state-error::before { background: var(--err); }
.barrier.state-sms::before { background: var(--accent); }
.barrier.inactive { opacity: .55; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-head h3 { margin: 0; font-size: 17px; }
.card-head p { margin: 2px 0 0; font-size: 13px; }

.pill { padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill-open { background: var(--ok-soft); color: var(--ok); }
.pill-closed { background: var(--err-soft); color: var(--err); }
.pill-moving { background: var(--warn-soft); color: var(--warn); }
.pill-error { background: var(--err); color: #fff; }
.pill-sms { background: var(--accent-soft); color: var(--accent); }
.pill-offline { background: var(--text); color: var(--bg); }
.state-offline .barrier-visual { opacity: .35; }

/* Schranken-Grafik (SVG, Winkel setzt dashboard.js) */
.barrier-visual { display: block; width: 100%; height: 150px; background: var(--surface-2); border-radius: 10px; padding: 6px 0 0; }
.bv-road { fill: var(--border); }
.bv-rest, .bv-housing { fill: var(--muted); }
.bv-housing { opacity: .9; }
.bv-pivot { fill: var(--surface); stroke: var(--muted); stroke-width: 3; }
.bv-arm { fill: url(#bv-stripes); }
.bv-arm-edge { fill: none; stroke: rgba(0, 0, 0, .18); stroke-width: 1; }
.bv-red { fill: #e11d48; }
.bv-white { fill: #ffffff; }
.bv-lamp { fill: var(--surface); }
.state-open .bv-lamp { fill: var(--ok); }
.state-closed .bv-lamp, .state-error .bv-lamp { fill: var(--err); }
.state-moving .bv-lamp { fill: var(--warn); animation: bv-blink 1s steps(2, start) infinite; }
.state-unknown .bv-arm, .state-error .bv-arm { opacity: .45; }
@keyframes bv-blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .state-moving .bv-lamp { animation: none; } }
.contacts { flex-wrap: wrap; }
.table.kv td { padding: 6px 12px; }
.table.kv td:first-child { color: var(--muted); width: 220px; }


.contacts { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.contact { display: inline-flex; align-items: center; gap: 6px; }
.led { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.led.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn { padding: 12px; }
.actions .btn-status { grid-column: span 2; }
.actions.three { grid-template-columns: 1fr auto 1fr; }
.btn-stop { background: var(--warn); border-color: var(--warn); color: #fff; padding-left: 18px; padding-right: 18px; }
.btn-stop:hover { background: var(--warn); filter: brightness(1.08); }

.aux-row { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-weight: 600; }
.aux-row > span:first-child { flex: 1; }
.switch { position: relative; width: 46px; height: 26px; border-radius: 999px; border: 0; background: var(--border); cursor: pointer; transition: background .2s; padding: 0; flex: none; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch.on { background: var(--ok); }
.switch.on .knob { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }


.sms-reply { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.sms-reply .label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.sms-reply p { margin: 0; white-space: pre-wrap; word-break: break-word; }

.card-foot { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; margin-top: auto; }
.foot-link { font-weight: 600; font-size: 13px; }

.solar { display: flex; flex-direction: column; gap: 10px; }
.solar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.solar .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.metric.warn { background: var(--err-soft); }
.metric.warn .v { color: var(--err); }
.metric .k { font-size: 11.5px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .v { font-size: 18px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.subtitle { margin: 2px 0 0; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.metric .v small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.spark { width: 100%; height: 60px; display: block; }
.spark-line { fill: none; stroke: var(--warn); stroke-width: 2; }
.spark-area { fill: var(--warn-soft); stroke: none; }
.spark-label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

@media (max-width: 720px) {
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .grid { grid-template-columns: 1fr; }
  .topbar-inner { padding: 8px 16px; }
  .container { padding: 18px 16px 48px; }
  .brand img, .customer-logo { max-height: 34px; max-width: 120px; }
}
