:root {
    --bg: #eceff2;
    --surface: #ffffff;
    --surface-2: #f5f6f8;
    --ink: #111821;
    --muted: #5a6573;
    --line: #d6dbe2;
    --accent: #0a6e8a;
    --c-accent: var(--accent);
    --c-red: #c2361f;
    --c-green: #2d6e5f;
    --c-violet: #5b48b0;
    --c-ochre: #8a6a12;
    --c-berry: #8c3a4f;
    --c-teal: #16798d;
    --c-blue: #2f55b0;
    --c-magenta: #b0306a;
    --ok: #2f7d4f;
    --warn: #b7791f;
    --crit: #c2361f;
    --f-display: "Archivo", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
    --f-body: "Newsreader", Georgia, "Times New Roman", serif;
    --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1218; --surface: #151c24; --surface-2: #1b2430; --ink: #e7ecf1; --muted: #98a4b1; --line: #29333f;
        --accent: #4cc0d9; --c-red: #f07d68; --c-green: #6cc3ad; --c-violet: #b2a1f2; --c-ochre: #dcc06a; --c-berry: #e58fa4;
        --c-teal: #63c9db; --c-blue: #8eaaf2; --c-magenta: #ef8cb8; --ok: #6fcf97; --warn: #e8b85a; --crit: #f07d68;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0d1218; --surface: #151c24; --surface-2: #1b2430; --ink: #e7ecf1; --muted: #98a4b1; --line: #29333f;
    --accent: #4cc0d9; --c-red: #f07d68; --c-green: #6cc3ad; --c-violet: #b2a1f2; --c-ochre: #dcc06a; --c-berry: #e58fa4;
    --c-teal: #63c9db; --c-blue: #8eaaf2; --c-magenta: #ef8cb8; --ok: #6fcf97; --warn: #e8b85a; --crit: #f07d68;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--f-body);
    font-size: 17px;
    line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Masthead */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px 0; display: grid; gap: 8px; }
.brand-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { margin: 0; font-family: var(--f-display); font-stretch: 78%; font-weight: 800; font-size: 26px; letter-spacing: -.01em; line-height: 1; }
.brand span { color: var(--accent); }
.stamp { flex: 1 1 260px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stamp b { color: var(--ink); font-weight: 500; }

.pill-btn {
    font-family: var(--f-mono);
    font-size: 12px;
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
}
.pill-btn:hover { border-color: var(--accent); }
.pill-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.pill-btn:disabled { opacity: .6; cursor: progress; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chips a {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
}
.chips a i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--sc); }
.chips a:hover { border-color: var(--sc); }

main { max-width: 1180px; margin: 0 auto; padding: 22px 16px 60px; }

.page-foot { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }

/* Mauerwerk-Raster: 12 Spalten und 4-px-Zeilen. app.js setzt je Kachel Spalten- und Zeilen-Span,
   dadurch stapeln sich kleine Kacheln neben einer großen, statt auf deren Höhe zu warten. */
.boxes {
    --cols: 12;
    --row: 4px;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: var(--row);
    grid-auto-flow: row dense;
    column-gap: 16px;
    align-items: start;
}
.boxes > .box { margin-bottom: 16px; }

@media (max-width: 1100px) { .boxes { --cols: 6; } }
@media (max-width: 700px) { .boxes { --cols: 2; } }
@media (max-width: 480px) { .boxes { --cols: 1; } }

.box {
    display: grid;
    gap: 8px;
    min-width: 0;
    padding: 14px 16px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 4px solid var(--sc);
    border-radius: var(--radius);
    scroll-margin-top: 120px;
    transition: opacity .2s, box-shadow .2s;
}
.box { position: relative; }
.box.has-height { grid-template-rows: auto minmax(0, 1fr); }
.box.has-height .box-body { overflow: auto; }
.box.is-dragging { opacity: .4; }
.box.is-drop-target { box-shadow: 0 0 0 2px var(--sc); }

.box-head { display: flex; align-items: baseline; gap: 8px; }
.box-head h2 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-family: var(--f-display);
    font-stretch: 78%;
    font-weight: 800;
    font-size: 22px;
    line-height: 1.05;
    letter-spacing: -.01em;
    color: var(--sc);
    text-wrap: balance;
}

