:root {
  --brand: #1c2040;
  --brand-ink: #ffffff;
  --accent: #a3202f;
  --soft: #f6efe0;

  --bg: #eceef2;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #e6e8ee;
  --text: #15171c;
  --muted: #6b7180;
  --hover: #f1f3f7;
  --select: #eceff5;
  --thumb: #c5c9d3;
  --shadow: 0 1px 2px rgba(16, 20, 40, .06), 0 12px 32px rgba(16, 20, 40, .08);

  --radius: 12px;
  --radius-sm: 8px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0f14;
    --surface: #15181f;
    --surface-2: #1a1d25;
    --line: #262a34;
    --text: #eceef3;
    --muted: #9399a8;
    --hover: #1d212a;
    --select: #222733;
    --thumb: #3b4152;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f14;
  --surface: #15181f;
  --surface-2: #1a1d25;
  --line: #262a34;
  --text: #eceef3;
  --muted: #9399a8;
  --hover: #1d212a;
  --select: #222733;
  --thumb: #3b4152;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
}

*, *::before, *::after { box-sizing: border-box; }

* { scrollbar-width: thin; scrollbar-color: var(--thumb) transparent; }

html, body { height: 100%; }
html { overflow-x: hidden; }

body {
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2 { margin: 0; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.btn-block { width: 100%; }

/* ---------- Anmeldung ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 14px;
  padding: 32px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-logo { display: block; max-height: 72px; max-width: 200px; width: auto; height: auto; margin: 0 auto 4px; object-fit: contain; }
.login-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.login-card .muted { margin: -6px 0 4px; text-align: center; }
.login-field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-field input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
}
.login-field input:focus { outline: 0; border-color: var(--accent); background: var(--surface); }
.login-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-size: 13.5px; }
.demo-note { margin: 0; padding: 8px 12px; border-radius: 10px; background: var(--select); font-size: 13px; text-align: center; }
.login-card .btn { height: 44px; margin-top: 4px; }
.login-card .btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- HTML-Mails ---------- */
.mail-frame {
  display: block;
  width: 100%;
  height: 120px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color-scheme: light;
}
.mail-frame.is-dark { border-color: transparent; background: transparent; color-scheme: normal; }
.bar-right { margin-left: auto; }
.images-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.images-bar .link-btn {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--hover);
  font-size: 12px;
  white-space: nowrap;
}
.images-bar .link-btn:hover { background: var(--select); text-decoration: none; }

/* ---------- Anhaenge beim Schreiben ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2);
  font-size: 12.5px;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip-size { color: var(--muted); }
.chip button { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.chip button:hover { background: var(--hover); color: var(--text); }

.load-more { margin: 8px 16px 12px; width: calc(100% - 32px); }
.btn[disabled] { opacity: .6; cursor: progress; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 16px; height: 16px; }
.ic-xl { width: 40px; height: 40px; stroke-width: 1.3; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  background: var(--surface);
}

.app.is-collapsed { grid-template-columns: 76px minmax(0, 1fr); }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px 14px;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 0 4px;
}

.brand-logo {
  display: block;
  max-height: 52px;
  max-width: 150px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.brand-wordmark {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  color: var(--text);
}
.search input::placeholder { color: var(--muted); }
.search kbd {
  font: 11px/1 var(--font);
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.nav { display: grid; gap: 2px; align-content: start; flex: 1; overflow: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background .15s;
}
.nav-item .ic { color: var(--muted); }
.nav-item:hover { background: var(--hover); }
.nav-item.is-active { background: var(--select); font-weight: 600; }
.nav-item.is-active .ic { color: var(--accent); }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  min-width: 22px; padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 11.5px; font-weight: 600; text-align: center;
}

.sidebar-foot { display: grid; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); }

.quota-bar { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; }
.quota-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s; }
.quota-text { margin-top: 6px; font-size: 12px; color: var(--muted); }

.user {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 6px;
  border: 0; border-radius: 10px;
  background: transparent; text-align: left;
}
.user:hover { background: var(--hover); }
.user-text { display: grid; min-width: 0; flex: 1; }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mail { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  flex: none;
  font-weight: 600; font-size: 14px;
  color: #fff;
  background: var(--brand);
  user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }

.app.is-collapsed .brand-logo,
.app.is-collapsed .brand-wordmark,
.app.is-collapsed .search-side,
.app.is-collapsed .nav-label,
.app.is-collapsed .nav-count,
.app.is-collapsed .quota,
.app.is-collapsed .user-text,
.app.is-collapsed .user .ic { display: none; }
.app.is-collapsed .brand { justify-content: center; }
.app.is-collapsed .nav-item { justify-content: center; padding: 0; }
.app.is-collapsed .user { justify-content: center; }

/* ---------- Hauptbereich ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--surface); }

.theme-toggle .ic { display: none; }
.theme-toggle[data-mode="auto"] .ic-auto,
.theme-toggle[data-mode="light"] .ic-light,
.theme-toggle[data-mode="dark"] .ic-dark { display: block; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -.015em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  transition: transform .1s, background .15s, filter .15s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn-primary:hover { background: var(--brand); filter: brightness(1.15); }

.panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
}

/* ---------- Liste ---------- */
.list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 10px; }

