/* ============================================================
   Mail Sorter – Stylesheet
   Dunkel- & Hell-Modus über [data-theme] auf <html>
   ============================================================ */

:root {
  --indigo: #6366f1;
  --indigo-600: #4f46e5;
  --sky: #0ea5e9;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --violet: #8b5cf6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maxw: 980px;
}

/* ---- Dunkel (Standard) ---- */
:root, :root[data-theme="dark"] {
  --bg: #0b1020;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #1b2550 0%, transparent 55%),
             radial-gradient(900px 500px at -10% 10%, #241b4d 0%, transparent 50%);
  --surface: #141a2e;
  --surface-2: #1b2238;
  --surface-3: #232c46;
  --border: #2a3355;
  --text: #eef1fb;
  --text-dim: #aab1cc;
  --text-mute: #727aa0;
  --primary: var(--indigo);
  --primary-text: #fff;
  --input-bg: #0f1526;
}

/* ---- Hell ---- */
:root[data-theme="light"] {
  --bg: #eef1f8;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #dfe6ff 0%, transparent 55%),
             radial-gradient(900px 500px at -10% 10%, #e8e2ff 0%, transparent 50%);
  --surface: #ffffff;
  --surface-2: #f6f8fd;
  --surface-3: #eef1f8;
  --border: #dce1ef;
  --text: #121833;
  --text-dim: #4a5272;
  --text-mute: #8891ad;
  --primary: var(--indigo-600);
  --primary-text: #fff;
  --input-bg: #ffffff;
  --shadow: 0 10px 30px rgba(40, 50, 90, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
body.modal-open { overflow: hidden; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.02em; }
.muted { color: var(--text-mute); font-size: .9rem; }

/* ============================================================
   Auth (Setup / Login)
   ============================================================ */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { font-size: 48px; line-height: 1; }
.auth-title { font-size: 1.6rem; margin-top: 10px; }
.auth-tagline { color: var(--text-mute); margin: 6px 0 0; font-size: .92rem; }
.auth-divider { height: 1px; background: var(--border); margin: 22px 0; }
.auth-subtitle { font-size: 1.15rem; }
.auth-hint { color: var(--text-dim); font-size: .9rem; margin: 8px 0 20px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.pin-input {
  width: 100%;
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: .4em;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
}
.pin-input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.lang-switch-small { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.lang-pill {
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  padding: 4px 14px; border-radius: 999px; font-size: .8rem; font-weight: 600;
}
.lang-pill.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.form-error { color: var(--red); font-size: .88rem; min-height: 1.1em; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: .92rem; font-weight: 600; color: var(--text);
  background: var(--surface-3); transition: transform .06s, filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: var(--primary-text); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); background: var(--surface-2); }
.btn--warn { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.btn--block { width: 100%; padding: 13px; }
.btn--sm { padding: 6px 10px; font-size: .82rem; }
.btn--icon { padding: 9px; width: 40px; height: 40px; }
.btn svg { display: block; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--text-mute);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ============================================================
   Topbar / Navigation
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-logo { font-size: 24px; }
.brand-name { font-weight: 800; font-size: 1.1rem; letter-spacing: -.02em; }
.nav--top { display: flex; gap: 4px; margin-left: 12px; flex: 1; }
.nav-item {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: none; color: var(--text-dim);
  padding: 9px 14px; border-radius: 10px; font-size: .92rem; font-weight: 600;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.nav-item.active .nav-icon { color: var(--primary); }
.nav-icon { display: inline-flex; color: var(--text-mute); }

.nav--bottom { display: none; }

/* ============================================================
   Layout / Views
   ============================================================ */
.main { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 90px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h1 { font-size: 1.6rem; }
.section-title { font-size: 1.1rem; margin: 28px 0 14px; color: var(--text-dim); }

/* ---- Statistik-Kacheln ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden;
}
.stat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); }
.stat-card.accent-indigo::before { background: var(--indigo); }
.stat-card.accent-sky::before { background: var(--sky); }
.stat-card.accent-green::before { background: var(--green); }
.stat-card.accent-amber::before { background: var(--amber); }
.stat-card.accent-red::before { background: var(--red); }
.stat-card.accent-violet::before { background: var(--violet); }
.stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; }
.stat-label { color: var(--text-mute); font-size: .85rem; margin-top: 2px; }

/* ---- Schnellzugriff ---- */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.quick-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 18px; font-weight: 600;
  transition: transform .08s, border-color .15s;
}
.quick-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.quick-icon { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }

/* ---- Toolbar / Suche / Filter ---- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search, .select, .input {
  background: var(--input-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: .92rem;
}
.search { flex: 1; min-width: 180px; }
.search:focus, .select:focus, .input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.select { min-width: 140px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  padding: 7px 14px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* ---- Karten-Liste (Konten / Abos) ---- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  transition: border-color .15s, transform .08s;
}
.card:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.1rem;
}
.avatar--square { border-radius: 12px; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--text-mute); font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.card-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.badge {
  font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary);
  white-space: nowrap;
}
.badge--soft { background: var(--surface-3); color: var(--text-dim); }
.badge--muted { background: transparent; border: 1px solid var(--border); color: var(--text-mute); }
.badge.status.st-active { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.badge.status.st-unsub { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.badge.status.st-spam { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.badge.status.st-ignored { background: var(--surface-3); color: var(--text-mute); }

/* ---- Leerer Zustand ---- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-mute); }
.empty-icon { color: var(--border); margin-bottom: 12px; }
.empty p { margin: 0; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 20, .6); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
  opacity: 0; transition: opacity .2s;
}
.modal-overlay.show { opacity: 1; }
.modal {
  width: 100%; max-width: 620px; max-height: 90vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
  transform: translateY(12px) scale(.98); transition: transform .2s;
}
.modal-overlay.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.2rem; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-dim); }
.field .input, .field .select { width: 100%; }
textarea.input { resize: vertical; font-family: inherit; }
.field--check { justify-content: flex-end; }
.check { flex-direction: row; align-items: center; gap: 8px; display: flex; cursor: pointer; }
.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1; }

.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; }
.color-dot.sel { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

/* ============================================================
   Einstellungen
   ============================================================ */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.settings-card h3 { font-size: 1rem; margin-bottom: 14px; }
.settings-card.note { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; }
.seg-btn { border: none; background: transparent; color: var(--text-dim); padding: 7px 18px; border-radius: 8px; font-weight: 600; font-size: .88rem; }
.seg-btn.active { background: var(--primary); color: var(--primary-text); }

/* ============================================================
   Toasts
   ============================================================ */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 13px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: .9rem; font-weight: 500;
  opacity: 0; transform: translateY(16px); transition: opacity .3s, transform .3s;
  border-left: 4px solid var(--primary);
}
.toast.show { opacity: 1; transform: none; }
.toast--success { border-left-color: var(--green); }
.toast--error { border-left-color: var(--red); }

/* ============================================================
   Ergänzungen: Postfächer, Mails, Abos
   ============================================================ */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-meta { color: var(--text-mute); font-size: .78rem; margin-top: 6px; }
.hint-banner {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  color: var(--text-dim); padding: 14px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: .92rem;
}
.subhint { margin: -8px 0 16px; }

/* Sync-Spinner */
.spin { display: inline-flex; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn[disabled] { opacity: .6; pointer-events: none; }

/* Formular-Hinweise */
.field-hint { color: var(--text-mute); font-size: .76rem; }
.form-hint { color: var(--amber); font-size: .8rem; min-height: 1em; }
/* Schritt-für-Schritt-Anleitung je Anbieter */
.guide-slot:empty { display: none; }
.guide { margin-top: 8px; border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); font-size: .86rem; line-height: 1.45; }
.guide--warn { border-left-color: var(--amber); }
.guide summary { cursor: pointer; font-weight: 600; list-style-position: outside; }
.guide ol { margin: 8px 0 10px; padding-left: 1.3em; display: grid; gap: 6px; }
.guide .btn { display: inline-flex; text-decoration: none; }
.mb-fix { margin-top: 8px; }
.auto-note { color: var(--green); font-size: .82rem; min-height: 1em; font-weight: 600; }

/* Einklappbare IMAP-Einstellungen */
.advanced { margin: 4px 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.advanced > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; font-size: .88rem; color: var(--text-dim); background: var(--surface-2); user-select: none; }
.advanced > summary:hover { color: var(--text); }
.advanced > .modal-grid { padding: 14px; }

/* „Mehr laden" */
.more-wrap { display: flex; justify-content: center; margin-top: 16px; }

/* Kontext-Menü (Abo-Status) */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 15;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; min-width: 190px; display: none; flex-direction: column;
}
.menu-wrap.open .menu { display: flex; }
.menu-item { text-align: left; background: transparent; border: none; color: var(--text); padding: 9px 12px; border-radius: 8px; font-size: .88rem; }
.menu-item:hover { background: var(--surface-2); }

/* ============================================================
   Postfach-Auswahl, Mail-Liste, Sprachumschalter
   ============================================================ */
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.lang-toggle {
  display: inline-flex; border: 1px solid var(--border); background: transparent;
  border-radius: 999px; padding: 3px; gap: 2px;
}
.lang-toggle span { font-size: .72rem; font-weight: 700; padding: 4px 8px; border-radius: 999px; color: var(--text-mute); }
.lang-toggle span.on { background: var(--primary); color: var(--primary-text); }

/* Waagerechte Postfach-Leiste (wischbar am Handy) */
.mb-tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin-bottom: 14px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.mb-tab {
  flex: none; display: inline-flex; align-items: center; gap: 8px; scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 12px; padding: 9px 12px; font-size: .88rem; font-weight: 600; max-width: 240px;
  transition: border-color .15s, background .15s, color .15s;
}
.mb-tab:hover { color: var(--text); border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.mb-tab.active { background: color-mix(in srgb, var(--primary) 16%, var(--surface)); border-color: var(--primary); color: var(--text); }
.mb-tab:focus-visible, .card-body--link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.mb-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.mb-dot--all { width: auto; height: auto; display: inline-flex; color: var(--text-mute); }
.mb-dot--all svg { width: 16px; height: 16px; }
.mb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.mb-count {
  font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-dim); font-variant-numeric: tabular-nums;
}
.mb-tab.active .mb-count { background: var(--primary); color: var(--primary-text); }

/* Info-Karte zum gewählten Postfach */
.mb-strip {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.mb-strip-body { flex: 1; min-width: 0; }
.mb-strip-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--text-mute); font-size: .8rem; margin-top: 2px; }

/* Tages-Überschriften */
.list-group {
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mute); margin: 14px 4px 2px;
}
.list-group:first-child { margin-top: 0; }

/* Mail-Karten */
.card--mail { padding: 12px 14px; }
.mail-line { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.mail-from { flex: 1; min-width: 0; font-size: .86rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-date { flex: none; font-size: .76rem; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.card--mail .card-title { font-weight: 500; }
.card--unread .card-title, .card--unread .mail-from { font-weight: 700; color: var(--text); }
.card--unread { border-left: 3px solid var(--primary); }

/* Antippbarer Karteninhalt (Postfach -> Mails) */
.card-body--link {
  text-align: left; background: transparent; border: none; padding: 0; color: inherit; font: inherit;
}

/* ============================================================
   Responsive (Smartphone)
   ============================================================ */
@media (max-width: 720px) {
  .nav--top { display: none; }
  .topbar { padding: 12px 16px; }
  .main { padding: 18px 16px 90px; }
  .view-head h1 { font-size: 1.35rem; }
  .modal-grid { grid-template-columns: 1fr; }
  .nav--bottom {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .nav--bottom .nav-item { flex-direction: column; gap: 3px; padding: 6px 8px; font-size: .68rem; flex: 1; }
  .nav--bottom .nav-label { font-size: .68rem; }
  .card-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 120px; }
  .card--mail .card-actions { max-width: none; flex-direction: column; }
  .card--mail .card-actions .btn--warn span:last-child { display: none; } /* nur Symbol */
  .mb-strip { flex-wrap: wrap; }
}
@media (max-width: 420px) {
  .card-sub { display: none; }
}
