:root {
  /* neutri tinti verso pino/teal profondo (hue ~190) */
  --bg-0:   oklch(0.19 0.014 190);
  --bg-1:   oklch(0.23 0.016 190);
  --bg-2:   oklch(0.27 0.018 190);
  --bg-3:   oklch(0.32 0.020 190);
  --line:   oklch(0.36 0.022 190);
  --line-soft: oklch(0.30 0.018 190);
  --ink-0:  oklch(0.95 0.008 190);
  --ink-1:  oklch(0.80 0.010 190);
  --ink-2:  oklch(0.62 0.012 190);
  --ink-3:  oklch(0.48 0.012 190);
  /* UN accento saturo (verde-menta acceso) */
  --acc:    oklch(0.80 0.16 165);
  --acc-dim: oklch(0.80 0.16 165 / 0.14);
  --acc-ink: oklch(0.24 0.05 165);
  --danger: oklch(0.66 0.15 25);

  --r-sm: 6px; --r-md: 9px; --r-lg: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-x: cubic-bezier(0.16, 1, 0.3, 1);
  font-synthesis: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--ink-0);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05", "ss01";
}
.hidden { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; }

.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 600; letter-spacing: -0.02em; }
.brand .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--acc); align-self: center; box-shadow: 0 0 10px var(--acc); }
.brand small { color: var(--ink-2); font-weight: 500; font-size: 11.5px; letter-spacing: 0.02em; }

/* ===== login ===== */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg-0); padding: 24px; }
.login-card {
  width: min(380px, 92vw);
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 32px 28px 22px;
  display: flex; flex-direction: column; align-items: stretch;
  text-align: center;
}
.login-card .brand { justify-content: center; font-size: 19px; margin-bottom: 4px; }
.login-sub { color: var(--ink-2); font-size: 13px; margin-bottom: 22px; }
.login-card input {
  background: var(--bg-0); border: 1px solid var(--line); color: var(--ink-0);
  padding: 12px 13px; border-radius: var(--r-md); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .3s var(--ease); margin-bottom: 11px; text-align: center;
}
.login-card input:focus { border-color: var(--acc); }
.login-btn {
  background: var(--acc); color: var(--acc-ink); font-weight: 700; font-size: 15px;
  padding: 12px; border-radius: var(--r-md);
  box-shadow: 0 4px 18px oklch(0.80 0.16 165 / 0.22);
  transition: filter .3s var(--ease), transform .35s var(--ease-x);
}
.login-btn:hover { filter: brightness(1.06); }
.login-btn:active { transform: translateY(1px) scale(0.99); }
.login-err { color: var(--danger); font-size: 12.5px; min-height: 1.3em; margin-top: 10px; }
.login-foot { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* ===== shell ===== */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 56px 1fr auto;
  grid-template-areas: "top top" "side main" "foot foot";
  height: 100vh; max-height: 100vh; overflow: hidden;
}

/* ===== topbar ===== */
.top {
  grid-area: top;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-soft);
}
.top .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--r-sm);
  color: var(--ink-1);
  transition: background .3s var(--ease), color .3s var(--ease);
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink-0); }
.icon-btn svg { width: 18px; height: 18px; }

/* ===== sidebar ===== */
.side {
  grid-area: side;
  background: var(--bg-1);
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.create { padding: 18px 16px 14px; border-bottom: 1px solid var(--line-soft); }
.create-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--acc); color: var(--acc-ink);
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  padding: 14px 16px; border-radius: var(--r-md);
  box-shadow: 0 4px 18px oklch(0.80 0.16 165 / 0.22);
  transition: transform .35s var(--ease-x), box-shadow .35s var(--ease-x), filter .3s var(--ease);
}
.create-btn:hover { filter: brightness(1.06); box-shadow: 0 6px 26px oklch(0.80 0.16 165 / 0.30); }
.create-btn:active { transform: translateY(1px) scale(0.99); }
.create-btn svg { width: 17px; height: 17px; }

.custom-row { display: flex; margin-top: 10px; align-items: stretch; }
.custom-row input {
  flex: 1; min-width: 0;
  background: var(--bg-0); border: 1px solid var(--line); border-right: none;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  color: var(--ink-0); padding: 8px 11px; font-size: 13px; font-family: inherit;
  outline: none; transition: border-color .3s var(--ease);
}
.custom-row input::placeholder { color: var(--ink-3); }
.custom-row input:focus { border-color: var(--acc); }
.custom-row .suffix {
  display: flex; align-items: center;
  background: var(--bg-0); border: 1px solid var(--line);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 0 11px; color: var(--ink-2); font-size: 12.5px; white-space: nowrap;
}

.list-head { display: flex; align-items: baseline; justify-content: space-between; padding: 16px 18px 8px; }
.list-head h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.11em; color: var(--ink-2); font-weight: 600; }
.list-head .total { font-size: 11px; color: var(--ink-3); }