.tile-actions { display: flex; gap: 2px; opacity: .45; transition: opacity .15s; align-self: center; }
.box:hover .tile-actions, .box:focus-within .tile-actions { opacity: 1; }
.edit-only { display: none !important; }

/* Bearbeiten-Modus */
.edit-hint { margin: 0 0 14px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.is-editing .edit-only { display: inline-grid !important; }
.is-editing .box { outline: 1px dashed var(--sc); outline-offset: 3px; }
.is-editing .box-head { cursor: grab; }
.is-editing .tile-actions { opacity: 1; }
.is-editing .box-body { pointer-events: none; user-select: none; }
.pill-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }

.resize-handle {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 0 0 var(--radius) 0;
    background: linear-gradient(135deg, transparent 50%, var(--sc) 50%);
    cursor: nwse-resize;
    touch-action: none;
}
.is-resizing { cursor: nwse-resize; user-select: none; }
.is-resizing .box { transition: none; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--ink); }
.icon-button svg { width: 15px; height: 15px; }

.box.is-loading [data-action="refresh"] svg { animation: spin 1s linear infinite; }
.box.is-loading .box-body { opacity: .5; }
@keyframes spin { to { transform: rotate(360deg); } }

.box-body { min-width: 0; overflow-x: auto; }

.box-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 12px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.tile-error {
    margin: 0;
    padding: 8px 10px;
    border-radius: 6px;
    box-shadow: inset 3px 0 0 var(--crit);
    background: var(--surface-2);
    font-family: var(--f-mono);
    font-size: 12px;
    color: var(--crit);
}

.tile-note { margin: 0; font-family: var(--f-mono); font-size: 11px; color: var(--muted); }

.placeholder { margin: 0; color: var(--muted); font-style: italic; font-size: 16px; }

