/* S&H Ausschreibungsradar — Apple HIG (siehe Skill sh-apple-design) */
:root {
  --text: #1d1d1f; --text-2: #6e6e73; --text-3: #aeaeb2;
  --accent: #007aff; --accent-hover: #0071e3;
  --red: #d70015; --green: #248a3d; --orange: #c93400;
  --bg: #ffffff; --bg-page: #f5f5f7; --fill: #f2f2f7;
  --line: #e5e5ea; --line-strong: #d1d1d6; --tint: #eaf3ff;
  --ok-bg: #eaf7ee; --warn-bg: #fff3e8; --err-bg: #ffebeb;
  --r-ctrl: 6px; --r-card: 12px;
  --sidebar: 232px;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg-page); color: var(--text); font-size: 16px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
input, select, textarea { font: inherit; color: var(--text); }
::selection { background: var(--tint); }

/* Typo-Rollen */
.h-large { font-size: 32px; font-weight: 700; letter-spacing: -0.4px; margin: 0; }
.h-title1 { font-size: 26px; font-weight: 700; margin: 0; }
.h-title2 { font-size: 20px; font-weight: 600; margin: 0; }
.headline { font-size: 16px; font-weight: 600; }
.callout { font-size: 15px; }
.sub { font-size: 13px; font-weight: 600; color: var(--text-2); }
.foot { font-size: 12px; color: var(--text-2); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--bg); border-right: 1px solid var(--line); padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { padding: 4px 12px 16px; }
.brand .name { font-size: 17px; font-weight: 700; }
.brand .foot { margin-top: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-size: 15px; }
.nav a:hover { background: var(--fill); }
.nav a.active { background: var(--tint); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--text-2); background: var(--fill); border-radius: 999px; padding: 1px 8px; }
.nav a.active .count { background: var(--bg); color: var(--accent); }
.sidebar .spacer { flex: 1; }
.sidebar .status { padding: 12px; font-size: 12px; color: var(--text-2); border-top: 1px solid var(--line); }
.main { padding: 28px 32px 48px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head .lead { color: var(--text-2); margin: 4px 0 0; font-size: 15px; }

/* Buttons */
.btn { border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); border-radius: var(--r-ctrl); padding: 8px 14px; cursor: pointer; font-size: 15px; line-height: 1.2; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--fill); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--fill); }

/* Chips / Pills */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--fill); }
.chip.on { background: var(--tint); border-color: var(--tint); color: var(--accent); font-weight: 600; }
.chip .n { font-size: 12px; color: var(--text-2); }
.chip.on .n { color: var(--accent); opacity: .8; }
.chip.add { border-style: dashed; color: var(--text-2); }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: var(--fill); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--green); }
.pill.warn { background: var(--warn-bg); color: var(--orange); }
.pill.err { background: var(--err-bg); color: var(--red); }
.pill.accent { background: var(--tint); color: var(--accent); }
.pill.new { background: var(--accent); color: #fff; }

/* Filterleiste */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 0 0 16px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input, select.input { border: 1px solid var(--line-strong); border-radius: var(--r-ctrl); padding: 8px 10px; background: var(--bg); font-size: 15px; width: 100%; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--tint); }
.search { position: relative; }
.search .input { padding-left: 32px; }
.search::before { content: "⌕"; position: absolute; left: 10px; top: 7px; color: var(--text-3); font-size: 18px; }
.segmented { display: inline-flex; background: var(--fill); border-radius: 8px; padding: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.segmented button.on { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.switch input { display: none; }
.switch .knob { width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .15s; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s; }
.switch input:checked + .knob { background: var(--green); }
.switch input:checked + .knob::after { left: 18px; }

/* Karten / Liste */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; }
.card + .card { margin-top: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px 16px; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; cursor: pointer; transition: border-color .1s; }
.row:hover { border-color: var(--line-strong); }
.row.expired { opacity: .55; }
.row .title { font-size: 16px; font-weight: 600; }
.row .meta { font-size: 13px; color: var(--text-2); display: flex; gap: 8px; flex-wrap: wrap; }
.row .meta .sep::before { content: "·"; color: var(--text-3); }
.row .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.row .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.row .deadline { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.row .deadline.soon { color: var(--orange); font-weight: 600; }
.row .deadline.urgent { color: var(--red); font-weight: 600; }
.score { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--accent); background: var(--tint); border-radius: 999px; padding: 2px 10px; }
.star { border: 0; background: transparent; font-size: 20px; color: var(--text-3); cursor: pointer; padding: 0 4px; line-height: 1; }
.star.on { color: #f5a623; }
.empty { padding: 40px; text-align: center; color: var(--text-2); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--text-2); font-weight: 600; }

/* Detail-Panel */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.18); display: none; z-index: 20; }
.overlay.open { display: block; }
.panel { position: fixed; top: 0; right: 0; height: 100vh; width: min(620px, 100vw); background: var(--bg); box-shadow: -8px 0 32px rgba(0,0,0,.12); transform: translateX(100%); transition: transform .2s ease; z-index: 21; overflow-y: auto; padding: 24px 28px 40px; }
.panel.open { transform: translateX(0); }
.panel .close { position: absolute; top: 14px; right: 16px; }
.panel h2 { font-size: 20px; font-weight: 600; margin: 0 40px 6px 0; line-height: 1.3; }
.panel .actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.panel section { margin-top: 20px; }
.panel section h3 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 8px; text-transform: none; }
.panel .text { white-space: pre-wrap; font-size: 15px; line-height: 1.5; }
.reasons li { font-size: 14px; }
.doc a { display: block; font-size: 14px; word-break: break-all; padding: 4px 0; }