.boxes { flex: 1; overflow-y: auto; padding: 0 10px 14px; }
.box {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--r-md);
  cursor: pointer; transition: background .28s var(--ease);
}
.box:hover { background: var(--bg-2); }
.box.active { background: var(--bg-2); }
.box.active .box-name { color: var(--ink-0); }
.box-avatar {
  width: 34px; height: 34px; flex: none; border-radius: 8px;
  background: var(--bg-3); display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: var(--ink-1); letter-spacing: -0.02em;
}
.box-body { flex: 1; min-width: 0; }
.box-name { font-weight: 600; font-size: 13.5px; color: var(--ink-1); letter-spacing: -0.01em; }
.box-addr { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boxes .box-empty { padding: 14px 12px; font-size: 12.5px; color: var(--ink-3); }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--acc); color: var(--acc-ink); font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.badge.zero { background: transparent; color: transparent; }

/* ===== main ===== */
.main { grid-area: main; background: var(--bg-0); overflow: hidden; display: flex; flex-direction: column; position: relative; }

.inbox-head { display: flex; align-items: center; gap: 14px; padding: 18px 26px; border-bottom: 1px solid var(--line-soft); }
.inbox-head .title { min-width: 0; flex: 1; }
.inbox-head h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.inbox-head .sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-head .sub b { color: var(--acc); font-weight: 600; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-1);
  padding: 8px 12px; border-radius: var(--r-sm); border: 1px solid var(--line-soft);
  transition: background .28s var(--ease), border-color .28s var(--ease), color .28s var(--ease);
}
.ghost-btn:hover { background: var(--bg-1); color: var(--ink-0); border-color: var(--line); }
.ghost-btn svg { width: 15px; height: 15px; }
.ghost-btn.danger:hover { color: var(--danger); border-color: oklch(0.66 0.15 25 / 0.4); }
.refresh svg { transition: transform .2s var(--ease); }
.refresh.spin svg { animation: spin .7s var(--ease-x); }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.scroll { flex: 1; overflow-y: auto; }

/* mail list */
.mails { padding: 6px 0; }
.mail-row {
  display: grid; grid-template-columns: 14px 168px 1fr auto; align-items: center; gap: 16px;
  padding: 13px 26px; cursor: pointer; border-bottom: 1px solid var(--line-soft);
  transition: background .24s var(--ease);
}
.mail-row:hover { background: var(--bg-1); }
.mail-dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.mail-row.unread .mail-dot { background: var(--acc); box-shadow: 0 0 8px var(--acc); }
.mail-row.unread .mail-from, .mail-row.unread .mail-subj { color: var(--ink-0); }
.mail-row.unread .mail-from { font-weight: 700; }
.mail-from { color: var(--ink-1); font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-mid { min-width: 0; }
.mail-subj { color: var(--ink-1); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-preview { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-time { color: var(--ink-3); font-size: 11.5px; white-space: nowrap; }

/* empty state */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px; gap: 22px; }
.empty .addr-big { font-size: clamp(20px, 3vw, 30px); font-weight: 600; letter-spacing: -0.03em; color: var(--ink-0); word-break: break-word; }
.empty .addr-big .at { color: var(--ink-3); font-weight: 400; }
.empty .waiting { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13.5px; }
.pulse-ring { position: relative; width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
.pulse-ring::before, .pulse-ring::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--acc); opacity: 0; animation: ring 2.6s var(--ease-x) infinite; }
.pulse-ring::after { animation-delay: 1.3s; }
.pulse-ring i { width: 7px; height: 7px; border-radius: 50%; background: var(--acc); }
@keyframes ring { 0% { transform: scale(0.3); opacity: 0.55; } 100% { transform: scale(1); opacity: 0; } }

/* reading view */
.reader { flex: 1; overflow-y: auto; }
.reader-inner { max-width: 680px; margin: 0 auto; padding: 30px 32px 60px; }
.back-btn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; margin-bottom: 22px; transition: color .28s var(--ease); }
.back-btn:hover { color: var(--ink-0); }
.back-btn svg { width: 15px; height: 15px; }
.reader h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.25; }
.reader-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 16px 0 4px; padding-bottom: 20px; border-bottom: 1px solid var(--line-soft); }
.reader-sender { display: flex; align-items: center; gap: 12px; }
.reader-sender .av { width: 40px; height: 40px; border-radius: 9px; flex: none; background: var(--bg-2); display: grid; place-items: center; font-weight: 700; color: var(--ink-1); }
.reader-sender .who b { font-weight: 600; color: var(--ink-0); font-size: 14px; }
.reader-sender .who .em { color: var(--ink-2); font-size: 12px; }
.reader-meta .when { color: var(--ink-2); font-size: 12.5px; }
.reader-body { margin-top: 26px; font-size: 15px; line-height: 1.7; color: var(--ink-1); max-width: 68ch; white-space: pre-wrap; word-break: break-word; }
.reader-body a { color: var(--acc); text-decoration: none; border-bottom: 1px solid oklch(0.80 0.16 165 / 0.4); padding-bottom: 1px; }
.reader-body a:hover { border-bottom-color: var(--acc); }
.reader-actions { display: flex; gap: 10px; margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line-soft); }

