:root {
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --text: #0b0b0b;
    --text-secondary: #52514e;
    --muted: #6f6d68;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --series: #2a78d6;
    --series-hover: #1c5cab;
    --link: #1c5cab;
    --error: #b42626;
    --error-surface: #fbeaea;
}

@media (prefers-color-scheme: dark) {
    :root {
        --page: #0d0d0d;
        --surface: #1a1a19;
        --text: #f0efec;
        --text-secondary: #c3c2b7;
        --muted: #9a988f;
        --grid: #2c2c2a;
        --axis: #383835;
        --series: #3987e5;
        --series-hover: #6da7ec;
        --link: #86b6ef;
        --error: #e66767;
        --error-surface: #2c1717;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--page);
    color: var(--text);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0 0 0.9rem; }
h2 .muted { font-weight: 400; }
h1:focus { outline: none; }
code { font-size: 0.9em; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.status-error { color: var(--error); }

/* Grundgerüst */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    flex: 0 0 190px;
    padding: 1.2rem 0.8rem;
    border-right: 1px solid var(--grid);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 0.6rem 1rem; }
.sidebar a { padding: 0.45rem 0.6rem; border-radius: 6px; color: var(--text-secondary); }
.sidebar a:hover { background: var(--page); text-decoration: none; }
.sidebar a.active { background: var(--page); color: var(--text); font-weight: 600; }
.content { flex: 1; min-width: 0; padding: 1.6rem 2rem 3rem; max-width: 1200px; }

@media (max-width: 720px) {
    .shell { flex-direction: column; }
    .sidebar { flex: none; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--grid); padding: 0.6rem; }
    .brand { padding: 0 0.6rem 0 0.2rem; }
    .content { padding: 1rem; }
}

.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem; margin-bottom: 1.2rem; }
.pagehead-actions { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }

button, .button {
    font: inherit;
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--axis);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--text-secondary); text-decoration: none; }
button.primary { background: var(--series); border-color: var(--series); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--series-hover); border-color: var(--series-hover); }
button:disabled { opacity: 0.55; cursor: default; }

input[type="search"] {
    font: inherit;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--axis);
    background: var(--surface);
    color: var(--text);
    width: min(22rem, 60vw);
}
.search { display: flex; gap: 0.5rem; }

.notice { padding: 0.7rem 0.9rem; border-radius: 8px; border: 1px solid var(--grid); background: var(--surface); margin-bottom: 1.2rem; overflow-wrap: anywhere; }
.notice-error { border-color: var(--error); background: var(--error-surface); }

.card { background: var(--surface); border: 1px solid var(--grid); border-radius: 10px; padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; min-width: 0; }
.grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.2rem; }
.grid .card { margin-bottom: 0; }
.grid { margin-bottom: 1.2rem; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* Kennzahlen */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1.2rem; margin-bottom: 1.2rem; }
.tile { background: var(--surface); border: 1px solid var(--grid); border-radius: 10px; padding: 0.9rem 1.2rem; display: flex; flex-direction: column; }
.tile-label { color: var(--text-secondary); font-size: 0.9rem; }
.tile-value { font-size: 2rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }

/* Tabellen */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--axis); }
th.num { text-align: right; }
td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--grid); vertical-align: top; overflow-wrap: anywhere; }
tr:last-child td { border-bottom: 0; }
.messages { table-layout: fixed; }
.messages th:nth-child(1) { width: 9.5rem; }
.messages th:nth-child(2) { width: 28%; }
.messages th:nth-child(4) { width: 3rem; }
.messages .sender, .messages .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
    .messages th:nth-child(2), .messages td:nth-child(2), .messages th:nth-child(4), .messages td:nth-child(4) { display: none; }
}

.pager { display: flex; align-items: center; justify-content: center; gap: 1.2rem; }
.pager a.disabled { visibility: hidden; }

