:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #2a2723;
  --muted: #7a736a;
  --line: #e2ddd5;
  --accent: #6b4f2e;
  --accent-text: #ffffff;
  --accent-soft: #efe6d9;
  --hover: #faf6ef;
  --danger: #b33a2b;
  --flag: #c0662a;
  --note: #fff6dd;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #26231f;
    --text: #ece7df;
    --muted: #a39b90;
    --line: #3a3530;
    --accent: #c79a62;
    --accent-text: #1c1a17;
    --accent-soft: #3a3024;
    --hover: #2e2a25;
    --danger: #e0705f;
    --flag: #e39a5c;
    --note: #332c1c;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
/* Kein Doppeltipp-Zoom auf Bedienelementen (iPhone) */
button, a, .btn, .msg, .folder, .cd, .ag-item, .trow, label { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.icon { padding: 7px 10px; min-width: 38px; }
.btn.wide { width: 100%; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ic.filled { fill: currentColor; }
.btn .ic { color: var(--accent); }
.btn.primary .ic { color: var(--accent-text); }
.btn.danger .ic { color: var(--danger); }
.btn.tb.on .ic { color: var(--flag); }
.msg .ic { width: 13px; height: 13px; vertical-align: -2px; }
.msg .flag .ic { color: var(--flag); }
.swipe-bg .ic { width: 22px; height: 22px; margin: 0 6px; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-height: 38px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > textarea, label > select { display: block; width: 100%; margin-top: 3px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.check input { min-height: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.login { max-width: 340px; margin: 10vh auto; }
.login .logo { display: block; width: 80%; margin: 0 auto 18px; }

/* Grundaufbau: Kopfzeile + drei Spalten */
#shell { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo-img { height: 38px; width: auto; display: block; }
.brand-sub { font-weight: 650; color: var(--muted); margin-right: 8px; }
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; }
#refreshBtn { margin-left: auto; }
.panes { flex: 1; display: grid; grid-template-columns: 230px minmax(300px, 400px) 1fr 280px; min-height: 0; }
body.no-agenda .panes { grid-template-columns: 230px minmax(300px, 400px) 1fr; }
body.no-agenda #agenda { display: none; }
#agenda { border-right: 0; border-left: 1px solid var(--line); padding: 0 0 12px; }
.ag-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ag-head h2 { margin: 0; font-size: 17px; }
.ag-head .ic, .mini-head .ic { width: 16px; height: 16px; }
.ag-empty { padding: 24px 14px; text-align: center; color: var(--muted); font-size: 14px; }
.mini { padding: 8px 10px 4px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; font-size: 14px; }
.mini-head .btn.icon { min-width: 30px; padding: 3px 6px; border: 0; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; }
.mini-grid span { color: var(--muted); padding: 2px 0; }
.cd { position: relative; border: 0; background: none; padding: 5px 0 7px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.cd:hover { background: var(--hover); }
.cd.other { color: var(--muted); opacity: .6; }
.cd.today { font-weight: 700; color: var(--accent); }
.cd.sel { background: var(--accent); color: var(--accent-text); }
.cd i { position: absolute; left: 50%; bottom: 2px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.cd.sel i { background: var(--accent-text); }
.ag-list { padding: 0 10px; }
.ag-day { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 12px 2px 4px; }
.ag-day.is-today { color: var(--accent); }
.ag-item { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; padding: 6px 8px; margin-bottom: 4px; border-radius: 6px; border-left: 3px solid var(--c); background: var(--hover); cursor: pointer; font-size: 13.5px; }
.ag-item:hover { background: var(--accent-soft); }
.ag-time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ag-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ag-loc { grid-column: 2; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-none { color: var(--muted); font-size: 13px; padding: 2px 2px 4px; }
.ev-desc { white-space: pre-wrap; font-size: 14px; background: var(--hover); padding: 8px 10px; border-radius: 6px; max-height: 40vh; overflow: auto; word-break: break-word; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; flex: none; }
.set-sec { font-weight: 650; margin: 14px 0 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.cal-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cal-row input { flex: 1; min-width: 0; }
.howto { padding-left: 18px; margin: 6px 0 10px; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.fields2 label { margin-bottom: 10px; }
.pane { min-height: 0; overflow: auto; border-right: 1px solid var(--line); }
#readPane { border-right: 0; overflow: auto; background: var(--surface); -webkit-overflow-scrolling: touch; }
#listPane { display: flex; flex-direction: column; overflow: hidden; background: var(--surface); }
#list { flex: 1; overflow: auto; outline: none; }
.only-mobile { display: none; }

/* Ordner */
#folders { padding: 10px 6px; }
.fsec { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.fsec:first-child { padding-top: 2px; }
.fsec .btn { text-transform: none; letter-spacing: 0; }
.folder { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; user-select: none; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent); color: var(--accent-text); }
.folder.active .count { color: var(--accent-text); }
.folder.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.folder .twisty { width: 14px; text-align: center; color: var(--muted); font-size: 11px; flex: none; }
.folder.active .twisty { color: var(--accent-text); }
.folder .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: 13px; font-weight: 650; color: var(--accent); }
.folder .more { visibility: hidden; border: 0; background: none; padding: 0 4px; cursor: pointer; color: inherit; }
.folder:hover .more { visibility: visible; }
.folder.noselect { cursor: default; color: var(--muted); }
.ferr { margin: 4px 8px; padding: 6px 8px; border-radius: 6px; background: var(--note); font-size: 13px; }

/* Liste */
.list-head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.list-head h2 { margin: 0; font-size: 17px; }
.msgwrap { position: relative; overflow: hidden; }
.swipe-bg { position: absolute; inset: 0; color: #fff; display: none; align-items: center; padding: 0 22px; font-weight: 650; opacity: .7; }
.swipe-bg.del { background: var(--danger); justify-content: flex-end; }
.swipe-bg.file { background: #6b4f2e; justify-content: flex-start; }
.msgwrap[data-dir=del] .swipe-bg.del, .msgwrap[data-dir=file] .swipe-bg.file { display: flex; }
.msgwrap.armed .swipe-bg { opacity: 1; }
.msg { position: relative; background: var(--surface); touch-action: pan-y; }
.msg.back { transition: transform .18s ease-out; }
.msg { display: grid; grid-template-columns: 10px 1fr auto; gap: 1px 8px; padding: 9px 14px 9px 8px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.msg:hover { background: var(--hover); }
.msg.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.msg .dot { grid-row: 1; width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; }
.msg.unseen .dot { background: var(--accent); }
.msg .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unseen .who, .msg.unseen .subj { font-weight: 650; }
.msg .when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.msg .subj { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.msg .icons { color: var(--muted); font-size: 13px; margin-left: 4px; }
.msg .flag { color: var(--flag); }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pager:empty { display: none; }

/* Lesebereich */
.read-actions { position: sticky; top: 0; z-index: 3; background: var(--surface); padding: 8px 18px; margin: 0; border-bottom: 1px solid var(--line); }
.read-head { padding: 12px 18px 10px; border-bottom: 1px solid var(--line); }
.meta .more-hint { display: none; }
.read-head h1 { font-size: 20px; margin: 0 0 8px; line-height: 1.3; word-break: break-word; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.meta { font-size: 14px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.meta .k { color: var(--muted); }
.meta .v { word-break: break-word; }
.meta .date { color: var(--muted); }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 14px; font-size: 13px; text-decoration: none; color: var(--text); max-width: 100%; }
.att:hover { border-color: var(--accent); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.thread summary { padding: 5px 10px; cursor: pointer; color: var(--muted); font-weight: 600; }
.thread[open] { max-height: 30vh; overflow: auto; }
.trow { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; padding: 5px 10px; border-top: 1px solid var(--line); cursor: pointer; }
.trow:hover { background: var(--hover); }
.trow.current { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); cursor: default; }
.trow.unseen .twho { font-weight: 650; }
.trow .tdate, .trow .tfolder { color: var(--muted); white-space: nowrap; }
.trow .twho { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner { margin: 10px 0 0; padding: 7px 10px; border-radius: 6px; background: var(--note); font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mailframe { display: block; width: 100%; border: 0; background: #fff; height: 300px; }
.placeholder { color: var(--muted); text-align: center; padding: 40px 20px; }

/* Dialoge */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(480px, calc(100vw - 24px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 18px; margin: 0; }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
dialog .buttons .left { margin-right: auto; }
.pick { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; }
.pick div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick div:last-child { border-bottom: 0; }
.pick div:hover, .pick div.hl { background: var(--accent-soft); }
.pick .sub { color: var(--muted); font-size: 13px; }
.pick .new { color: var(--accent); }

/* Schreiben */
dialog.compose { width: min(860px, calc(100vw - 24px)); height: min(820px, calc(100vh - 24px)); }
dialog.compose[open] { display: flex; }
dialog.compose form { flex: 1; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.cfield { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 8px; }
.cfield > span { color: var(--muted); font-size: 14px; }
.cfield input { width: 100%; }
.compose textarea { flex: 1; resize: none; width: 100%; min-height: 160px; font: 15px/1.5 system-ui, sans-serif; margin-top: 4px; }
.compose .from { font-size: 13px; color: var(--muted); }
.compose .files { display: flex; flex-wrap: wrap; gap: 6px; }
.compose .files .att button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 2px; }
.compose.dragover form { outline: 3px dashed var(--accent); outline-offset: -8px; }
.suggest { position: fixed; z-index: 100; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-height: 260px; overflow: auto; }
.suggest div { padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.suggest div.hl, .suggest div:hover { background: var(--accent-soft); }
.suggest .sub { color: var(--muted); font-size: 13px; margin-left: 6px; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 200; max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; }
#toast.show { opacity: 1; pointer-events: auto; }
#toast.err { background: var(--danger); color: #fff; }
#toast button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 5px; padding: 2px 8px; cursor: pointer; }

/* Mittelgroß: Ordnerspalte schmaler */
@media (max-width: 1100px) {
  .panes { grid-template-columns: 190px minmax(260px, 340px) 1fr 250px; }
  body.no-agenda .panes { grid-template-columns: 190px minmax(260px, 340px) 1fr; }
  .brand-sub { display: none; }
}
/* Handy: immer nur eine Spalte */
@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  /* iPhone zoomt bei Feldern unter 16 px automatisch hinein */
  input, select, textarea, .compose textarea { font-size: 16px; }
  html, body { overflow-x: hidden; }
  .hide-narrow, .brand { display: none; }
  .topbar { padding: 6px 8px; gap: 6px; }
  .panes { display: block; position: relative; }
  .pane { position: absolute; inset: 0; border: 0; display: none !important; }
  .panes[data-view=folders] #folders { display: block !important; }
  .panes[data-view=list] #listPane { display: flex !important; }
  .panes[data-view=read] #readPane, .panes[data-view=agenda] #agenda { display: block !important; }
  .cd { padding: 9px 0 11px; font-size: 14px; }
  .ag-item { font-size: 15px; padding: 9px 10px; }
  .folder { padding: 9px 10px; }
  .folder .more { visibility: visible; }
  .read-head { padding: 8px 12px; }
  .read-head h1 { font-size: 17px; margin-bottom: 4px; }
  /* Handy: Symbol mit kurzem Wort darunter, alle Knöpfe in einer Zeile */
  .read-actions { padding: 4px 2px; flex-wrap: nowrap; gap: 0; }
  .read-actions .btn.tb { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; padding: 5px 0 4px; border: 0; background: none; font-size: 11px; color: var(--text); }
  .read-actions .btn.tb .ic { width: 24px; height: 24px; }
  .read-actions .btn.tb .lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px; letter-spacing: -.1px; }
  .read-actions .btn.tb.danger { color: var(--danger); }
  .read-actions .btn.tb:active { background: var(--accent-soft); }
  .read-actions .desk { display: none; }
  .topbar .btn .ic { width: 22px; height: 22px; }
  .meta { font-size: 13px; cursor: pointer; }
  .meta .extra { display: none; }
  .meta.show-extra .extra { display: block; }
  .meta .more-hint { display: block; grid-column: 1 / 3; color: var(--accent); font-size: 12px; }
  .meta.show-extra .more-hint { visibility: hidden; height: 0; }
  .atts { margin-top: 6px; }
  dialog.compose { width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; border-radius: 0; }
}