/* Modal (Sheet) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: none; align-items: center; justify-content: center; z-index: 30; padding: 20px; }
.modal.open { display: flex; }
.sheet { background: var(--bg); border-radius: 14px; width: min(720px, 100%); max-height: 92vh; overflow-y: auto; padding: 24px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.sheet h2 { margin: 0 0 16px; font-size: 20px; font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form .hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.chipeditor { border: 1px solid var(--line-strong); border-radius: var(--r-ctrl); padding: 6px 8px; display: flex; flex-wrap: wrap; gap: 6px; background: var(--bg); }
.chipeditor input { border: 0; outline: none; flex: 1; min-width: 140px; padding: 4px; font-size: 15px; }
.chipeditor .chip { padding: 3px 10px; font-size: 14px; }
.chipeditor .chip .x { color: var(--text-3); cursor: pointer; font-size: 13px; }
.chipeditor .chip .x:hover { color: var(--red); }
.sheet .foot-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.sheet .foot-actions .left { margin-right: auto; }
.range { display: flex; align-items: center; gap: 12px; }
.range input[type=range] { flex: 1; accent-color: var(--accent); }

/* Suchpattern-Karten */
.pcard { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.pcard .terms { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--text-2); margin-top: 6px; }
.pcard .terms b { color: var(--text); font-weight: 600; }
.pcard .terms .ex b { color: var(--red); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; z-index: 40; pointer-events: none; }
.toast.show { opacity: 1; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 36px 36px 28px; width: min(380px, 100%); box-shadow: 0 12px 40px rgba(0,0,0,.06); text-align: center; }
.login .logo { width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 800; font-size: 22px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; letter-spacing: -.5px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.login p { color: var(--text-2); margin: 0 0 22px; font-size: 14px; }
.login .input { text-align: center; font-size: 17px; padding: 11px; }
.login .btn { width: 100%; justify-content: center; margin-top: 12px; padding: 11px; font-size: 16px; }
.login .err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Log-Box */
.log { background: var(--fill); border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-2); white-space: pre-wrap; max-height: 220px; overflow-y: auto; }
code.k { background: var(--fill); border-radius: 4px; padding: 1px 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }

/* Tab-Leiste und Ansichts-Umschalter (nur mobil sichtbar) */
.tabbar { display: none; }
.mobile-only { display: none !important; }
body.no-scroll { overflow: hidden; }

