:root {
  color-scheme: light;
}
body { margin: 0; padding: 0; }
img { max-width: 100%; }
[hidden]:not([hidden=until-found]) { display: none !important; }

:root {
  --bg: #eef1f0;
  --surface: #ffffff;
  --surface-2: #f4f6f5;
  --border: #d7dcda;
  --text: #1c2321;
  --text-dim: #5b6663;
  --accent: #1f5d5a;
  --accent-ink: #ffffff;
  --accent-soft: #dceae8;
  --ok-bg: #e1f2e6; --ok-fg: #2c7a4b; --ok-bd: #b6ddc2;
  --warn-bg: #fbeed9; --warn-fg: #a5680e; --warn-bd: #edcf9c;
  --crit-bg: #fbe3e0; --crit-fg: #b23a2f; --crit-bd: #f0bcb5;
  --none-bg: #e9ebea; --none-fg: #666f6c; --none-bd: #d2d7d5;
  --shadow: 0 1px 2px rgba(20,30,28,0.06), 0 6px 20px rgba(20,30,28,0.05);
  --radius: 10px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615;
    --surface: #191f1d;
    --surface-2: #202826;
    --border: #2c3634;
    --text: #e7ece9;
    --text-dim: #93a09c;
    --accent: #4fa39a;
    --accent-ink: #0b1413;
    --accent-soft: #1f3532;
    --ok-bg: #16301f; --ok-fg: #7bd39a; --ok-bd: #245234;
    --warn-bg: #3a2c11; --warn-fg: #e7b862; --warn-bd: #5c471c;
    --crit-bg: #3a1c18; --crit-fg: #f19a8f; --crit-bd: #602b23;
    --none-bg: #232b29; --none-fg: #98a3a0; --none-bd: #333d3a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #191f1d; --surface-2: #202826; --border: #2c3634;
  --text: #e7ece9; --text-dim: #93a09c; --accent: #4fa39a; --accent-ink: #0b1413; --accent-soft: #1f3532;
  --ok-bg: #16301f; --ok-fg: #7bd39a; --ok-bd: #245234;
  --warn-bg: #3a2c11; --warn-fg: #e7b862; --warn-bd: #5c471c;
  --crit-bg: #3a1c18; --crit-fg: #f19a8f; --crit-bd: #602b23;
  --none-bg: #232b29; --none-fg: #98a3a0; --none-bd: #333d3a;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --bg: #eef1f0; --surface: #ffffff; --surface-2: #f4f6f5; --border: #d7dcda;
  --text: #1c2321; --text-dim: #5b6663; --accent: #1f5d5a; --accent-ink: #ffffff; --accent-soft: #dceae8;
  --ok-bg: #e1f2e6; --ok-fg: #2c7a4b; --ok-bd: #b6ddc2;
  --warn-bg: #fbeed9; --warn-fg: #a5680e; --warn-bd: #edcf9c;
  --crit-bg: #fbe3e0; --crit-fg: #b23a2f; --crit-bd: #f0bcb5;
  --none-bg: #e9ebea; --none-fg: #666f6c; --none-bd: #d2d7d5;
  --shadow: 0 1px 2px rgba(20,30,28,0.06), 0 6px 20px rgba(20,30,28,0.05);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.45;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }
header.top {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; box-shadow: var(--shadow); margin-bottom: 20px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.badge-mark {
  width: 50px; height: 50px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none;
  font-family: var(--mono); letter-spacing: -0.02em;
}
header.top h1 { font-size: 20px; margin: 0 0 3px; letter-spacing: -0.01em; text-wrap: balance; }
header.top p { margin: 0; color: var(--text-dim); font-size: 13.5px; }

.main-nav { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.main-nav-btn {
  padding: 11px 20px; border: none; background: transparent; color: var(--text-dim); font-weight: 700;
  font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.main-nav-btn:hover { color: var(--text); }
.main-nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.main-nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.main-nav-right .whoami { font-size: 12.5px; color: var(--text-dim); }
.gewerk-chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}

.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 9px 18px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all .15s ease;
}
.tab:hover { border-color: var(--accent); color: var(--text); }
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.stats { display: grid; grid-template-columns: repeat(5,1fr); gap: 12px; margin-bottom: 18px; }
.stat.follow { border-left-color: var(--accent); } .stat.follow .n { color: var(--accent); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.types-table td a { text-decoration: none; color: var(--accent); }
a.type-open, a.bericht-link { color: inherit; text-decoration: none; cursor: pointer; }
a.type-open:hover, a.bericht-link:hover { color: var(--accent); text-decoration: underline; }
a.bericht-link { color: var(--accent); font-size: 12.5px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); padding: 11px 18px; border-radius: 9px; z-index: 60; box-shadow: var(--shadow); font-weight: 600; font-size: 13.5px; max-width: min(92vw, 640px); }
.overlay { position: fixed; inset: 0; background: rgba(10,16,15,0.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card-modal { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 20px 22px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.card-quick a { text-decoration: none; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-soft); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
a.contact-name { color: var(--text); text-decoration: underline dotted; cursor: pointer; }
a.contact-name:hover { color: var(--accent); }
.hist-count { font-size: 11.5px; color: var(--text-dim); font-weight: 500; margin-top: 2px; }
tr.hist-row td { background: var(--surface-2); padding: 14px 16px 18px; }
.hist-table { min-width: 0; width: 100%; }
.hist-table th { background: transparent; font-size: 11px; padding: 6px 10px; }
.hist-table td { padding: 8px 10px; font-size: 13px; border-bottom: 1px solid var(--border); }
.hist-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); font-weight: 700; margin-bottom: 8px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border-left: 4px solid transparent;
}
.stat .n { font-family: var(--mono); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin-top: 2px; }
.stat.ok { border-left-color: var(--ok-fg); } .stat.ok .n { color: var(--ok-fg); }
.stat.warn { border-left-color: var(--warn-fg); } .stat.warn .n { color: var(--warn-fg); }
.stat.crit { border-left-color: var(--crit-fg); } .stat.crit .n { color: var(--crit-fg); }
.stat.none { border-left-color: var(--none-fg); } .stat.none .n { color: var(--none-fg); }
.stat[data-filter] { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.stat[data-filter]:hover { transform: translateY(-2px); }
.stat.active { outline: 2px solid var(--accent); outline-offset: 1px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
select, input, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
button {
  font-family: inherit; font-size: 13.5px; font-weight: 600; border-radius: 8px; padding: 9px 16px;
  border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-icon { padding: 6px 8px; background: transparent; border: 1px solid transparent; color: var(--text-dim); }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.danger:hover { color: var(--crit-fg); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; border-top: 3px solid var(--accent);
}
.panel h2 { margin: 0 0 14px; font-size: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
select, input, textarea { width: 100%; }
.form-actions { grid-column: 1/-1; display: flex; gap: 10px; margin-top: 4px; }
.form-actions button { flex: 1; justify-content: center; }

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
thead th {
  background: var(--surface-2); color: var(--text-dim); text-align: left; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em; padding: 12px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sortable .arrow { display: inline-block; margin-left: 4px; opacity: .4; font-size: 10px; }
thead th.sortable.active .arrow { opacity: 1; color: var(--accent); }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13.5px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.type-cell { font-weight: 600; }
.date-cell { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text-dim); }
.due-days { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; font-family: var(--mono); }
.chip { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.chip.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.chip.crit { background: var(--crit-bg); color: var(--crit-fg); border-color: var(--crit-bd); }
.chip.none { background: var(--none-bg); color: var(--none-fg); border-color: var(--none-bd); }
.notes-cell { color: var(--text-dim); width: 170px; max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.notes-cell.open { white-space: normal; overflow: visible; max-width: 340px; width: auto; color: var(--text); cursor: zoom-out; }
table.main-table { min-width: 0; }
#tbody td, #ovTbody td { padding: 10px 8px; }
#ovTbody .notes-cell { width: 140px; max-width: 140px; }
#ovTbody .notes-cell.open { width: auto; max-width: 300px; }
#ovTbody .date-cell { white-space: nowrap; }
table.main-table thead th { padding: 12px 8px; font-size: 11px; letter-spacing: .03em; }
#tbody .notes-cell { width: 140px; max-width: 140px; }
#tbody .notes-cell.open { width: auto; max-width: 300px; }
#tbody .btn-icon { padding: 5px 5px; }
#tbody .contact-links { margin-left: 3px; }
#tbody .date-cell { white-space: nowrap; }
#tbody .btn-sm { padding: 5px 10px; }
.empty-row td { text-align: center; color: var(--text-dim); padding: 40px; }

.types-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.types-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.types-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.types-table input[type="text"] { width: 100%; }
.types-table input[type="number"] { width: 90px; }
.interval-hint { font-size: 11px; color: var(--text-dim); margin-left: 6px; white-space: nowrap; }
.types-add-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 10px; align-items: end; margin-top: 6px; }
.types-add-row label { margin-bottom: 4px; }
.types-table input[placeholder="Ansprechpartner"], .types-table input[placeholder="Telefon"],
.types-table input[placeholder="E-Mail"], .types-table input[placeholder="Adresse"] { width: 100%; }
.contact-name { font-weight: 600; }
.contact-links { display: inline-flex; gap: 6px; margin-left: 6px; }
.contact-links a {
  color: var(--accent); text-decoration: none; font-size: 12px; border: 1px solid var(--accent-soft);
  border-radius: 6px; padding: 1px 6px; background: var(--accent-soft);
}
.contact-links a:hover { filter: brightness(0.95); }
.contact-name[title]:hover { text-decoration: underline dotted; cursor: help; }

.legend { margin-top: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.legend h3 { margin: 0 0 12px; font-size: 13.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.legend-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; font-size: 13px; }
.legend-grid .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 26px; }
.login-card h1 { font-size: 18px; margin: 14px 0 4px; }
.login-card p.sub { margin: 0 0 20px; color: var(--text-dim); font-size: 13.5px; }
.login-card .field { margin-bottom: 14px; }
.login-error { background: var(--crit-bg); color: var(--crit-fg); border: 1px solid var(--crit-bd); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.login-badge { display: flex; align-items: center; gap: 12px; }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2,1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .legend-grid { grid-template-columns: repeat(2,1fr); }
}
