:root {
  --bg: #f2f5fa; --card: #ffffff; --text: #1b2230; --muted: #667085; --line: #e2e8f0; --hover: #f5f7fb;
  --primary: #2563eb; --primary-text: #fff; --primary-soft: #e6eefe; --primary-ink: #1d4ed8;
  --ok: #0f7b3e; --ok-bg: #e4f6ea; --err: #b42318; --err-bg: #fde8e6; --warn-bg: #fff4d6; --warn: #8a5a00;
  /* state colours: stripe/dot (--c-x), tinted badge background (--c-x-bg) and badge text (--c-x-ink) */
  --c-blue: #3b82f6;   --c-blue-bg: #e7efff;   --c-blue-ink: #1d4ed8;
  --c-green: #16a34a;  --c-green-bg: #e3f6e9;  --c-green-ink: #166534;
  --c-amber: #f59e0b;  --c-amber-bg: #fdf1d9;  --c-amber-ink: #92400e;
  --c-violet: #8b5cf6; --c-violet-bg: #efe9fe; --c-violet-ink: #6d28d9;
  --c-red: #ef4444;    --c-red-bg: #fde8e7;    --c-red-ink: #b91c1c;
  --c-grey: #a0aab8;   --c-grey-bg: #eef1f5;   --c-grey-ink: #556070;
  --r-sm: 8px; --r: 10px; --r-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 16px -4px rgba(16, 24, 40, .12), 0 2px 4px rgba(16, 24, 40, .06);
  --av-l-bg: 90%; --av-s-bg: 70%; --av-l-ink: 30%; --av-s-ink: 45%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e131c; --card: #171f2d; --text: #e6e9ef; --muted: #9aa6ba; --line: #263247; --hover: #1d2738;
          --primary: #3b82f6; --primary-soft: #1a2b4a; --primary-ink: #a5c4ff;
          --ok-bg: #11301d; --ok: #7ad29a; --err-bg: #3a1613; --err: #f3a39a; --warn-bg: #3a2d0b; --warn: #f1c565;
          --c-blue: #60a5fa;   --c-blue-bg: #172a4a;   --c-blue-ink: #a5c8ff;
          --c-green: #4ade80;  --c-green-bg: #12301f;  --c-green-ink: #8fe5ae;
          --c-amber: #fbbf24;  --c-amber-bg: #3a2a0c;  --c-amber-ink: #fcd36a;
          --c-violet: #a78bfa; --c-violet-bg: #2a2049; --c-violet-ink: #cbbcfd;
          --c-red: #f87171;    --c-red-bg: #3a1716;    --c-red-ink: #fca5a5;
          --c-grey: #6b7689;   --c-grey-bg: #232c3c;   --c-grey-ink: #a7b0c0;
          --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
          --shadow-md: 0 8px 20px -6px rgba(0, 0, 0, .6), 0 2px 4px rgba(0, 0, 0, .3);
          --av-l-bg: 27%; --av-s-bg: 32%; --av-l-ink: 84%; --av-s-ink: 70%;
          color-scheme: dark; }
}
.tone-blue   { --tone: var(--c-blue);   --tone-bg: var(--c-blue-bg);   --tone-ink: var(--c-blue-ink); }
.tone-green  { --tone: var(--c-green);  --tone-bg: var(--c-green-bg);  --tone-ink: var(--c-green-ink); }
.tone-amber  { --tone: var(--c-amber);  --tone-bg: var(--c-amber-bg);  --tone-ink: var(--c-amber-ink); }
.tone-violet { --tone: var(--c-violet); --tone-bg: var(--c-violet-bg); --tone-ink: var(--c-violet-ink); }
.tone-red    { --tone: var(--c-red);    --tone-bg: var(--c-red-bg);    --tone-ink: var(--c-red-ink); }
.tone-grey   { --tone: var(--c-grey);   --tone-bg: var(--c-grey-bg);   --tone-ink: var(--c-grey-ink); }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
a { color: var(--primary); }
header.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 17px; }
nav a { margin-right: 16px; text-decoration: none; color: var(--muted); padding: 4px 10px; border-radius: 999px; }
nav a:hover { color: var(--text); background: var(--hover); }
nav a.active { color: var(--primary-ink); background: var(--primary-soft); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
h2 { font-size: 18px; margin: 0 0 10px; }
section, details.account { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
details.account > summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; list-style: none; }
details.account > summary::-webkit-details-marker { display: none; }
.acc-name { font-weight: 700; font-size: 16px; }
.acc-mail { color: var(--muted); }
.overview-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.count { display: inline-block; background: var(--err-bg); color: var(--err); border-radius: 999px; padding: 0 9px; font-size: 13px; margin-left: 6px; }
.open-list { margin: 0; padding-left: 18px; }
.open-list > li { margin-bottom: 8px; }
.open-list ul { margin: 2px 0 0; padding-left: 16px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 8px 0 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 18px; padding: 1px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
/* state badge and tinted badges take the colour of the nearest tone-* class */
.badge.st, .badge.tint { background: var(--tone-bg, var(--bg)); color: var(--tone-ink, var(--text)); border-color: transparent; font-weight: 600; }
.badge.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--tone, var(--muted)); flex: none; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.cat { background: var(--bg); color: var(--muted); border-color: var(--line); }
.badge.conf.good { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.conf.mid { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.conf.low { background: var(--err-bg); color: var(--err); border-color: transparent; }
.card { border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; margin-top: 12px; background: var(--bg); box-shadow: var(--shadow-sm); }
.card.gone { border-left: 4px solid var(--ok); }
.card header { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card .subject { font-weight: 600; margin-top: 2px; }
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.summary { margin: 10px 0 6px; }
.questions, .points { margin: 6px 0; padding-left: 18px; font-size: 14px; }
.questions .basis { font-size: 12.5px; }
details.orig { margin: 6px 0; font-size: 13px; }
details.orig > summary { cursor: pointer; color: var(--muted); }
details.orig pre { white-space: pre-wrap; background: var(--bg); padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--line); max-height: 300px; overflow: auto; }
form.draft label { display: block; margin-top: 10px; font-size: 13px; color: var(--muted); }
form.draft input[type=text], form.draft textarea, .grid input, .grid select, .grid textarea, input[type=email], #push-name {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); color: var(--text); font: inherit; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
form.draft textarea { font-family: inherit; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.actions { padding-top: 10px; border-top: 1px dashed var(--line); }
.test-group { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 280px; }
.test-group input { flex: 1; }
.row input[name=hint] { flex: 1; min-width: 240px; }
button, .button { font: inherit; padding: 8px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; box-shadow: var(--shadow-sm); transition: filter .15s, background-color .15s; }
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; font-weight: 600; }
button.secondary { border-color: var(--primary); color: var(--primary); }
button.small { padding: 5px 12px; font-size: 13px; }
button.ghost { background: transparent; box-shadow: none; }
button.ghost:hover { background: var(--hover); }
button.danger { color: var(--err); border-color: var(--err); }
button:hover { filter: brightness(.95); }
.flash { padding: 8px 12px; border-radius: var(--r); margin: 8px 0; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.saved { color: var(--ok); font-size: 13px; }
.working { animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.actions-cell form { display: inline-block; margin: 2px 2px 2px 0; }
form.inline { display: inline; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px 20px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid label.check { flex-direction: row; align-items: center; color: var(--text); }
.grid .wide, .grid .row { grid-column: 1 / -1; }
.folders { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; margin-top: 8px; }
.folders label { color: var(--text); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
progress { width: 160px; }
section.empty { text-align: center; padding: 40px 20px; }
@media (max-width: 640px) { header.top { padding: 10px 16px; gap: 12px; } nav a { margin-right: 10px; } }
.grid input[type=checkbox], form.draft input[type=checkbox] { width: auto; margin: 0; }
.grid label.check { justify-content: flex-start; gap: 8px; }

/* ---- three-pane dashboard ---- */
.layout { display: grid; grid-template-columns: 236px minmax(320px, 1fr) minmax(380px, 1.3fr); gap: 16px; align-items: start; }
#sidebar { position: sticky; top: 72px; }
.side-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 8px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.side-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 8px 6px; }
.side-item { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 7px 10px; border-radius: var(--r); color: var(--text); text-decoration: none; font-size: 14px; }
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.side-item.active .pill { background: var(--card); color: inherit; border-color: transparent; }
.side-item.active .side-sub { color: inherit; opacity: .85; }
.side-label { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.side-name { font-weight: 600; }
.side-sub { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.pills { display: flex; gap: 4px; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.pill.tint { background: var(--tone-bg); color: var(--tone-ink); border-color: transparent; font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--muted)); flex: none; }
.dot.tone-all { background: transparent; box-shadow: inset 0 0 0 2px var(--muted); }
.legend ul { list-style: none; margin: 0; padding: 0 8px 4px; display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .legend-hint { padding: 6px 8px 2px; }
.wide-btn { width: 100%; }
#list-pane, #detail-pane { min-width: 0; }
#list-pane, #detail-pane { background: transparent; border: 0; padding: 0; margin-bottom: 0; box-shadow: none; border-radius: 0; }
.group + .group { margin-top: 18px; }
.list-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 0 6px 12px; }
.group-head { display: flex; gap: 8px; align-items: baseline; padding: 2px 6px 8px; font-weight: 600; font-size: 13px; min-width: 0; }
.group-mail { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.group-head .pill { margin-left: auto; }

/* ---- mail rows: rounded cards with a colour stripe, swipeable ---- */
.mail { position: relative; margin-bottom: 8px; border-radius: var(--r-lg); cursor: pointer; touch-action: pan-y; overflow: hidden;
        box-shadow: var(--shadow-sm); transition: box-shadow .15s, transform .15s; }
.mail-card { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px 12px 18px;
             background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); transition: transform .22s ease; }
.mail-card::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--tone); }
@media (hover: hover) {
  .mail:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
}
.mail.selected { box-shadow: 0 0 0 2px var(--primary), var(--shadow-md); }
.mail.selected .mail-card { border-color: transparent; }
.mail.state-generating .mail-card::before, .mail.state-generating .badge.st::before { animation: pulse 1.4s ease-in-out infinite; }
.mail.state-no_reply .mail-card > * { opacity: .8; }
.mail.state-sent .mail-card > *, .mail.state-ignored .mail-card > *, .mail.state-answered_externally .mail-card > *, .mail.state-forwarded .mail-card > * { opacity: .6; }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px;
          font-size: 13px; font-weight: 600; letter-spacing: .02em; user-select: none;
          background: hsl(var(--h, 220) var(--av-s-bg) var(--av-l-bg)); color: hsl(var(--h, 220) var(--av-s-ink) var(--av-l-ink)); }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-from { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-date { white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.row-subject { font-size: 14px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-summary { font-size: 13px; margin-top: 2px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-badges { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.row-questions { margin: 6px 0 0; padding-left: 16px; font-size: 12px; color: var(--c-amber-ink); }
/* what a swipe reveals underneath the card */
.swipe-under { position: absolute; inset: 0; border-radius: var(--r-lg); display: flex; align-items: center; justify-content: space-between;
               padding: 0 20px; font-size: 13px; font-weight: 600; color: #fff; opacity: 0; pointer-events: none; }
.swipe-under span { display: inline-flex; align-items: center; gap: 8px; opacity: 0; transition: transform .15s; }
.mail.reveal-open .swipe-under { opacity: 1; background: var(--primary); }
.mail.reveal-open .su-open { opacity: 1; }
.mail.reveal-archive .swipe-under { opacity: 1; background: #6b7484; }
.mail.reveal-archive .su-archive { opacity: 1; }
.mail.armed .swipe-under span { transform: scale(1.08); }
.mail.reveal-archive.armed .swipe-under { background: #4b5463; }
.mail.swiping { box-shadow: none; transform: none; user-select: none; -webkit-user-select: none; }
.mail.swiping .mail-card { transition: none; }
/* ---- rows leaving the list (app/static/motion.js animates them; these are the static states) ---- */
.mail.leaving { pointer-events: none; box-shadow: none; transform: none; transition: none; }
.mail.leaving .mail-card { transition: none; }
.mail.left, .group.left { display: none; }
.leave-cue { position: absolute; inset: -1px; z-index: 1; border-radius: inherit; display: flex; align-items: center; justify-content: center; gap: 8px;
             background: var(--tone-bg); color: var(--tone-ink); font-size: 14px; font-weight: 600; opacity: 0; }
/* empty view after the last mail is handled (list and detail) */
.all-done { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 36px 16px; text-align: center; }
.all-done svg { color: var(--c-green); margin-bottom: 4px; }
.all-done:focus { outline: none; }
.all-done.enter { animation: done-in .38s cubic-bezier(.2, 0, 0, 1) both; }
.all-done.enter svg { animation: done-pop .42s cubic-bezier(.2, 0, 0, 1.3) .08s both; }
@keyframes done-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes done-pop { from { opacity: 0; transform: scale(.6); } }
#detail .card:focus { outline: none; }
@media (prefers-color-scheme: dark) {
  .mail.reveal-archive .swipe-under { background: #3c4556; }
  .mail.reveal-archive.armed .swipe-under { background: #4d5869; }
}
#detail-pane { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; padding: 2px 4px 16px; }
#detail .card { margin-top: 0; background: var(--card); box-shadow: var(--shadow-md); }
.card-account { font-size: 12px; margin-bottom: 6px; }
.placeholder { padding: 30px 16px; text-align: center; }
.back-btn { display: none; }
.card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr; }
  /* detail becomes a full-screen overlay that slides in when a mail is tapped */
  #detail-pane { position: fixed; inset: 0; top: 0; z-index: 20; max-height: none; background: var(--bg); padding: 12px 12px 40px;
                 overflow: auto; transform: translateX(100%); transition: transform .2s ease; }
  body.detail-open #detail-pane { transform: translateX(0); }
  body.detail-open { overflow: hidden; }
  .back-btn { display: inline-block; }
}
@media (max-width: 700px) {
  main { padding: 10px 10px 40px; }
  header.top { padding: 8px 12px; }
  .brand { font-size: 15px; }
  nav a { font-size: 14px; }
  .layout { grid-template-columns: 1fr; gap: 10px; }
  #sidebar { position: static; }
  .side-block { display: flex; overflow-x: auto; gap: 6px; padding: 6px; -webkit-overflow-scrolling: touch; }
  .side-title { display: none; }
  .side-item { white-space: nowrap; flex: 0 0 auto; border: 1px solid var(--line); gap: 6px; padding: 6px 10px; }
  .side-sub { display: none; }
  .wide-btn { width: auto; }
  .mail-card { padding: 10px 12px 10px 16px; gap: 10px; }
  .avatar { width: 30px; height: 30px; font-size: 12px; }
  .row-summary { -webkit-line-clamp: 1; }
  .legend { display: none; }
  .card { padding: 12px; }
  form.draft textarea { font-size: 16px; }   /* prevents iOS zoom on focus */
  form.draft input[type=text], input[type=email] { font-size: 16px; }
  .row.actions { flex-direction: column; align-items: stretch; }
  .row.actions .primary, .test-group { width: 100%; }
}
#sidebar, .side-block, #list-pane, #list, .group, .mail { min-width: 0; }
.layout { max-width: 100%; }
@media (max-width: 1100px) { #detail-pane { left: 0; right: 0; width: 100vw; box-sizing: border-box; } }
.brand { white-space: nowrap; }
header.top nav { display: flex; gap: 12px; flex-wrap: wrap; }
header.top nav a { margin-right: 0; }
@media (max-width: 700px) {
  /* nav becomes a scrollable strip under brand + user instead of a tall column */
  header.top { flex-wrap: wrap; row-gap: 6px; }
  /* all entries visible: the strip wraps into a second row instead of cutting „Benutzer“ off */
  header.top nav { order: 3; flex: 1 1 100%; flex-wrap: wrap; gap: 4px; }
  header.top nav a { padding: 4px 10px; white-space: nowrap; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
}

.auth-box { max-width: 440px; margin: 40px auto; }
.grid.one-col { grid-template-columns: 1fr; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.who a { color: var(--text); text-decoration: none; font-weight: 600; }

pre.log { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; font-size: 12px; max-height: 360px; overflow: auto; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.tile { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px; }
.tile-n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.tile-l { font-size: 13px; margin-top: 4px; }
/* wide tables scroll inside their own box, never the page (phones) */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 100%; }
@media (max-width: 700px) { main, section, .card { min-width: 0; } }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.side-alert.llm-down { margin: 0 0 12px; background: var(--warn-bg); color: var(--warn); font-size: 13px; line-height: 1.4; }
/* desktop sidebar: a long label wraps inside itself, its count stays on the same line */
@media (min-width: 701px) {
  .side-item > .side-label, .side-item > .side-name { flex: 1 1 0; min-width: 0; }
  .side-item > .pill, .side-item > .pills { flex: none; margin-left: auto; }
  .side-item { column-gap: 6px; }
  .side-item .pill { padding: 1px 6px; min-width: 20px; }
}
.inline-label { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.inline-label select { padding: 4px 10px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card); color: var(--text); }

.row-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { padding: 5px; border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: var(--r-sm); line-height: 0; cursor: pointer; box-shadow: none; }
.icon-btn:hover { color: var(--text); border-color: var(--line); background: var(--card); }

.badge.cc { background: transparent; color: var(--text); border: 1px dashed var(--muted); }

.invoice-box { border: 1px dashed var(--line); border-radius: var(--r); padding: 10px; }
.invoice-action { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }

.row-forward { padding: 3px 10px; font-size: 12px; border-radius: 999px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(680px, 92vw); padding: 10px 18px; border-radius: var(--r-lg);
         box-shadow: 0 10px 30px rgba(0,0,0,.18); z-index: 50; font-size: 14px; background: var(--ok-bg); color: var(--ok); border: 1px solid var(--line); }
.toast.err { background: var(--err-bg); color: var(--err); }
ol.steps { padding-left: 20px; }
ol.steps > li { margin-bottom: 14px; line-height: 1.6; }
.code-box { margin-top: 10px; padding: 10px; border: 1px dashed var(--primary); border-radius: var(--r); }
.code-box textarea { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* ---- open-mail counter (sidebar) ---- */
.open-counter { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.open-n { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; color: var(--primary); }
.open-l { font-weight: 600; font-size: 14px; }
.open-l .side-sub { font-weight: 400; margin-top: 2px; }
@media (max-width: 700px) {
  .open-counter { padding: 8px 12px; }
  .open-n { font-size: 24px; }
  .open-counter .side-sub { display: block; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .mail:hover { transform: none; }
}

/* ---- account form: provider presets and sign-in ---- */
[hidden] { display: none !important; }
.provider-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.provider-hint { margin-top: 10px; padding: 9px 12px; border-radius: var(--r); background: var(--primary-soft); color: var(--text); font-size: 14px; line-height: 1.5; }
.provider-hint.warn { background: var(--warn-bg); color: var(--warn); }
.provider-hint a { white-space: nowrap; font-weight: 600; }
.auth-choice { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.auth-choice legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; float: left; width: 100%; }
.grid .auth-choice label.opt { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); cursor: pointer; }
.grid .auth-choice label.opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.grid .auth-choice input[type=radio] { width: auto; margin: 0; accent-color: var(--primary); }
.oauth-box { border: 1px dashed var(--primary); border-radius: var(--r); padding: 10px 12px; }
.oauth-box p { margin: 4px 0; }
.oauth-ok { color: var(--ok); }
.server-box { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: var(--card); }
.server-box > summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.server-box > summary .muted { font-weight: 400; margin-left: 6px; overflow-wrap: anywhere; }
.server-box[open] > summary { margin-bottom: 10px; }
.copy-field { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.copy-field code { font-size: 13px; padding: 4px 8px; overflow-wrap: anywhere; }
ol.setup-steps { padding-left: 20px; margin: 6px 0; font-size: 14px; line-height: 1.55; }
ol.setup-steps li { margin-bottom: 4px; }
details.oauth-provider { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-top: 12px; }
details.oauth-provider > summary { cursor: pointer; font-weight: 600; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.side-alert { display: block; margin: 2px 8px 6px; padding: 6px 10px; border-radius: var(--r-sm); background: var(--err-bg); color: var(--err); font-size: 12px; text-decoration: none; font-weight: 600; }
.side-alert:hover { filter: brightness(.97); }
.status-err { color: var(--err); font-weight: 600; }

/* ---- knowledge documents (account page) ---- */
section.docs { margin-top: 24px; }
.docs-hint { margin: 0 0 12px; padding: 9px 12px; border-radius: var(--r); background: var(--primary-soft); font-size: 14px; line-height: 1.5; }
.drop-zone { position: relative; border: 2px dashed var(--line); border-radius: var(--r-lg); background: var(--bg); transition: border-color .15s, background-color .15s; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.drop-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.drop-input:focus-visible + .drop-inner { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--r-lg); }
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 16px; text-align: center; cursor: pointer; }
.drop-icon { color: var(--primary); }
.drop-title { font-weight: 600; }
.drop-title u { color: var(--primary); text-underline-offset: 3px; }
.drop-busy { color: var(--primary-ink); font-weight: 600; }
.drop-zone.htmx-request { border-color: var(--primary); }
.doc-list { margin-top: 12px; }
.doc-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.doc { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px 12px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.doc::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--tone); }
.doc-type { flex: none; min-width: 42px; padding: 7px 4px; border-radius: var(--r-sm); background: var(--tone-bg); color: var(--tone-ink); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-align: center; }
.doc-main { flex: 1; min-width: 0; }
.doc-title { font-weight: 650; overflow-wrap: anywhere; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 2px 0; margin-top: 1px; }
.doc-meta span { overflow-wrap: anywhere; }
.doc-meta span:not(:last-child)::after { content: "·"; margin: 0 6px; }
.doc-status { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 6px; }
.doc-error { margin: 6px 0 0; color: var(--err); }
.doc-waiting_llm .doc-error, .doc-no_text .doc-error { color: var(--warn); }
.doc-actions { flex: none; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.doc-actions .button, .doc-actions button { white-space: nowrap; }
.button.small { padding: 5px 12px; font-size: 13px; }
.button.ghost { background: transparent; box-shadow: none; }
.button.ghost:hover { background: var(--hover); }
.doc-empty { padding: 14px; text-align: center; border: 1px dashed var(--line); border-radius: var(--r-lg); }
@media (max-width: 700px) {
  .doc { flex-wrap: wrap; padding: 12px 12px 12px 16px; }
  .doc-actions { flex-basis: 100%; justify-content: flex-start; gap: 6px; }
  .doc-actions .button.small, .doc-actions button.small { padding: 5px 10px; }
  .drop-desktop { display: none; }
}
@media (hover: none) { .drop-desktop { display: none; } }
/* templates to fill in (account page, knowledge documents) */
details.templates { margin: 0 0 12px; border: 1px solid var(--line); border-radius: var(--r); padding: 9px 12px; background: var(--card); }
details.templates > summary { cursor: pointer; font-weight: 600; }
details.templates[open] > summary { margin-bottom: 8px; }
.templates-hint { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }
.template-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.template-list li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); min-width: 0; }
.template-list .doc-type { --tone-bg: var(--c-blue-bg); --tone-ink: var(--c-blue-ink); min-width: 40px; padding: 4px; }
.template-list a { overflow-wrap: anywhere; text-decoration: none; color: var(--text); font-size: 14px; }
.template-list a:hover { text-decoration: underline; }
.template-files { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.template-files a { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--primary-ink); }
.templates-all { margin-top: 10px; }

/* ---- attachments of a reply (detail view): knowledge documents as chips ---- */
fieldset.attach { margin: 12px 0 0; padding: 8px 10px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); min-width: 0; }
fieldset.attach legend { padding: 0 4px; font-size: 13px; color: var(--text); font-weight: 600; }
.attach-hint { margin: -2px 0 8px; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chips:empty { display: none; }
form.draft label.attach-chip { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px 4px 8px; max-width: 100%;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer; }
form.draft label.attach-chip:has(input:checked) { border-color: var(--c-green); background: var(--c-green-bg); }
.attach-chip input { accent-color: var(--c-green); }
.attach-type { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 5px; border-radius: 6px; background: var(--c-grey-bg); color: var(--c-grey-ink); }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attach-size { font-size: 12px; white-space: nowrap; }
.attach-tag { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-ink); white-space: nowrap; }
.attach-empty { margin: 0; }
select.attach-pick { margin-top: 8px; max-width: 100%; padding: 5px 10px; border: 1px dashed var(--line); border-radius: var(--r); background: var(--card); color: var(--primary-ink); font: inherit; font-size: 13px; }

/* ---- sources of a draft (detail view) ---- */
.sources { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.sources li { display: flex; gap: 8px; align-items: baseline; }
.src-id { flex: none; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: var(--c-grey-bg); color: var(--c-grey-ink); }
.src-doc .src-id { background: var(--c-green-bg); color: var(--c-green-ink); }
.src-used { font-weight: 600; }
.sources a { overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }

/* shared mailboxes: soft lock, assignment, members (app/team.py, app/access.py) */
.team-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 8px 0 10px; padding: 8px 10px;
            background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); }
.claim-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 260px; min-width: 0; }
.team-row form.assign { margin: 0; flex: 0 1 auto; }
.team-row select { max-width: 100%; font: inherit; font-size: 13px; padding: 5px 8px; border-radius: var(--r-sm);
                   border: 1px solid var(--line); background: var(--card); color: var(--text); }
.team-row select.assigned { border-color: var(--c-blue); color: var(--c-blue-ink); background: var(--c-blue-bg); font-weight: 600; }
.badge.assignee { background: var(--bg); color: var(--text); border-color: var(--line); }
.badge.assignee.mine { background: var(--c-blue-bg); color: var(--c-blue-ink); border-color: transparent; font-weight: 600; }
.badge.handled-by { background: transparent; color: var(--muted); border-color: var(--line); }
.claim-badge { white-space: normal; }
.shared-mark { color: var(--muted); font-size: 12px; font-weight: 400; }
.sender-note { margin: 2px 0 6px; }
.member-list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--r); flex-wrap: wrap; }
.member-list .member-name { flex: 1 1 140px; min-width: 0; overflow-wrap: anywhere; }
.avatar.small { width: 28px; height: 28px; font-size: 11px; margin-top: 0; }
.member-add { gap: 8px; flex-wrap: wrap; }
.member-add .grow { flex: 1 1 200px; }
.member-add input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card);
                    color: var(--text); font: inherit; }
.member-chip { display: inline-flex; align-items: center; gap: 2px; margin: 0 6px 4px 0; padding: 0 0 0 8px; border: 1px solid var(--line); border-radius: 999px; }
@media (max-width: 700px) {
  .team-row { padding: 8px; }
  .team-row form.assign, .team-row select { width: 100%; }
  .team-row select, .member-add input { font-size: 16px; }   /* prevents iOS zoom on focus */
}
/* ---- Regiondo panel and inquiry data (detail view, read-only) ---- */
.regiondo-slot:empty { display: none; }
.rg-loading { margin: 6px 0; }
details.regiondo { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; background: var(--card); }
details.regiondo > summary { font-weight: 600; color: var(--text); }
details.regiondo > summary::marker { color: var(--muted); }
.rg-body { display: grid; gap: 10px; margin-top: 8px; min-width: 0; }
.rg-box { border-top: 1px solid var(--line); padding-top: 8px; min-width: 0; }
.rg-box:first-child { border-top: 0; padding-top: 0; }
.rg-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 6px; }
.rg-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; margin: 0; }
.rg-fields div { min-width: 0; }
.rg-fields dt { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.rg-fields dd { margin: 0; overflow-wrap: anywhere; }
.rg-actions { margin-top: 8px; gap: 6px; }
.rg-bookings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rg-bookings li { padding: 6px 10px; border-radius: var(--r-sm); background: var(--bg); min-width: 0; }
.rg-line1 { overflow-wrap: anywhere; }
.rg-line2 { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; margin-top: 2px; }
.rg-product { margin-bottom: 8px; overflow-wrap: anywhere; }
.rg-day { display: flex; gap: 8px; align-items: baseline; margin-top: 4px; }
.rg-daylabel { flex: none; min-width: 5.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.rg-daylabel.rg-wanted { color: var(--text); font-weight: 650; }
.rg-slots { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.rg-slot { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--c-green-bg); color: var(--c-green-ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.flash.small { padding: 6px 10px; font-size: 13px; }

/* ---- urgent mails: red badge with the reason as tooltip, red stripe, note in the detail view ---- */
.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; }
.badge.urgent { background: var(--c-red); color: #fff; border-color: transparent; font-weight: 650; gap: 4px; cursor: help; }
.mail.urgent .mail-card::before { background: var(--c-red); width: 5px; }
.mail.urgent .mail-card { border-color: color-mix(in srgb, var(--c-red) 35%, var(--line)); }
.urgent-note { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 10px 0;
               padding: 8px 12px; border-radius: var(--r); background: var(--c-red-bg); color: var(--c-red-ink); }
.urgent-note svg { vertical-align: -1px; }
.urgent-note .muted { color: inherit; opacity: .75; }
.side-alert.urgent-alert { display: flex; align-items: center; gap: 6px; margin: 0 0 12px; font-size: 13px; }

/* ---- push notifications (profile) ---- */
.push-hint { padding: 10px 12px; border-radius: var(--r); background: var(--warn-bg); color: var(--warn); margin: 10px 0; }
.push-hint ol { margin: 6px 0 0; padding-left: 20px; }
.push-hint li { margin-bottom: 3px; }
.push-prefs { display: grid; gap: 8px; margin-top: 12px; }
.push-prefs label { display: flex; gap: 8px; align-items: flex-start; }
.push-prefs input[type=checkbox], .push-prefs input[type=radio] { margin-top: 4px; }
.push-status { margin-top: 8px; }
.push-times { gap: 6px; margin-top: 0; }
.push-times input[type=time] { width: auto; }
.badge.urgent.legend-urgent { padding: 0 5px; font-size: 10px; line-height: 13px; cursor: default; }

/* ---- foreign-language mails: language badge, German translation of mail and draft ---- */
.badge.lang { background: var(--c-violet-bg); color: var(--c-violet-ink); border-color: transparent; font-weight: 700; letter-spacing: .04em; }
.mail-translation { margin: 6px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mail-translation > .translation { flex-basis: 100%; }
.translation { border-left: 3px solid var(--c-violet); background: var(--card); border-radius: 0 var(--r) var(--r) 0; padding: 8px 12px; margin: 8px 0 4px; font-size: 13px; }
.translation-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.translation pre { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 6px 0 0; max-height: 320px; overflow: auto; }
.translation .row { margin-top: 6px; }
form.draft .draft-translation { margin-top: 4px; }

/* ---- knowledge gaps page ---- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.gaps-title { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.gaps-title h2, .gaps-title h3 { margin: 0; }
.gaps-filter { display: flex; flex-wrap: wrap; gap: 8px; }
.gaps-filter select { font: inherit; font-size: 14px; padding: 6px 10px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); color: var(--text); max-width: 100%; }
.gaps-account { margin: 2px 0 8px; font-size: 14px; overflow-wrap: anywhere; }
.gaps-intro { margin: 0 0 12px; font-size: 14px; max-width: 75ch; }
.gaps-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.gaps-stats > div { background: var(--bg); border-radius: var(--r); padding: 8px 12px; display: flex; flex-direction: column; }
.gaps-stats b { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.gaps-stats span { font-size: 12px; color: var(--muted); }
.gaps-week { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--warn-bg); max-width: 75ch; }
.gaps-week h3 { margin: 0 0 6px; font-size: 15px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.gaps-week-box + .gaps-week-box { margin-top: 6px; }
.gaps-week-acc { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.gaps-week ul { margin: 2px 0 0; padding-left: 20px; font-size: 14px; }
.gaps-week li { overflow-wrap: anywhere; }
.gaps-h { margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.gap { position: relative; display: flex; gap: 14px; align-items: flex-start; padding: 12px 14px 12px 18px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--card); margin-bottom: 8px; }
.gap::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--tone); }
.gap-count { flex: none; min-width: 52px; text-align: center; padding: 6px 4px; border-radius: var(--r-sm); background: var(--tone-bg); color: var(--tone-ink); display: flex; flex-direction: column; line-height: 1.15; }
.gap-count b { font-size: 20px; font-variant-numeric: tabular-nums; }
.gap-count span { font-size: 11px; }
.gap-main { flex: 1; min-width: 0; }
.gap-q { font-weight: 650; overflow-wrap: anywhere; }
.gap-also { margin-top: 2px; overflow-wrap: anywhere; }
.gap-covered { margin: 6px 0 0; color: var(--ok); }
.gap-mails { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; display: grid; gap: 2px; }
.gap-mails li { overflow-wrap: anywhere; }
.gap-answer { margin: 6px 0; padding: 6px 10px; border-left: 3px solid var(--c-blue); background: var(--bg); border-radius: 0 var(--r-sm) var(--r-sm) 0; white-space: pre-wrap; font-size: 14px; }
.gap-answer-text { margin: 4px 0; white-space: pre-wrap; font-size: 14px; }
.gap-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; margin-top: 8px; }
.gap-save { margin-top: 8px; }
.gap-actions .gap-save { margin-top: 0; }
.gap-save[open] { flex-basis: 100%; }
.gap-save > summary { list-style: none; cursor: pointer; display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gap-save > summary::-webkit-details-marker { display: none; }
.gap-save[open] > summary .button { filter: brightness(.92); }
.faq-form { display: grid; gap: 8px; margin-top: 10px; padding: 12px; background: var(--bg); border-radius: var(--r); border: 1px solid var(--line); }
.faq-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.faq-form input[type=text], .faq-form textarea { width: 100%; box-sizing: border-box; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); color: var(--text); font: inherit; resize: vertical; }
.faq-form .row { margin-top: 0; }
.pii-hint { margin: 0; padding: 6px 10px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn); }
label.check { display: inline-flex; gap: 8px; align-items: center; }
@media (max-width: 700px) {
  .gaps-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gap { padding: 12px 12px 12px 16px; gap: 10px; }
  .gap-count { min-width: 44px; }
  .gaps-filter, .gaps-filter select { width: 100%; }
}

/* ---- search (app/search): box above the list, results replace the list ---- */
.layout { grid-template-rows: auto 1fr; }   /* the tall sidebar's extra height goes to the list row, not under the box */
.layout > #search-form { grid-column: 2; grid-row: 1; }
.layout > #sidebar { grid-column: 1; grid-row: 1 / span 2; }
.layout > #list-pane { grid-column: 2; grid-row: 2; }
.layout > #detail-pane { grid-column: 3; grid-row: 1 / span 2; }
@media (max-width: 1100px) { .layout > #detail-pane { grid-column: auto; grid-row: auto; } }
@media (max-width: 700px) {
  .layout > #search-form, .layout > #sidebar, .layout > #list-pane { grid-column: 1; grid-row: auto; }
}
.search { min-width: 0; }
.search-box { position: relative; display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line);
              border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 4px 6px 4px 12px; transition: border-color .15s, box-shadow .15s; }
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-icon { flex: none; color: var(--muted); }
.search-box input[type=search] { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font: inherit;
                                 padding: 7px 4px; box-shadow: none; }
.search-box input[type=search]:focus-visible { box-shadow: none; }
.search-box input[type=search]::placeholder { color: var(--muted); opacity: .9; }
.search-kbd { flex: none; font: 600 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); border: 1px solid var(--line);
              border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; background: var(--bg); }
.search-box:focus-within .search-kbd { display: none; }
.search-filter-toggle { display: none; flex: none; }
.search-filter-toggle .pill { margin-left: 4px; }
.search-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 2px 0; font-size: 13px; }
select.sf, input.sf { font: inherit; font-size: 13px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line);
                      background: var(--card); color: var(--text); min-width: 0; max-width: 100%; }
select.sf.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
input.sf[type=date] { width: 9.4em; padding: 3px 8px; }
.sf-dates { display: inline-flex; align-items: center; gap: 4px; }
.sf-dates[hidden] { display: none; }
.sf-check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; padding: 0 4px; }
.sf-check input { margin: 0; }
@media (max-width: 700px) {
  .search-kbd { display: none; }
  .search-filter-toggle { display: inline-block; }
  .search-filters { display: none; }
  .search.filters-open .search-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 0 2px; }
  .search.filters-open .sf { font-size: 16px; width: 100%; box-sizing: border-box; padding: 6px 10px; }
  .search.filters-open .sf-dates { grid-column: 1 / -1; }
  .search.filters-open .sf-dates[hidden] { display: none; }
  .search.filters-open .sf-dates input.sf { flex: 1; width: auto; }
  .search.filters-open .sf-check { font-size: 15px; }
  .search-box input[type=search] { font-size: 16px; }   /* prevents iOS zoom on focus */
}
body.searching #list { display: none; }
.search-results { min-width: 0; }
.search-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 6px 8px; }
.search-title { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.search-close { flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: var(--muted);
                border: 1px solid var(--line); background: var(--card); text-decoration: none; }
.search-close:hover { color: var(--text); background: var(--hover); }
.search-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-size: 12.5px; padding: 3px 8px 3px 10px; border-radius: 999px;
        background: var(--primary-soft); color: var(--primary-ink); text-decoration: none; font-weight: 600; }
.chip > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.chip svg { flex: none; opacity: .75; }
.chip:hover svg { opacity: 1; }
.chip-note { font-weight: 400; }
.search-notice { margin: 0 4px 10px; padding: 8px 12px; border-radius: var(--r); background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.search-expansion { margin: -4px 6px 10px; }
.search-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 36px 16px; text-align: center; }
.search-empty svg { color: var(--muted); margin-bottom: 4px; }
.hit-snippet { font-size: 13px; line-height: 1.45; margin-top: 3px; color: var(--muted); overflow-wrap: anywhere;
               display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hit-snippet mark { background: var(--c-amber-bg); color: var(--text); border-radius: 3px; padding: 0 2px; font-weight: 600; }
.badge.reason { background: transparent; color: var(--muted); border-color: var(--line); }
.badge.reason.sem { border-style: dashed; color: var(--c-violet-ink); border-color: var(--c-violet); }
.hit-box { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.search-hit.state-archived .mail-card > *, .search-hit.state-sent .mail-card > *, .search-hit.state-ignored .mail-card > *,
.search-hit.state-answered_externally .mail-card > *, .search-hit.state-forwarded .mail-card > * { opacity: 1; }
.readonly-note { display: flex; gap: 8px; align-items: center; margin: 10px 0 6px; padding: 8px 12px; border-radius: var(--r);
                 background: var(--c-grey-bg); color: var(--c-grey-ink); font-size: 13px; }
.readonly-note svg { flex: none; }
.card-to { margin-top: 1px; overflow-wrap: anywhere; }
@media (max-width: 700px) { body.searching #sidebar { display: none; } }   /* phone: results right under the box */