/* ===== footer + claim (animato come codice) ===== */
.foot { grid-area: foot; display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 15px 26px; background: var(--bg-1); border-top: 1px solid var(--line-soft); color: var(--ink-1); }
.claim {
  font-family: ui-monospace, 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--acc); white-space: nowrap; overflow: hidden;
}
.claim .claim-caret { display: inline-block; width: 0.6em; margin-left: 1px; color: var(--acc); animation: caret-blink 1s steps(1) infinite; }
@keyframes caret-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ===== toast ===== */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-0);
  padding: 11px 16px; border-radius: var(--r-md); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 9px;
  box-shadow: 0 12px 40px oklch(0.10 0.02 190 / 0.55);
  animation: toast-in .42s var(--ease-x) both;
}
.toast .ck { color: var(--acc); display: inline-flex; }
.toast.out { animation: toast-out .34s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(0.97); } }

/* ===== settings popover ===== */
.pop-wrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 10px); right: 0; width: 300px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 18px 50px oklch(0.10 0.02 190 / 0.6); padding: 18px; z-index: 40;
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(0.98); transform-origin: top right;
  transition: opacity .3s var(--ease-x), transform .3s var(--ease-x), visibility .3s;
}
.popover.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.popover h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-2); font-weight: 600; margin-bottom: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.set-row label { font-size: 13.5px; color: var(--ink-0); font-weight: 500; }
.switch { position: relative; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.track { position: absolute; inset: 0; background: var(--bg-3); border-radius: 999px; transition: background .32s var(--ease); }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--ink-1); transition: transform .34s var(--ease-x), background .3s var(--ease); }
.switch input:checked + .track { background: var(--acc); }
.switch input:checked + .track::after { transform: translateX(17px); background: var(--acc-ink); }
.days-row { display: flex; align-items: center; gap: 9px; }
.days-row input { width: 58px; background: var(--bg-0); border: 1px solid var(--line); color: var(--ink-0); border-radius: var(--r-sm); padding: 7px 9px; font-size: 13px; font-family: inherit; outline: none; text-align: center; }
.days-row input:focus { border-color: var(--acc); }
.set-note { font-size: 11.5px; color: var(--ink-2); line-height: 1.5; margin-top: 8px; }
.set-note b { color: var(--ink-0); font-weight: 600; }
.set-disabled { opacity: 0.4; pointer-events: none; }

/* ===== confirm dialog ===== */
.confirm-back { position: fixed; inset: 0; z-index: 60; background: oklch(0.12 0.015 190 / 0.6); display: grid; place-items: center; opacity: 0; visibility: hidden; transition: opacity .3s var(--ease), visibility .3s; }
.confirm-back.open { opacity: 1; visibility: visible; }
.confirm { width: min(360px, 90vw); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; box-shadow: 0 24px 70px oklch(0.08 0.02 190 / 0.7); transform: translateY(10px) scale(0.97); transition: transform .34s var(--ease-x); }
.confirm-back.open .confirm { transform: none; }
.confirm h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.confirm p { font-size: 13px; color: var(--ink-2); margin-top: 8px; line-height: 1.55; }
.confirm p b { color: var(--ink-0); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.btn-quiet { padding: 9px 15px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; color: var(--ink-1); border: 1px solid var(--line-soft); transition: background .28s var(--ease); }
.btn-quiet:hover { background: var(--bg-1); }
.btn-danger { padding: 9px 15px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; background: var(--danger); color: oklch(0.20 0.03 25); transition: filter .28s var(--ease); }
.btn-danger:hover { filter: brightness(1.08); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 3px solid var(--bg-0); }

/* ===== responsive (telefono) ===== */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr auto;
    grid-template-areas: "top" "side" "main" "foot";
    height: auto; min-height: 100vh; max-height: none; overflow: visible;
  }
  .side { border-right: none; border-bottom: 1px solid var(--line-soft); }
  .boxes { max-height: 40vh; }
  .main { min-height: 50vh; }
  .mail-row { grid-template-columns: 12px 1fr auto; gap: 11px; padding: 12px 16px; }
  .mail-from { grid-column: 2; }
  .mail-mid { grid-column: 2; grid-row: 2; }
  .mail-dot { grid-row: 1 / 3; }
  .mail-time { grid-column: 3; grid-row: 1; }
  .inbox-head { padding: 14px 16px; flex-wrap: wrap; }
  .reader-inner { padding: 22px 18px 40px; }
  .foot { padding: 14px 16px; }
  .claim { font-size: 10.5px; letter-spacing: 0.03em; }
}