/* Kicker & Tags (wie im Briefing) */
.kick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); }
.tag {
    padding: 2px 6px;
    border: 1px solid var(--tc, var(--sc));
    border-radius: 4px;
    color: var(--tc, var(--sc));
    font-family: var(--f-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: .07em;
    text-transform: uppercase;
}
.more { margin-left: auto; padding: 2px 0; border: 0; background: none; font-family: var(--f-mono); font-size: 11px; color: var(--accent); cursor: pointer; }
.more:hover { text-decoration: underline; }

/* Generierte Vorschaubilder & externe Bilder */
.thumb { position: relative; display: block; overflow: hidden; background: var(--surface-2); border-radius: 6px; }
.thumb canvas, .thumb img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb .glyph {
    position: absolute;
    left: 10px;
    bottom: 8px;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--sc);
    color: var(--surface);
    font-family: var(--f-display);
    font-stretch: 75%;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

/* Renderer: Aufmacher */
.lead { display: grid; gap: 10px; min-width: 0; }
.lead .thumb { aspect-ratio: 21 / 9; margin: 0 -16px; border-radius: 0; }
.lead h3 {
    margin: 0;
    font-family: var(--f-display);
    font-stretch: 80%;
    font-weight: 800;
    font-size: clamp(26px, 3.4vw, 40px);
    line-height: 1.04;
    letter-spacing: -.015em;
    text-wrap: balance;
}
.lead h3 a { text-decoration: none; }
.lead h3 a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.lead p { margin: 0; font-size: 18px; max-width: 62ch; }
@media (max-width: 560px) { .lead .thumb { aspect-ratio: 16 / 9; } }

/* Renderer: Nachrichtenliste */
.news { list-style: none; margin: 0; padding: 0; display: grid; }
.news li { display: grid; gap: 4px; min-width: 0; padding: 10px 0; border-top: 1px solid var(--line); }
.news li:first-child { border-top: 0; padding-top: 0; }
.news li[style*="--sev"] { padding-left: 10px; box-shadow: inset 3px 0 0 var(--sev); }
.news li.has-thumb { grid-template-columns: minmax(0, 1fr) 72px; column-gap: 12px; }
.news li.has-thumb > :not(.thumb) { grid-column: 1; }
.news li.has-thumb > .thumb { grid-column: 2; grid-row: 1 / span 3; width: 72px; height: 54px; }
.news .headline { font-family: var(--f-display); font-stretch: 88%; font-weight: 600; font-size: 16.5px; line-height: 1.25; text-decoration: none; }
.news a.headline:hover { text-decoration: underline; text-decoration-color: var(--sc); text-underline-offset: 3px; }
.news a.headline:visited { color: var(--muted); }
.news .sum { margin: 2px 0 0; font-size: 15.5px; }

/* Renderer: Markdown */
.markdown { font-size: 16px; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
    margin: 14px 0 4px;
    font-family: var(--f-display);
    font-stretch: 85%;
    font-weight: 700;
    font-size: 18px;
    line-height: 1.2;
}
.markdown ul, .markdown ol { padding-left: 20px; }
.markdown li + li { margin-top: 4px; }
.markdown strong { font-weight: 600; }
.markdown code { font-family: var(--f-mono); font-size: 13px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.markdown pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow: auto; }
.markdown a { text-decoration-color: var(--sc); text-underline-offset: 3px; }

/* Renderer: Tabelle */
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table th, .data-table td { padding: 7px 8px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
.data-table th {
    border-top: 0;
    border-bottom: 2px solid var(--sc);
    font-family: var(--f-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}
.data-table tbody tr:first-child td { border-top: 0; }
.data-table td:first-child { font-family: var(--f-display); font-stretch: 88%; font-weight: 600; }

/* Renderer: Metrik (wie das Lage-Panel) */
.metric { display: grid; gap: 10px; padding: 4px 0 6px; }
.metric-label { margin: 0; font-family: var(--f-mono); font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.level { display: flex; align-items: center; gap: 14px; }
.level-dot { position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--lv); }
.level-dot::after { content: ""; position: absolute; inset: -6px; border: 2px solid var(--lv); border-radius: 50%; opacity: .35; }
.metric-value {
    font-family: var(--f-display);
    font-stretch: 78%;
    font-weight: 800;
    font-size: 46px;
    line-height: 1;
    letter-spacing: -.01em;
    font-variant-numeric: tabular-nums;
    color: var(--lv);
}
.metric-unit { margin-left: 4px; font-size: 22px; font-weight: 600; color: var(--muted); }
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.count { padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); font-family: var(--f-mono); font-size: 12px; }
.metric-note { margin: 0; font-size: 16px; }

/* Renderer: Key-Value (wie die Fristen-Liste) */
.key-value { list-style: none; margin: 0; padding: 0; display: grid; }
.key-value li { display: grid; grid-template-columns: minmax(80px, 38%) minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); }
.key-value li:first-child { border-top: 0; padding-top: 0; }
.key-value .key { font-family: var(--f-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); overflow-wrap: anywhere; }
.key-value .value { font-family: var(--f-display); font-stretch: 88%; font-weight: 600; font-size: 16.5px; line-height: 1.25; overflow-wrap: anywhere; }

/* Quellenliste unter Text-, Tabellen- und Zahlenkacheln */
.sources { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); font-family: var(--f-mono); font-size: 11px; }
.sources-label { color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.sources a { color: var(--accent); text-decoration: none; }
.sources a:hover { text-decoration: underline; }

/* Renderer: Wetter */
.weather { display: grid; gap: 12px; }
.weather-now { display: flex; align-items: center; gap: 14px; }
.weather-symbol { font-size: 38px; line-height: 1; color: var(--sc); }
.weather .metric-value { color: var(--ink); }
.weather-condition { display: grid; line-height: 1.25; }
.weather-condition strong { font-family: var(--f-display); font-stretch: 85%; font-weight: 700; font-size: 18px; }
.weather-condition span { font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.weather-hours { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; padding-top: 4px; border-top: 1px solid var(--line); }
.weather-hour { display: grid; justify-items: center; gap: 3px; font-family: var(--f-mono); font-size: 10.5px; color: var(--muted); }
.weather-hour-temp { color: var(--ink); font-size: 11px; }
.weather-rain { position: relative; width: 100%; max-width: 14px; height: 32px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.weather-rain::after { content: ""; position: absolute; inset: auto 0 0; height: var(--p); background: color-mix(in srgb, var(--c-blue) 70%, transparent); }
.weather-days { list-style: none; margin: 0; padding: 0; display: grid; }
.weather-days li { display: grid; grid-template-columns: 44px 22px 30px minmax(40px, 1fr) 30px 54px; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid var(--line); font-family: var(--f-mono); font-size: 12px; }
.weather-day { font-family: var(--f-display); font-weight: 600; font-size: 14px; }
.weather-day-symbol { color: var(--sc); text-align: center; }
.weather-temp { text-align: right; font-variant-numeric: tabular-nums; }
.weather-temp + .weather-range + .weather-temp { text-align: left; }
.weather-range { position: relative; height: 6px; border-radius: 3px; background: var(--surface-2); }
.weather-range::after { content: ""; position: absolute; top: 0; bottom: 0; left: var(--from); right: calc(100% - var(--to)); border-radius: 3px; background: linear-gradient(90deg, var(--c-teal), var(--c-ochre)); }
.weather-day-rain { color: var(--c-blue); text-align: right; }

/* Renderer: Mein Tag */
.digest { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 8px 28px; align-items: start; }
.digest-summary { font-size: 18px; line-height: 1.55; }
.digest-highlights { list-style: none; margin: 0; padding: 0; display: grid; }
.digest-highlights li { display: grid; gap: 4px; padding: 9px 0; border-top: 1px solid var(--line); }
.digest-highlights li:first-child { border-top: 0; padding-top: 0; }
.digest-highlights li[style*="--sev"] { padding-left: 10px; box-shadow: inset 3px 0 0 var(--sev); }
.digest-highlights .headline { font-family: var(--f-display); font-stretch: 88%; font-weight: 600; font-size: 16px; line-height: 1.3; }
.digest-highlights .more { text-decoration: none; }
@media (max-width: 820px) { .digest { grid-template-columns: minmax(0, 1fr); } }

.field-hint { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }
.field select:disabled { opacity: .5; }
.check input:disabled + span { opacity: .5; }

/* Leerer Zustand */
.empty { display: grid; gap: 10px; justify-items: start; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.empty h2 { margin: 0; font-family: var(--f-display); font-stretch: 80%; font-weight: 800; font-size: 26px; }
.empty p { margin: 0; }

/* Dialog */
.dialog {
    width: min(560px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 20px 50px rgb(0 0 0 / .25);
}
.dialog::backdrop { background: rgb(10 14 20 / .5); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; }
.dialog-header h2 { margin: 0; font-family: var(--f-display); font-stretch: 80%; font-weight: 800; font-size: 24px; }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--line); }
.dialog-body { display: grid; gap: 14px; padding: 0 18px 18px; }

.field { display: grid; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > span, .field > legend {
    padding: 0;
    margin-bottom: 5px;
    font-family: var(--f-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
}
.field input, .field textarea, .field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-2);
    font-size: 16px;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }
.field-error { font-family: var(--f-mono); font-size: 12px; color: var(--crit); }
.field-error:empty { display: none; }
.form-error { margin: 0; font-family: var(--f-mono); font-size: 12px; color: var(--crit); }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.35; cursor: pointer; }
.check input { flex: none; width: 16px; height: 16px; margin-top: 3px; accent-color: var(--accent); }
.check b { font-family: var(--f-display); font-weight: 700; }
.check + .check { margin-top: 6px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.swatch span::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--sc); }
.swatch input:checked + span { border-color: var(--sc); box-shadow: 0 0 0 1px var(--sc); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Toasts */
.toast-container { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; }
.toast {
    max-width: 360px;
    padding: 10px 14px;
    border-radius: 6px;
    background: var(--ink);
    color: var(--surface);
    font-family: var(--f-mono);
    font-size: 12.5px;
    animation: toast-in .2s ease-out;
}
.toast--error { background: var(--crit); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 480px) {
    .brand { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: min(360px, 100%);
    display: grid;
    gap: 14px;
    padding: 24px 22px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
}
.login-card .brand { margin-bottom: 4px; }
.login-card input { font-size: 16px; }
.login-card .pill-btn { justify-self: start; padding: 8px 18px; font-size: 13px; }