/* Einzelansicht */
.meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.35rem 1rem; margin-top: 0; }
.meta dt { color: var(--text-secondary); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.mailbody { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; }

/* Säulendiagramm: Mails je Woche */
.weekchart {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    grid-template-rows: 180px auto auto;
    column-gap: 0.5rem;
}
.weekchart-axis { display: flex; flex-direction: column; justify-content: space-between; text-align: right; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; line-height: 1; margin: -0.4em 0; }
.weekchart-plot {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    border-bottom: 1px solid var(--axis);
    background: linear-gradient(var(--grid), var(--grid)) top / 100% 1px no-repeat,
                linear-gradient(var(--grid), var(--grid)) center / 100% 1px no-repeat;
}
.weekchart-col { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; outline: none; }
.weekchart-bar { width: 100%; max-width: 34px; background: var(--series); border-radius: 4px 4px 0 0; }
.weekchart-col:hover .weekchart-bar, .weekchart-col:focus-visible .weekchart-bar { background: var(--series-hover); }
.weekchart-tip {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--axis);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
    pointer-events: none;
}
.weekchart-tip span { display: block; color: var(--text-secondary); }
.weekchart-col:hover .weekchart-tip, .weekchart-col:focus-visible .weekchart-tip { display: block; bottom: auto; top: 0; }
.weekchart-col:first-child .weekchart-tip { left: 0; transform: none; }
.weekchart-col:last-child .weekchart-tip { left: auto; right: 0; transform: none; }
.weekchart-labels { grid-column: 2; display: flex; gap: 2px; padding-top: 0.3rem; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.weekchart-labels span { flex: 1; text-align: center; }
.weekchart-title { grid-column: 2; text-align: center; color: var(--muted); font-size: 0.8rem; }

.tableview { margin-top: 0.8rem; }
.tableview summary { cursor: pointer; color: var(--text-secondary); font-size: 0.9rem; }
.tableview table { margin-top: 0.5rem; }

/* Balkenliste: häufigste Absender */
.barlist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 11rem) minmax(3rem, 1fr) max-content; gap: 0.55rem 0.7rem; align-items: center; }
.barlist li { display: contents; }
.barlist-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.barlist-track { height: 14px; display: block; }
.barlist-bar { display: block; height: 100%; min-width: 2px; background: var(--series); border-radius: 0 4px 4px 0; }
.barlist-value { font-variant-numeric: tabular-nums; text-align: right; }

/* Blazor */
#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; padding: 0.7rem 1.2rem; background: var(--error-surface); color: var(--text); border-top: 1px solid var(--error); }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.8rem; top: 0.6rem; }

/* Angebote */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.8rem; margin-bottom: 1.2rem; }
.filters label { display: flex; flex-direction: column; gap: 0.25rem; }
.filters label > span { color: var(--text-secondary); font-size: 0.85rem; }
.filters .filter-text { flex: 1; min-width: 14rem; }
.filters .filter-text input { width: 100%; min-width: 0; }
select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--axis);
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
}
.offers { table-layout: fixed; }
.offers th:nth-child(1) { width: 9.5rem; }
.offers th:nth-child(3) { width: 16%; }
.offers th:nth-child(4) { width: 13%; }
.offers th:nth-child(5) { width: 4.8rem; }
.offers th:nth-child(6) { width: 5.5rem; }
.offers th:nth-child(7) { width: 5rem; }
.offers .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offers .offer-title { overflow-wrap: anywhere; }
@media (max-width: 1200px) {
    .offers th:nth-child(3), .offers td:nth-child(3), .offers th:nth-child(6), .offers td:nth-child(6) { display: none; }
    .offers th:nth-child(1) { width: 7.2rem; }
    .offers th:nth-child(4) { width: 22%; }
    .offers td:nth-child(1) { white-space: normal; }
}

/* Trends */
.tile-note { color: var(--muted); font-size: 0.85rem; }
.grid-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1300px) { .grid-even { grid-template-columns: minmax(0, 1fr); } }
.trends { table-layout: fixed; margin-bottom: 0.9rem; }
.trends th:nth-child(n+2) { width: 4.8rem; }
.trends th:nth-child(5) { width: 6.8rem; }
.trends .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trends tr.notable td { font-weight: 600; }
.trendlist { list-style: none; margin: 0 0 0.8rem; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr) max-content; gap: 0.35rem 1rem; }
.trendlist li { display: contents; }
.trendlist span { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Erinnerungen */
.badge { display: inline-block; margin-left: 0.4rem; padding: 0 0.45rem; border-radius: 999px; background: var(--series); color: #fff; font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.savebar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.8rem; margin-bottom: 1.2rem; }
.savebar label { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; min-width: 14rem; max-width: 30rem; }
.savebar label > span { color: var(--text-secondary); font-size: 0.85rem; }
input[type="text"] { font: inherit; padding: 0.45rem 0.7rem; border-radius: 6px; border: 1px solid var(--axis); background: var(--surface); color: var(--text); }
.reminder-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.6rem; }

/* Anmeldung */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.2rem; }
.login { width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 0.9rem; margin: 0; }
.login h1 { margin: 0 0 0.2rem; font-size: 1.4rem; }
.login label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--text-secondary); font-size: 0.9rem; }
.login input { width: 100%; box-sizing: border-box; font: inherit; padding: 0.5rem 0.7rem; border-radius: 6px; border: 1px solid var(--axis); background: var(--page); color: var(--text); }
.login button { margin-top: 0.3rem; }
.login-error { margin: 0; padding: 0.6rem 0.8rem; border-radius: 8px; border: 1px solid var(--error); background: var(--error-surface); }
.logout { margin-top: auto; padding-top: 1rem; }
.logout button { width: 100%; }
@media (max-width: 720px) {
    .logout { margin: 0 0 0 auto; padding: 0; }
    .logout button { width: auto; }
}
