/* ==========================================================================
   Proviantomat Sicherheits-Dashboard — Mobile-First Brand-Styles
   Basis = Smartphone. Größere Screens via @media (min-width: …).
   Design-Tokens aus proviantomat-design (Brand-Red, Fraunces + Fira Sans)
   ========================================================================== */
:root {
  --p-brand-red: #85170D;
  --p-brand-red-2: #CB503D;
  --p-burgundy: #A12614;
  --p-green: #3D8E34;
  --p-blue: #007CBA;
  --p-paper: #FBF7EE;

  --ink: #1c1714;
  --ink-soft: #6b605a;
  --line: #e7ddd0;
  --bg: #f6f1e9;
  --card: #ffffff;

  --warn: #b8860b;
  --crit: #85170D;
  --ok: #3D8E34;
  --offline: #6b605a;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28,23,20,.08), 0 4px 16px rgba(28,23,20,.05);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Fira Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --tap: 46px;            /* Mindest-Tap-Target */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 16px;        /* 16px = kein Auto-Zoom bei iOS-Input-Focus */
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}
[x-cloak] { display: none !important; }
a { color: var(--p-blue); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(160deg, #2a0a06 0%, #85170D 55%, #A12614 100%);
}
.login-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  padding: 34px 26px calc(30px + var(--safe-b));
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-card .logo { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; color: var(--p-brand-red); margin-bottom: 4px; }
.login-card .sub { color: var(--ink-soft); font-size: .95rem; margin-bottom: 26px; }
.login-card input {
  width: 100%; padding: 15px 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px; font-family: var(--font-body); margin-bottom: 14px;
}
.login-card input:focus { outline: 2px solid var(--p-blue); border-color: var(--p-blue); }
.login-card .err { color: var(--p-brand-red); font-size: .9rem; min-height: 1.2em; margin-bottom: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font-body); font-weight: 600; font-size: 1rem;
  padding: 13px 18px; min-height: var(--tap);
  border: none; border-radius: var(--radius-sm);
  background: var(--p-brand-red); color: #fff; cursor: pointer;
  transition: background .15s ease; -webkit-appearance: none; appearance: none;
}
.btn:active { background: var(--p-burgundy); }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.ghost:active { background: #f0e8db; }
.btn.sm { padding: 9px 13px; min-height: 40px; font-size: .9rem; }

/* ---------- Topbar (kompakt, mobil) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--p-brand-red); color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.topbar .brand { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; line-height: 1.05; }
.topbar .brand small { font-family: var(--font-body); font-weight: 400; opacity: .82; font-size: .68rem; display: block; }
.topbar .spacer { flex: 1; }
.live-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.15);
}
.live-dot .dot { width: 9px; height: 9px; border-radius: 50%; background: #9ae6a0; }
.live-dot.live .dot { animation: pulse 2s infinite; }
.live-dot.down .dot { background: #ffb4ab; animation: none; }
.live-dot .txt { display: none; }      /* Label erst ab Tablet */
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(154,230,160,.6);} 70%{box-shadow:0 0 0 7px rgba(154,230,160,0);} 100%{box-shadow:0 0 0 0 rgba(154,230,160,0);} }

/* Icon-Buttons in der Topbar: mobil nur Icon, ab Tablet mit Label */
.tb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 12px;
  border: 1.5px solid rgba(255,255,255,.4); border-radius: var(--radius-sm);
  background: transparent; color: #fff; font-size: 1.25rem; cursor: pointer;
}
.tb-btn:active { background: rgba(255,255,255,.15); }
.tb-btn .t { display: none; font-family: var(--font-body); font-weight: 600; font-size: .9rem; }

/* ---------- Layout ---------- */
.layout { max-width: 1240px; margin: 0 auto; padding: 14px; padding-bottom: calc(28px + var(--safe-b)); }

