/* Nocturne visual foundation, implemented locally without runtime dependencies. */
:root, :root[data-theme="light"] {
  --bg: #f6f6fb; --surface: #ffffff; --text: #222331; --muted: #606375;
  --border: #d9d9e5; --primary: #6655a7; --primary-text: #ffffff;
  --danger: #a52536; --danger-bg: #fff0f2; --ok: #246c46; --ok-bg: #edf8f0;
  --warn-bg: #fff7df; --warn-border: #a67a00; --focus: #6655a7;
  --selected: #ece8fa; --hover: #efeff7; --radius: 8px;
  --color-neutral-100: #222331; --color-neutral-200: #303244; --color-neutral-300: #494c61;
  --color-neutral-400: #606375; --color-neutral-500: #6b6e80; --color-neutral-600: #898c9d;
  --color-neutral-700: #b7b9c8; --color-neutral-800: #d9d9e5; --color-neutral-900: #e9e9f1;
  --color-accent-100: #fff; --color-accent-200: #e7e5fe; --color-accent-300: #6655a7;
  --color-accent-400: #7561bc; --color-accent-500: #968ae0; --color-accent-600: #796cbf;
  --color-accent-700: #a99bd8; --color-accent-800: #d8d0ed; --color-accent-900: #ece8fa;
  --shadow-sm: 0 0 0 1px var(--border); --shadow-md: 0 0 0 1px var(--border), 0 6px 18px #22233118;
  --shadow-lg: 0 0 0 1px var(--border), 0 16px 40px #22233124;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #161826; --surface: #232532; --text: #e9e9ed; --muted: #b2b6ca;
  --border: #3f424d; --primary: #9184d9; --primary-text: #161826;
  --danger: #ff9ba5; --danger-bg: #3d202c; --ok: #8dd4a5; --ok-bg: #1e352c;
  --warn-bg: #39311e; --warn-border: #d4b567; --focus: #b5abfc;
  --selected: #2b2741; --hover: #202231;
  --color-neutral-100: #f3f5fe; --color-neutral-200: #e4e7f5; --color-neutral-300: #cfd3e5;
  --color-neutral-400: #b2b6ca; --color-neutral-500: #9397ab; --color-neutral-600: #75798c;
  --color-neutral-700: #595d6c; --color-neutral-800: #3f424d; --color-neutral-900: #292b31;
  --color-accent-100: #f5f4ff; --color-accent-200: #e7e5fe; --color-accent-300: #d2cefd;
  --color-accent-400: #b5abfc; --color-accent-500: #968ae0; --color-accent-600: #796cbf;
  --color-accent-700: #5d5294; --color-accent-800: #423a6a; --color-accent-900: #2b2741;
  --shadow-sm: 0 0 0 1px #3f424d; --shadow-md: 0 0 0 1px #595d6c, 0 6px 18px #0008;
  --shadow-lg: 0 0 0 1px #9397ab, 0 16px 40px #000a;
  color-scheme: dark;
}
:root {
  --color-bg: var(--bg); --color-surface: var(--surface); --color-text: var(--text);
  --color-accent: var(--primary); --color-accent-2: #a7a1db; --color-divider: var(--border);
  --font-heading: system-ui, -apple-system, "Segoe UI", sans-serif; --font-body: var(--font-heading);
  --space-1: 2.8px; --space-2: 5.6px; --space-3: 8.4px; --space-4: 11.2px; --space-6: 16.8px; --space-8: 22.4px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding-top: 1rem; padding-bottom: 2rem; outline: none; }
.wrap { width: 100%; max-width: 62rem; margin: 0 auto; padding-left: 1rem; padding-right: 1rem; }