/* ── Mobil (iPhone & kleine Geräte) ──────────────────────────────── */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  /* minmax(0,1fr) + min-width:0: sonst dehnt eine nicht umbrechende Zeile
     (Pattern-Chips) das ganze Layout auf ihre Inhaltsbreite und iOS zoomt
     die Seite heraus (Layout-Viewport 900px statt 390px). */
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: calc(12px + env(safe-area-inset-top)) 14px 24px; max-width: none; min-width: 0; width: 100%; }
  .row, .card, .toolbar, .list { min-width: 0; }
  .row .title, .row .meta, .panel h2, .panel .text { overflow-wrap: anywhere; }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 14px; }
  .page-head .lead { font-size: 14px; }
  .page-head > div:last-child { display: flex; }
  .page-head > div:last-child .btn { flex: 1; justify-content: center; min-height: 44px; }
  .h-large { font-size: 28px; }
  .h-title2 { font-size: 18px; }

  /* Touch-Ziele */
  .btn { min-height: 44px; padding: 10px 14px; font-size: 16px; }
  .btn.small { min-height: 38px; font-size: 14px; }
  .btn.icon { min-height: 40px; }
  .input, select.input { font-size: 16px; padding: 11px 12px; } /* 16px verhindert Auto-Zoom in iOS */
  .chip { min-height: 38px; font-size: 15px; padding: 7px 14px; white-space: nowrap; }
  .star { font-size: 26px; padding: 4px 6px; }

  .mobile-only { display: inline-flex !important; }
  .view-switch { display: flex !important; width: 100%; margin: 0 0 12px; }
  .view-switch button { flex: 1; min-height: 38px; font-size: 14px; }

  /* Pattern-Buttons als horizontal wischbare Zeile */
  .toolbar { gap: 10px; margin-bottom: 12px; }
  .toolbar .chips { flex: 0 0 100vw; width: 100vw; max-width: 100vw; min-width: 0; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 -14px; padding: 2px 14px; box-sizing: border-box; }
  .toolbar .chips::-webkit-scrollbar { display: none; }
  .toolbar .grow { flex-basis: 100%; }
  .toolbar select.input { flex: 1; min-width: 0; width: auto; }
  .segmented { flex: 0 0 auto; }
  .segmented button { min-height: 36px; padding: 6px 12px; font-size: 14px; }
  .switch { flex-basis: 100%; }
  .switch .knob { width: 46px; height: 28px; }
  .switch .knob::after { width: 24px; height: 24px; }
  .switch input:checked + .knob::after { left: 20px; }

  /* Listenzeilen */
  .row { grid-template-columns: 1fr; gap: 8px; padding: 14px 14px; border-radius: 14px; }
  .row .title { font-size: 16px; line-height: 1.3; }
  .row .meta { font-size: 13px; }
  .row .right { flex-direction: row; align-items: center; justify-content: space-between; text-align: left; }
  .row .deadline { white-space: normal; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid2 { grid-template-columns: 1fr; }
  .pcard { grid-template-columns: 1fr; }
  .pcard > div:last-child { display: flex; gap: 8px; }
  .pcard > div:last-child .btn { flex: 1; justify-content: center; }
  .pcard .terms { font-size: 15px; }
  .kv { grid-template-columns: 110px 1fr; font-size: 14px; }
  .card { padding: 14px; }

  /* Detail als Vollbild-Sheet von rechts */
  .panel { width: 100vw; padding: calc(18px + env(safe-area-inset-top)) 18px calc(30px + env(safe-area-inset-bottom)); }
  .panel .close { top: calc(10px + env(safe-area-inset-top)); right: 12px; min-height: 40px; min-width: 40px; font-size: 18px; }
  .panel h2 { font-size: 20px; margin-right: 48px; }
  .panel .actions .btn { flex: 1 1 45%; justify-content: center; }
  .panel .actions .btn.small { flex-basis: 100%; }

  /* Formulare als Bottom-Sheet */
  .modal { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0; padding: 18px 18px calc(20px + env(safe-area-inset-bottom)); }
  .sheet .foot-actions { flex-wrap: wrap; }
  .sheet .foot-actions .btn { flex: 1; justify-content: center; }
  .sheet .foot-actions .left { flex-basis: 100%; margin-right: 0; order: 3; }
  .chipeditor { padding: 8px; }
  .chipeditor input { font-size: 16px; min-width: 120px; }

  /* Tab-Leiste unten, iOS-typisch */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: rgba(255,255,255,.92); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-2); font-size: 10.5px; font-weight: 500; padding: 4px 0; position: relative; min-height: 48px; justify-content: center; }
  .tabbar a svg { width: 26px; height: 26px; fill: currentColor; }
  .tabbar a.active { color: var(--accent); }
  .tabbar .badge { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--red); color: #fff; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 5px; min-width: 16px; text-align: center; line-height: 14px; }
  .tabbar .badge:empty { display: none; }

  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); text-align: center; }
  .log { font-size: 11px; max-height: 160px; }
  .login { padding: 28px 22px 22px; }
}

/* Sehr kleine Geräte (iPhone SE) */
@media (max-width: 380px) {
  .h-large { font-size: 25px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 6px; }
}