/* ---------- KPIs (2 Spalten mobil) ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 15px; border-left: 4px solid var(--line); }
.kpi.crit { border-left-color: var(--crit); }
.kpi.warn { border-left-color: var(--warn); }
.kpi.ok { border-left-color: var(--ok); }
.kpi .num { font-family: var(--font-display); font-size: 1.8rem; font-weight: 600; line-height: 1; }
.kpi .lbl { color: var(--ink-soft); font-size: .78rem; margin-top: 6px; }

/* ---------- Panels / Filter ---------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px; margin-bottom: 14px; }
.panel h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; margin: 0 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 100%; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.field input, .field select {
  padding: 12px 13px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 16px; background: #fff; min-height: var(--tap); width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--p-blue); border-color: var(--p-blue); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-scroll { max-height: 168px; overflow-y: auto; padding: 2px; -webkit-overflow-scrolling: touch; }
.chip {
  font-size: .9rem; padding: 9px 13px; min-height: 40px; display: inline-flex; align-items: center;
  border-radius: 999px; cursor: pointer; border: 1.5px solid var(--line); background: #fff;
  color: var(--ink-soft); user-select: none;
}
.chip.on { background: var(--p-brand-red); border-color: var(--p-brand-red); color: #fff; }

.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: none; background: #fff; padding: 11px 14px; font-family: var(--font-body); font-size: .9rem; cursor: pointer; min-height: var(--tap); flex: 1; }
.seg.full { display: flex; width: 100%; }
.seg button.on { background: var(--p-brand-red); color: #fff; }

/* ---------- Event-Feed ---------- */
.feed { display: flex; flex-direction: column; }
.event {
  display: grid; grid-template-columns: 7px 1fr; column-gap: 12px; row-gap: 4px; align-items: start;
  padding: 13px 14px; background: var(--card); border-bottom: 1px solid var(--line);
  transition: background .4s ease;
}
.feed .event:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.feed .event:last-child { border-bottom: none; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.event.flash { background: #fff6d6; }
.event .bar { width: 7px; align-self: stretch; min-height: 40px; border-radius: 4px; background: var(--line); grid-row: 1 / span 2; }
.event.cat-tuer .bar { background: var(--p-brand-red); }
.event.cat-kasse .bar { background: var(--p-burgundy); }
.event.cat-strom .bar { background: var(--warn); }
.event.cat-offline .bar { background: var(--offline); }
.event.cat-technik .bar { background: var(--p-blue); }
.event .main { grid-column: 2; grid-row: 1; min-width: 0; }
.event .ttl { font-weight: 600; font-size: .98rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.event .meta { color: var(--ink-soft); font-size: .85rem; margin-top: 4px; }
.event .meta b { color: var(--ink); font-weight: 600; }
.event .right { grid-column: 2; grid-row: 2; display: flex; gap: 10px; align-items: baseline; margin-top: 5px; }
.event .time { font-size: .82rem; color: var(--ink-soft); }
.event .dur { font-size: .78rem; color: var(--ink-soft); }

.badge { font-size: .72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.badge.open { background: #fde8e6; color: var(--p-brand-red); }
.badge.closed { background: #e6f3e4; color: var(--p-green); }
.badge.cat { background: #eee6d8; color: var(--ink-soft); }
.badge.crit { background: var(--p-brand-red); color: #fff; }

.empty { text-align: center; padding: 44px 20px; color: var(--ink-soft); }
.group-head { font-family: var(--font-display); font-weight: 600; font-size: .95rem; color: var(--ink-soft); margin: 20px 0 8px; padding-left: 4px; }

/* ---------- Modal (mobil: Bottom-Sheet) ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(28,23,20,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal {
  background: var(--card); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px rgba(0,0,0,.3);
  width: 100%; max-width: 600px; max-height: 92svh; overflow: auto;
}
.modal-head { position: sticky; top: 0; background: var(--card); display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.15rem; }
.modal-head .x { margin-left: auto; background: none; border: none; font-size: 1.7rem; cursor: pointer; color: var(--ink-soft); line-height: 1; min-width: var(--tap); min-height: var(--tap); }
.modal-body { padding: 18px 20px; }
.modal-body .field { margin-bottom: 16px; }
.help { font-size: .82rem; color: var(--ink-soft); margin-top: 4px; line-height: 1.4; }
.modal-foot { position: sticky; bottom: 0; background: var(--card); display: flex; gap: 10px; padding: 14px 20px calc(16px + var(--safe-b)); border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1; }

.muted { color: var(--ink-soft); }
.toast {
  position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 13px 20px; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); z-index: 60; max-width: 90vw; text-align: center;
}

/* ==========================================================================
   Tablet ab 640px
   ========================================================================== */
@media (min-width: 640px) {
  .topbar { padding: 12px 22px; gap: 14px; }
  .topbar .brand { font-size: 1.2rem; }
  .topbar .brand small { font-size: .72rem; margin-top: -2px; }
  .live-dot .txt { display: inline; }
  .tb-btn { font-size: 1rem; }
  .tb-btn .t { display: inline; }
  .tb-btn .i { font-size: 1.05rem; }
  .layout { padding: 22px; }
  .kpis { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .field { flex: 1 1 auto; }
  .field.wide { flex-basis: 100%; }
  .modal-bg { align-items: center; padding: 18px; }
  .modal { border-radius: 16px; max-height: 88vh; }
  .modal-foot { justify-content: flex-end; }
  .modal-foot .btn { flex: 0 0 auto; }
  .event { grid-template-columns: 8px 1fr auto; column-gap: 16px; align-items: center; }
  .event .bar { grid-row: 1; }
  .event .main { grid-column: 2; grid-row: 1; }
  .event .right { grid-column: 3; grid-row: 1; flex-direction: column; gap: 2px; align-items: flex-end; margin-top: 0; text-align: right; min-width: 96px; }
}

/* ==========================================================================
   Desktop ab 1000px
   ========================================================================== */
@media (min-width: 1000px) {
  body { font-size: 15px; }
  .panel { padding: 18px; }
}
