:root {
  --bg: #e6e0d4;
  --paper: #f7f3eb;
  --paper-2: #fffdf8;
  --ink: #1c1915;
  --muted: #6f675c;
  --line: #ddd4c6;
  --accent: #1d4f3a;
  --accent-soft: #e4f0e8;
  --hot: #8d341f;
  --hot-soft: #f8e7df;
  --gold: #8a5a12;
  --gold-soft: #f6ecd6;
  --violet: #4c446e;
  --violet-soft: #ece8f3;
  --blue: #234e70;
  --blue-soft: #e3eef5;
  --shadow: 0 18px 40px rgba(48, 36, 18, 0.08);
  --sans: "Segoe UI Variable Text", "Segoe UI", sans-serif;
  --serif: Georgia, "Palatino Linotype", serif;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-width: 320px;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  background: #fbf8f2;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -0.02em; }
.brand em { display: block; color: var(--muted); font-style: normal; font-size: 13px; }
.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #f6f3ec;
  border-radius: 11px;
  font-family: var(--serif);
  font-weight: 700;
}
.queue-count { margin-left: auto; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

.btn, .btn-primary, .btn-hot, .btn-ghost, .btn-quiet {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  padding: 8px 14px;
}
.btn-primary { background: var(--accent); color: #f7f4ee; border-color: var(--accent); }
.btn-hot { background: var(--hot); color: #fffaf7; border-color: var(--hot); }
.btn-ghost { background: transparent; }
.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  padding: 4px 8px;
}
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn:hover, .btn-ghost:hover, .btn-quiet:hover { border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-hot:hover { filter: brightness(1.08); }

#banner:empty { display: none; }
.banner {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 12px 20px 0;
  padding: 12px 14px;
  background: var(--gold-soft);
  border: 1px solid #ead7ae;
  border-radius: 14px;
}
.banner p { max-width: 78ch; }

.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 232px minmax(320px, 430px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}
.view-rules, .view-settings { grid-template-columns: 232px minmax(0, 1fr); }
.view-rules #list-pane, .view-rules #detail-pane,
.view-settings #list-pane, .view-settings #detail-pane { display: none; }
.view-mail #extra-pane { display: none; }

#rail, #list-pane, #detail-pane, #extra-pane {
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
#rail { padding: 12px; overflow: auto; }
#list-pane, #extra-pane, #detail-pane { display: flex; flex-direction: column; }
.nav-label {
  margin: 14px 8px 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.nav-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
}
.nav-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-btn .count { color: var(--muted); }
.nav-btn.active .count { color: var(--accent); }

.list-head { padding: 14px 14px 8px; }
.list-head h2 { font-size: 18px; letter-spacing: -0.02em; }
#search {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 12px;
  padding: 10px 12px;
}
#mail-list { overflow: auto; padding: 0 8px 8px; }
.hint { color: var(--muted); font-size: 12px; padding: 0 16px 12px; }
.section-label {
  margin: 12px 8px 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mail {
  position: relative;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 14px;
  padding: 10px 10px 10px 14px;
  margin-bottom: 4px;
  cursor: pointer;
}
.mail:hover { background: rgba(255, 253, 248, 0.7); }
.mail.selected { background: var(--paper-2); border-color: var(--line); }
.bar {
  position: absolute;
  left: 4px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 99px;
  background: var(--line);
}
.bar-haute { background: var(--hot); }
.bar-normale { background: var(--gold); }
.bar-basse { background: #cfc6b8; }
.kicker, .meta, .people { color: var(--muted); font-size: 12px; }
.mail-from, .mail-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-from { font-weight: 650; margin-top: 2px; }
.mail-subject { margin-top: 2px; }
.top-actions .btn { white-space: nowrap; }
details.card summary { cursor: pointer; font-weight: 650; }
details.card .send-box { margin-top: 8px; }
.kicker { font-weight: 650; }
.mail-summary {
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 4px;
}
.mail-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.row-actions { display: flex; gap: 4px; }
.empty {
  margin: 24px 12px;
  color: var(--muted);
}

.detail-scroll { overflow: auto; padding: 18px 20px 12px; }
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbf8f2;
  border-radius: 18px 18px 0 0;
}
.detail-title { min-width: 0; flex: 1; display: flex; align-items: flex-start; gap: 10px; }
.who { min-width: 0; }
.who-name { font-weight: 650; font-size: 15px; }
.detail-head .subject {
  font-size: 22px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.subject { font-family: var(--serif); font-size: 28px; line-height: 1.2; letter-spacing: -0.03em; font-weight: 500; }
.back-btn { display: none; }
.people { margin-top: 10px; }
.people div + div { margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.chip {
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  font-size: 13px;
}
.chip-hot { background: var(--hot-soft); border-color: transparent; color: var(--hot); }
.chip-ok { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip-gold { background: var(--gold-soft); border-color: transparent; color: var(--gold); }
.chip-violet { background: var(--violet-soft); border-color: transparent; color: var(--violet); }
.chip-blue { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.prose { font-family: var(--serif); font-size: 18px; line-height: 1.45; }
.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-top: 12px;
}
.card-label { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.facts { margin-top: 8px; }
.attach { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.note { color: var(--muted); margin-top: 8px; font-size: 13px; }
.drafts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.draft-col.send { outline: 2px solid var(--accent); outline-offset: 0; border-radius: 14px; }
textarea, select, .field input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 12px;
  padding: 10px 12px;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.45; }
textarea.brief { min-height: 72px; }
.draft-actions { display: flex; gap: 8px; margin-top: 8px; }
.selectors { display: flex; gap: 8px; flex-shrink: 0; justify-content: flex-end; }
.selectors label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.selectors select { min-width: 168px; background: var(--paper-2); }
.actionbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fbf8f2;
  border-radius: 0 0 18px 18px;
}
.detail-empty { margin: auto; max-width: 42ch; text-align: center; color: var(--muted); padding: 24px; }
.detail-empty strong { display: block; color: var(--ink); font-size: 22px; font-family: var(--serif); font-weight: 500; margin-bottom: 8px; }

#extra-pane { overflow: auto; padding: 22px; }
.page-title { font-family: var(--serif); font-size: 32px; font-weight: 500; letter-spacing: -0.03em; }
.lede { color: var(--muted); max-width: 70ch; margin: 8px 0 18px; }
.stack { display: grid; gap: 12px; }
.suggestion, .rule-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.suggestion { background: var(--accent-soft); border-color: transparent; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.field { display: grid; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field span { font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.help { color: var(--muted); max-width: 75ch; }
.path { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }

#modal {
  position: fixed;
  inset: 0;
  background: rgba(32, 25, 16, 0.46);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 5;
}
#modal[hidden] { display: none !important; }
.modal {
  width: min(760px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  background: var(--paper);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal h3 { font-family: var(--serif); font-size: 28px; font-weight: 500; }
.send-box { white-space: pre-wrap; }
.modal .send-box { font-family: var(--serif); font-size: 17px; }
#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #f7f4ee;
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 6;
  max-width: min(640px, calc(100% - 24px));
}
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 12px;
}
.login-card h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 32px;
  margin: 0;
}
.login-card .mark { width: 46px; height: 46px; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 1180px) {
  .drafts { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1080px) {
  .shell, .view-rules, .view-settings { grid-template-columns: 1fr; }
  #rail { display: flex; gap: 6px; overflow: auto; padding: 8px; }
  .nav-label { display: none; }
  .nav-btn { width: auto; white-space: nowrap; }
  .queue-count { display: none; }
  .subject, .detail-head .subject { font-size: 22px; }
  .detail-head { flex-direction: column; }
  .selectors { width: 100%; }
  .selectors select { flex: 1; min-width: 0; }
  .shell.reading #rail, .shell.reading #list-pane { display: none; }
  .shell.reading .back-btn { display: inline-flex; }
  .banner { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