:root { --star: #f0b429; }

.mail-item { position: relative; }
.mail-item .mail { padding-right: 16px; }
.mail-subject { padding-right: 30px; }

.mail-star {
  position: absolute;
  right: 12px;
  top: 40px;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.mail-star .ic { width: 17px; height: 17px; }
.mail-item:hover .mail-star, .mail-star:focus-visible { opacity: 1; }
.mail-star:hover { background: var(--hover); color: var(--text); }
.mail-star.is-on, .star-btn.is-on { opacity: 1; color: var(--star); }
.mail-star.is-on .ic, .star-btn.is-on .ic { fill: var(--star); stroke: var(--star); }
@media (hover: none) { .mail-star { opacity: .55; } .mail-star.is-on { opacity: 1; } }

.link-btn {
  padding: 2px 4px;
  border: 0; background: transparent;
  color: var(--accent);
  font-size: 12.5px; font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 230px; padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 38px; padding: 0 10px;
  border: 0; border-radius: 8px;
  background: transparent; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); }
.menu .ic { color: var(--muted); }

.tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2);
}
.tab {
  height: 30px; padding: 0 14px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16,20,40,.08); }

.list { flex: 1; overflow: auto; }

.mail {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  transition: background .12s;
}
.mail:hover { background: var(--hover); }
.mail.is-active { background: var(--select); }
.mail.is-active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent);
}
.mail-body { min-width: 0; }
.mail-row { display: flex; align-items: center; gap: 8px; }
.mail-from { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail.is-unread .mail-from, .mail.is-unread .mail-subject { font-weight: 700; }
.mail-time { font-size: 12px; color: var(--muted); flex: none; }
.mail-subject { display: flex; align-items: center; gap: 8px; margin-top: 2px; overflow: hidden; }
.mail-subject span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-preview { margin-top: 2px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.mail .clip { color: var(--muted); }

.list-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.list-empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------- Lesebereich ---------- */
.reader { min-width: 0; min-height: 0; overflow: auto; background: var(--surface); }

.reader-empty {
  height: 100%;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--muted);
}

.message { width: 100%; padding: 28px clamp(24px, 3vw, 56px) 48px; }

.message-head { display: flex; align-items: center; gap: 12px; }
.message-who { flex: 1; min-width: 0; }
.message-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-to { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-date { font-size: 12.5px; white-space: nowrap; }
.message-actions { display: flex; gap: 2px; }

.message-subject { margin: 22px 0 14px; font-size: 22px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }

.message-body { font-size: 14.5px; line-height: 1.65; }
.message-body p { margin: 0 0 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

.attachments { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.attachment {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2);
}
.attachment .ic { color: var(--accent); width: 26px; height: 26px; }
.attachment-name { font-weight: 600; font-size: 13px; }
.attachment-meta { font-size: 12px; color: var(--muted); }
.attachment-meta a { color: var(--accent); font-weight: 600; text-decoration: none; }
.attachment-meta a:hover { text-decoration: underline; }

.reply {
  margin-top: 28px;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.reply-head { font-size: 13px; margin-bottom: 8px; }
.reply textarea, .compose textarea {
  display: block;
  width: 100%;
  border: 0; outline: 0; resize: none;
  background: transparent;
  line-height: 1.6;
  overflow-y: auto;
}
.reply textarea { min-height: 72px; max-height: 50vh; }
.reply-foot, .compose-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

/* ---------- Verfassen ---------- */
.modal {
  position: fixed; inset: 0;
  display: grid; place-items: end center;
  padding: 24px;
  background: rgba(10, 12, 20, .45);
  z-index: 40;
}
@media (min-width: 700px) { .modal { place-items: center; } }

.compose {
  width: min(640px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  padding: 18px 20px 16px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.compose-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.compose-head h2 { font-size: 16px; font-weight: 700; }
.field { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.field span, .field label { width: 56px; flex: none; color: var(--muted); font-size: 13px; }
.field input { flex: 1; border: 0; outline: 0; background: transparent; }
.compose textarea { margin-top: 12px; min-height: 180px; max-height: 50vh; }

/* ---------- Sonstiges ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 60;
}

.scrim { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); z-index: 25; }

.tip {
  position: fixed;
  z-index: 80;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(10, 12, 20, .25);
  animation: tip-in .12s ease-out;
}
@keyframes tip-in { from { opacity: 0; } to { opacity: 1; } }

.only-mobile { display: none; }
.top-logo { display: none; }

/* ---------- Tablet ---------- */
@media (max-width: 1099px) {
  .app { grid-template-columns: 76px minmax(0, 1fr); }
  .app .brand-logo, .app .brand-wordmark, .app .search-side, .app .nav-label,
  .app .nav-count, .app .quota, .app .user-text, .app .user .ic { display: none; }
  .app .brand { justify-content: center; }
  .app .nav-item { justify-content: center; padding: 0; }
  .app .user { justify-content: center; }
  .topbar { padding: 0 18px; }
  .panes { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .message { padding: 20px 22px 32px; }
}

/* ---------- Handy: eine Spalte ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform .22s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  .app.menu-open .sidebar { transform: none; }
  .app .brand-logo { display: block; }
  .app .brand-wordmark { display: block; }
  .app .search-side, .app .nav-label, .app .quota, .app .user-text, .app .user .ic { display: flex; }
  .app .nav-count { display: block; }
  .app .user-text { display: grid; }
  .app .brand { justify-content: space-between; }
  .app .nav-item { justify-content: flex-start; padding: 0 10px; }
  .app .user { justify-content: flex-start; }

  .only-mobile { display: inline-grid; }
  .topbar { height: 60px; padding: 0 12px; }
  .topbar h1 { font-size: 18px; }
  .topbar .btn span { display: none; }
  .topbar .btn { width: 38px; padding: 0; }
  .top-logo { display: block; height: 30px; width: auto; max-width: 84px; object-fit: contain; flex: none; }

  .panes { grid-template-columns: minmax(0, 1fr); position: relative; overflow: hidden; }
  .reader {
    position: absolute; inset: 0; z-index: 5;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .app[data-view="read"] .reader {
    transform: none;
    visibility: visible;
    transition: transform .22s ease, visibility 0s;
  }
  .message { padding: 14px 16px 28px; }
  .message-date { display: none; }
  .message-subject { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