h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
p { margin: 0.5rem 0; }
a { color: var(--primary); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link {
  position: absolute; left: 0.5rem; top: -4rem; background: var(--surface);
  padding: 0.5rem 0.75rem; border: 2px solid var(--primary); border-radius: var(--radius); z-index: 100;
}
.skip-link:focus { top: 0.5rem; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding-top: 0.5rem; padding-bottom: 0.5rem; }
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
#nav { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-left: auto; }
#nav a, #nav button {
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 0.75rem;
  border-radius: var(--radius); text-decoration: none; color: var(--text);
  background: transparent; border: 1px solid transparent; font: inherit; cursor: pointer;
}
#nav a:hover, #nav button:hover { background: var(--bg); border-color: var(--border); }
#nav a[aria-current="page"] { border-color: var(--primary); color: var(--primary); font-weight: 600; }

.notice-m0 { background: var(--warn-bg); border-bottom: 1px solid var(--warn-border); font-size: 0.9rem; padding: 0.5rem 0; }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; padding: 0.75rem 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin: 0 0 1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.narrow { max-width: 28rem; margin-left: auto; margin-right: auto; }

.alert {
  border: 1px solid var(--danger); background: var(--danger-bg); color: var(--text);
  border-left-width: 6px; border-radius: var(--radius); padding: 0.75rem 1rem; margin: 0.75rem 0;
}
.alert.ok { border-color: var(--ok); background: var(--ok-bg); }
.alert.warn { border-color: var(--warn-border); background: var(--warn-bg); }
.alert .ref { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }

label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.field { margin: 0 0 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.875rem; margin: 0.25rem 0 0; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 0.5rem 0.75rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
input[type="checkbox"] { width: auto; min-height: 0; transform: scale(1.3); margin-right: 0.5rem; }
.check { display: flex; align-items: center; font-weight: 400; min-height: 44px; }
input[readonly] { background: var(--bg); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 1rem; padding: 0.75rem 1rem; }
legend { font-weight: 600; padding: 0 0.25rem; }

button, .btn {
  min-height: 44px; padding: 0.5rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--primary); background: var(--primary); color: var(--primary-text);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
button.secondary, .btn.secondary { background: transparent; color: var(--primary); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.link-btn { background: none; border: 0; color: var(--primary); text-decoration: underline; min-height: 44px; padding: 0 0.25rem; font-weight: 400; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: 1rem 0; }
.tabs a {
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 0.9rem; text-decoration: none;
  color: var(--text); border: 1px solid transparent; border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
}
.tabs a[aria-current="page"] { background: var(--surface); border-color: var(--border); color: var(--primary); font-weight: 600; margin-bottom: -1px; }

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; justify-content: space-between;
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row .main { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.row .title { font-weight: 600; }
.badge {
  display: inline-block; font-size: 0.8rem; padding: 0.1rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); margin-left: 0.25rem; vertical-align: middle;
}
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.bad { color: var(--danger); border-color: var(--danger); }
.badge.warn { color: var(--text); border-color: var(--warn-border); background: var(--warn-bg); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { white-space: nowrap; }
td.wrap-any { overflow-wrap: anywhere; min-width: 10rem; }

.copybox { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: stretch; }
.copybox input { flex: 1 1 14rem; }
.codes { columns: 2; list-style: none; padding: 0.75rem; margin: 0.5rem 0; background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius); }
.codes li { padding: 0.15rem 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }

dialog {
  max-width: 28rem; width: calc(100% - 2rem); padding: 1rem; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

.toasts { position: fixed; left: 1rem; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; pointer-events: none; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: var(--radius); max-width: 28rem; }

@media (max-width: 30rem) {
  .codes { columns: 1; }
  h1 { font-size: 1.3rem; }
  .actions > button, .actions > .btn { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* --- Mail --------------------------------------------------------------- */
main.wide { max-width: 90rem; }
.mail-head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.25rem 1rem; }
.mail-head-row .actions { margin-top: 0; }
.mail-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
.mail-folders, .mail-list-pane, .mail-detail {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; min-width: 0;
}
.mail-detail { outline: none; }
.mail-back { margin-bottom: 0.5rem; }
@media (min-width: 60rem) {
  .mail-layout { grid-template-columns: 15rem minmax(18rem, 26rem) minmax(0, 1fr); }
  .mail-back { display: none; }
}
@media (max-width: 59.99rem) {
  .mail-layout.has-msg .mail-folders, .mail-layout.has-msg .mail-list-pane { display: none; }
}
.mail-acc { margin-bottom: 1rem; }
.mail-acc-head { overflow-wrap: anywhere; margin-bottom: 0.25rem; }
.mail-acc-err { color: var(--danger); margin: 0.25rem 0; overflow-wrap: anywhere; }
.mail-folder {
  width: 100%; justify-content: space-between; gap: 0.5rem; text-align: left;
  background: transparent; color: var(--text); border-color: transparent; font-weight: 400;
}
.mail-folder:hover { background: var(--bg); border-color: var(--border); }
.mail-folder[aria-current="true"] { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.mail-count {
  min-width: 1.5rem; padding: 0 0.4rem; text-align: center; border-radius: 999px; font-size: 0.8rem;
  background: var(--primary); color: var(--primary-text);
}
.mail-filters { margin-bottom: 0.75rem; }
.mail-filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0 0.75rem; }
.mail-list { list-style: none; margin: 0; padding: 0; }
.mail-item { border-bottom: 1px solid var(--border); }
.mail-row {
  width: 100%; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 0.15rem;
  text-align: left; background: transparent; color: var(--text); border: 1px solid transparent; font-weight: 400; padding: 0.5rem;
}
.mail-row:hover { background: var(--bg); }
.mail-row[aria-current="true"] { background: var(--bg); border-color: var(--primary); }
.mail-row.unread .mail-from, .mail-row.unread .mail-subject { font-weight: 700; }
.mail-row-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.mail-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.mail-subject { overflow-wrap: anywhere; }
.mail-meta { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; font-size: 0.8rem; color: var(--muted); }
.mail-meta .badge { margin-left: 0; }
.mail-acct { overflow-wrap: anywhere; margin-right: 0.25rem; }
.mail-title { margin-top: 0; overflow-wrap: anywhere; }
.mail-head { margin-bottom: 0.75rem; }
.mail-toolbar .actions { margin-top: 0.5rem; }
.mail-move select { width: auto; flex: 1 1 12rem; }
.mail-frame {
  width: 100%; height: 60vh; min-height: 20rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: #ffffff; resize: vertical; display: block;
}
.mail-text {
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 0.75rem; background: var(--bg);
  border-radius: var(--radius); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92rem;
}
.mail-body { margin-top: 0.75rem; }
.mail-attachments { margin-top: 1rem; }
.mail-placeholder { padding: 1rem 0.25rem; }
.mail-body-input { min-height: 16rem; resize: vertical; }
.mail-test { list-style: none; padding: 0; margin: 0.5rem 0; }
.mail-test li { margin: 0.35rem 0; }
.mail-sig { white-space: pre-wrap; }
.mail-focus { background: var(--warn-bg); }
.mail-sub .main > * { margin-top: 0.25rem; }

/* --- Mail: Ordnerverwaltung, Ziehen, Anpinnen, Filter ---------------------------- */
.mail-item { display: flex; align-items: stretch; }
.mail-item .mail-row { flex: 1 1 auto; min-width: 0; }
.mail-item.dragging { opacity: 0.5; }
.mail-pin { min-width: 44px; padding: 0 0.5rem; border-color: transparent; filter: grayscale(1); opacity: 0.55; }
.mail-pin.on { filter: none; opacity: 1; }
.mail-pin:hover { opacity: 1; }
.mail-folder.drop-target { border-color: var(--primary); background: var(--bg); outline: 2px dashed var(--primary); outline-offset: -2px; }
.mail-folder.drop-denied { border-color: var(--danger); cursor: not-allowed; opacity: 0.6; }
.mail-folder-admin, .mail-sieve, .mail-sieve-scripts { margin-top: 0.75rem; }
.mail-rule-list { display: block; }
.mail-rule { margin-bottom: 1rem; }
.mail-rule h4 { margin-top: 0; }
.mail-cond { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.mail-cond select, .mail-cond input { width: auto; flex: 1 1 10rem; }
.mail-cond button { flex: 0 0 auto; }
.mail-rule-tools { margin-top: 0; }
.mail-sieve-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; min-height: 16rem; resize: vertical; white-space: pre; overflow: auto; }
.mail-oauth-help { margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
@media (max-width: 30rem) {
  .mail-cond select, .mail-cond input { flex: 1 1 100%; }
}

/* Shared application shell and module surfaces. */
[hidden] { display: none !important; }
body.app-shell {
  min-width: 0; min-height: 100dvh; display: grid;
  grid-template-columns: 60px minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr) auto;
  font: 14px/1.5 var(--font-body); overflow-wrap: anywhere;
}
body.app-shell::before { content: ''; position: fixed; inset: 0 auto 0 0; width: 60px; border-right: 1px solid var(--color-neutral-900); pointer-events: none; }
.app-shell > .brand { grid-column: 1; grid-row: 1; justify-self: center; align-self: center; width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--color-accent); border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--primary); }
.site-header { grid-column: 2; grid-row: 1; min-width: 0; background: var(--bg); border-color: var(--color-neutral-900); position: sticky; top: 0; z-index: 20; }
.bar { flex-wrap: nowrap; padding: 0 20px; gap: 18px; height: 52px; min-width: 0; }
#nav { grid-column: 1; grid-row: 2; margin: 0; padding: 12px 8px; gap: 4px; display: flex; flex-direction: column; align-items: center; position: sticky; top: 52px; align-self: start; }
#nav a { flex: none; width: 44px; height: 44px; padding: 0; justify-content: center; color: var(--color-neutral-500); border: 0; border-radius: 8px; }
#nav a:hover { background: var(--hover); }
#nav a[aria-current="page"] { color: var(--color-accent-300); background: var(--selected); }
#nav .nav-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); }
.icon { width: 20px; height: 20px; flex: none; }
.shell-search { display: flex; position: relative; align-items: center; min-width: 120px; flex: 0 1 380px; }
.shell-search input { min-height: 44px; height: 44px; padding: 5px 64px 5px 44px; font-size: 13px; background: var(--surface); }
.shell-search input:disabled { opacity: .7; }
.shell-search .search-submit { position: absolute; left: 0; top: 0; width: 44px; min-height: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 24px; }
.shell-search kbd { position: absolute; right: 10px; font: 10px var(--font-body); color: var(--color-neutral-500); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; pointer-events: none; }
.shell-accounts { display: flex; gap: 6px; min-width: 0; flex: 1; overflow: auto; scrollbar-width: none; }
.account-chip { display: inline-flex; align-items: center; gap: 6px; flex: none; max-width: 160px; min-height: 28px; padding: 2px 9px; text-decoration: none; border: 1px solid var(--border); border-radius: 999px; color: var(--text); font-size: 12px; }
.account-chip > span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.account-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color-accent); flex: none; }
.account-color-1 .account-dot { background: #68b7d8; }.account-color-2 .account-dot { background: #eb9990; }.account-color-3 .account-dot { background: #80be93; }.account-color-4 .account-dot { background: #d4b567; }.account-color-5 .account-dot { background: #73c3c6; }
.shell-tools { display: flex; align-items: center; margin-left: auto; gap: 10px; flex: none; }
#theme-mode { min-height: 44px; width: auto; max-width: 100px; font-size: 12px; padding: 4px 7px; background: transparent; }
.profile-avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--selected); color: var(--color-accent-300); text-decoration: none; font-size: 11px; font-weight: 600; }
.shell-login { white-space: nowrap; }
.shell-context { position: relative; }
.shell-context > summary { width: 44px; min-height: 44px; display: grid; place-items: center; border-radius: 8px; cursor: pointer; list-style: none; }
.shell-context > summary::-webkit-details-marker { display: none; }
.shell-context[open] > summary { background: var(--selected); color: var(--primary); }
#context-nav { position: absolute; top: 50px; right: -40px; width: 230px; padding: 8px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-md); z-index: 30; }
#context-nav a, #context-nav button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px; border: 0; border-radius: 8px; text-decoration: none; font-size: 13px; font-weight: 400; color: var(--text); background: transparent; justify-content: flex-start; }
#context-nav a:hover, #context-nav button:hover, #context-nav a[aria-current="page"] { background: var(--selected); }
.app-shell > main { grid-column: 2; grid-row: 2; width: 100%; min-width: 0; max-width: 1120px; padding: 24px; }
.app-shell > main.wide, .app-shell > main.workspace { max-width: none; }
.app-shell > main.workspace { padding: 0; }
.app-shell > main > * { min-width: 0; }
.site-footer { grid-column: 2; grid-row: 3; padding: 8px 22px; font-size: 11px; border-color: var(--color-neutral-900); }
body:not(.authenticated) > #nav { display: none; }
h1 { font-weight: 500; letter-spacing: -.02em; font-size: 28px; line-height: 1.25; }
h2 { font-weight: 500; letter-spacing: -.01em; }
h3 { font-weight: 500; }
button, .btn { border-radius: 8px; font-size: 13px; font-weight: 500; background: transparent; color: var(--primary); }
button:hover:not(:disabled), .btn:hover { background: var(--selected); }
button.secondary, .btn.secondary { border-color: var(--border); color: var(--text); }
input, select, textarea { font-size: 14px; }
label { font-size: 13px; font-weight: 500; }
.card { box-shadow: none; }
.badge { font-size: 11px; }
.tabs a { font-size: 13px; }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-md); }
dialog { max-width: 560px; max-height: calc(100dvh - 32px); overflow: auto; border-radius: 14px; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: #10111d99; }
.kv { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); }
.table-wrap, fieldset { min-width: 0; }
fieldset { max-width: 100%; }
.workspace-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100dvh - 86px); }
.workspace-sidebar { padding: 20px 14px; border-right: 1px solid var(--color-neutral-900); min-width: 0; }
.workspace-content { padding: 22px; min-width: 0; }
.workspace-title { margin: 0 0 8px; font-size: 28px; font-weight: 500; }
.workspace-meta { color: var(--muted); font-size: 12px; }
.workspace-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.workspace-toolbar .actions { margin-top: 0; }
.workspace-sidebar-heading { margin: 24px 8px 8px; color: var(--color-neutral-500); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.workspace-sidebar-link { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px; text-decoration: none; border-radius: 8px; color: var(--text); }
.workspace-sidebar-link[aria-current="page"], .workspace-sidebar-link[aria-current="true"], .workspace-sidebar-link.active { background: var(--selected); color: var(--color-accent-300); }
.workspace-list { list-style: none; padding: 0; margin: 0; }
.workspace-row { display: flex; gap: 12px; align-items: center; padding: 12px 8px; min-height: 56px; border-radius: 8px; min-width: 0; }
.workspace-row:hover { background: var(--hover); }
.workspace-row[aria-current="true"], .workspace-row.is-selected { background: var(--selected); box-shadow: inset 0 0 0 1px var(--color-accent-700); }
.workspace-row > * { min-width: 0; }
.workspace-split { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: calc(100dvh - 86px); min-width: 0; }
.workspace-detail { padding: 24px; background: var(--surface); border-left: 1px solid var(--color-neutral-900); min-width: 0; overflow-wrap: anywhere; }
.workspace-empty { padding: 24px; color: var(--muted); }
.contact-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--color-neutral-900); color: var(--color-neutral-300); font-size: 12px; font-weight: 600; }
.segmented { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; flex-wrap: wrap; }
.segmented button, .segmented a { border: 0; color: var(--muted); }
.segmented [aria-pressed="true"], .segmented [aria-current="page"] { background: var(--selected); color: var(--color-accent-300); }
.icon-button { display: inline-grid; place-items: center; width: 44px; min-height: 44px; padding: 0; border: 0; }
/* Retain all existing mail actions, filters and rendering; style their real panes. */
.mail-app { margin: 0; }
.mail-layout { gap: 0; }
.mail-folders, .mail-list-pane, .mail-detail { border: 0; border-radius: 0; padding: 14px; background: var(--bg); }
.mail-folders, .mail-list-pane { border-right: 1px solid var(--color-neutral-900); }
.mail-detail { background: var(--surface); }
.mail-row { border-radius: 8px; padding: 12px 8px; }
.mail-folder { min-height: 40px; padding: 6px 8px; font-size: 12px; }
.mail-folder[aria-current="true"] { background: var(--selected); border-color: transparent; }
.mail-row[aria-current="true"] { background: var(--selected); border-color: var(--color-accent-700); }
.mail-count { background: var(--selected); color: var(--color-accent-300); }
@media (min-width: 1200px) {
  .mail-layout { grid-template-columns: 250px minmax(300px, 420px) minmax(0, 1fr); }
}
@media (min-width: 768px) and (max-width: 1199px) {
  .shell-accounts { display: none; }
  .mail-layout { grid-template-columns: 190px minmax(0, 1fr); }
  .mail-detail { grid-column: 1 / -1; border-top: 1px solid var(--border); }
  .mail-layout.has-msg .mail-folders, .mail-layout.has-msg .mail-list-pane { display: block; }
  .mail-back { display: inline-flex; }
  .workspace-layout { grid-template-columns: 200px minmax(0, 1fr); }
  .workspace-split { grid-template-columns: 280px minmax(0, 1fr); }
}
@media (max-width: 767px) {
  body.app-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr) auto; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  body.app-shell::before { display: none; }
  .app-shell > .brand { display: none; }
  .site-header { grid-column: 1; }
  .bar { gap: 8px; padding: 0 12px; }
  .shell-accounts { display: none; }
  .shell-search { flex: 1; min-width: 0; }
  .shell-search kbd { display: none; }
  .shell-search input { padding-right: 6px; font-size: 12px; }
  .shell-tools { gap: 6px; }
  #theme-mode { max-width: 80px; padding: 4px; }
  #nav { position: fixed; inset: auto 0 0; top: auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: stretch; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; background: var(--bg); border-top: 1px solid var(--border); z-index: 25; }
  #nav a { width: 100%; height: 56px; flex-direction: column; gap: 3px; border-radius: 6px; font-size: 10px; font-weight: 400; }
  #nav .nav-label { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip-path: none; }
  #nav a[aria-current="page"] { background: transparent; }
  .app-shell > main { grid-column: 1; padding: 16px; }
  .app-shell > main.workspace { padding: 0; }
  .site-footer { grid-column: 1; padding: 8px 16px; }
  .workspace-layout, .workspace-split { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .workspace-sidebar { border-right: 0; border-bottom: 1px solid var(--color-neutral-900); padding: 12px 16px; }
  .workspace-content, .workspace-detail { padding: 16px; }
  .workspace-detail { border-left: 0; border-top: 1px solid var(--color-neutral-900); }
  .workspace-toolbar { gap: 8px; margin-bottom: 16px; }
  .workspace-title { font-size: 28px; }
  .mail-layout { grid-template-columns: minmax(0, 1fr); }
  .mail-folders, .mail-list-pane { border-right: 0; border-bottom: 1px solid var(--border); }
  .mail-layout.has-msg .mail-folders, .mail-layout.has-msg .mail-list-pane { display: none; }
  .mail-back { display: inline-flex; }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .actions { max-width: 100%; }
  .actions > button, .actions > .btn { max-width: 100%; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  body:not(.authenticated) { padding-bottom: 0; }
}
@media (max-width: 359px) {
  #shell-profile { display: none; }
  .shell-search input { font-size: 11px; }
  .shell-tools { gap: 2px; }
}

/* Desktop workspaces keep navigation and details visible while lists scroll. */
@media (min-width: 768px) {
  body.app-shell { height: 100dvh; min-height: 0; overflow: hidden; }
  .app-shell > main { min-height: 0; overflow: auto; }
  .app-shell .workspace-tasks, .app-shell .workspace-contacts, .app-shell .calendar-workspace { height: 100%; min-height: 0; }
  .app-shell .workspace-tasks { grid-template-columns: 200px minmax(0, 1fr); overflow: hidden; }
  .app-shell .workspace-tasks .workspace-sidebar, .app-shell .workspace-task-detail { min-height: 0; overflow: auto; }
  .app-shell .workspace-task-split { height: 100%; min-height: 0; }
  .app-shell .workspace-task-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: auto; }
  .app-shell .workspace-task-pane > :not(.workspace-task-list) { flex-shrink: 0; }
  .app-shell .workspace-task-list { flex: 1 0 8rem; min-height: 8rem; overflow: auto; }
  .app-shell .workspace-contacts { overflow: hidden; }
  .app-shell .workspace-contact-pane { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
  .app-shell .workspace-contact-pane > :not(.workspace-contact-list) { flex-shrink: 0; }
  .app-shell .workspace-contact-list { flex: 1 0 8rem; min-height: 8rem; overflow: auto; }
  .app-shell .workspace-contact-detail, .app-shell .calendar-sidebar, .app-shell .calendar-content { min-height: 0; overflow: auto; }
  .app-shell .mail-app { display: flex; flex-direction: column; height: 100%; min-height: 0; margin: 0; }
  .app-shell .mail-app > :not(.mail-layout) { flex-shrink: 0; margin: 6px 14px; }
  .app-shell .mail-layout { flex: 1; min-height: 0; overflow: hidden; align-items: stretch; }
  .app-shell .mail-folders, .app-shell .mail-list-pane, .app-shell .mail-detail { min-height: 0; overflow: auto; }
  .app-shell .mail-list-pane { display: flex; flex-direction: column; }
  .app-shell .mail-list-pane > :not(.mail-list) { flex-shrink: 0; }
  .app-shell .mail-list { flex: 1 0 8rem; min-height: 8rem; overflow: auto; }
}
@media (min-width: 768px) and (max-width: 1199px) {
  .app-shell .workspace-tasks .workspace-task-split { display: block; }
  .app-shell .workspace-task-detail { display: none; height: 100%; }
  .app-shell .workspace-task-split.has-detail .workspace-task-pane { display: none; }
  .app-shell .workspace-task-split.has-detail .workspace-task-detail { display: block; }
  .app-shell .workspace-tasks .workspace-back { display: inline-flex; }
  .app-shell .mail-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); overflow: hidden; }
  .app-shell .mail-folders { grid-column: 1; grid-row: 1; height: 100%; }
  .app-shell .mail-list-pane { grid-column: 2; grid-row: 1; height: 100%; overflow: auto; }
  .app-shell .mail-detail { display: none; }
  .app-shell .mail-layout.has-msg .mail-folders, .app-shell .mail-layout.has-msg .mail-list-pane { display: none; }
  .app-shell .mail-layout.has-msg .mail-detail { display: block; grid-column: 1 / -1; grid-row: 1; height: 100%; }
}
@media (min-width: 1200px) {
  .app-shell .workspace-tasks { grid-template-columns: 250px minmax(0, 1fr); }
}
.mail-filter-details { margin: 8px 0; color: var(--muted); font-size: 12px; }
.mail-filter-details > summary { cursor: pointer; }
.mail-filter-details .mail-filter-row { margin-top: 10px; }

.app-shell .mail-app > .messages:empty { display: none; }

@media (max-width: 359px) { .app-shell #context-nav { right: 0; } }

.shell-accounts .account-chip, .shell-login { min-height: 44px; display: inline-flex; align-items: center; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
