:root {
  --bg: #f6f3ee;
  --paper: #fffdf9;
  --ink: #1f1d1a;
  --muted: #6b655c;
  --line: #e4ddd2;
  --accent: #c2410c;
  --accent-ink: #fff;
  --accent-soft: #fdeee6;
  --ok: #15803d;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 8px 24px rgba(40, 30, 20, .06);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513;
    --paper: #211e1b;
    --ink: #f1ece4;
    --muted: #a59d92;
    --line: #34302b;
    --accent: #f97316;
    --accent-ink: #1a0d05;
    --accent-soft: #3a2316;
    --ok: #4ade80;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1200px; margin: 0 auto; padding: 18px 20px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand svg { width: 28px; height: 28px; fill: var(--accent); stroke: var(--paper); stroke-width: 2; stroke-linejoin: round; }
.topbar-actions { display: flex; gap: 6px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; text-decoration: none;
  font-weight: 600; font-size: 15px; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 13px 20px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--paper); border-color: var(--line); }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger-ghost:hover { border-color: currentColor; }

/* ---------- главная ---------- */
.view { max-width: 1200px; margin: 0 auto; padding: 0 20px 48px; }
.home { max-width: 960px; }
.hero { padding: 40px 0 28px; }
.hero h1 { font-size: clamp(30px, 5vw, 52px); line-height: 1.08; letter-spacing: -.03em; margin: 0 0 18px; font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--accent); }
.lede { color: var(--muted); font-size: 18px; max-width: 620px; margin: 0; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.card h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 800;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; }
.field input, .field select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; font-weight: 400; min-width: 0;
}
.addr-input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.addr-input input, .addr-input select { border: 0; border-radius: 0; background: transparent; }
.addr-input input { flex: 1 1 auto; font-family: var(--mono); font-size: 15px; }
.addr-input select { flex: 0 1 auto; width: auto; max-width: 55%; font-family: var(--mono); font-size: 15px; padding-left: 4px; cursor: pointer; }
.addr-input .at { display: grid; place-items: center; color: var(--muted); font-family: var(--mono); padding: 0 2px; }
.addr-input:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.addr-input input:focus-visible, .addr-input select:focus-visible { outline: none; }
.pin-input { letter-spacing: .12em; text-transform: uppercase; }
.error { color: var(--danger); font-size: 14px; margin: 0; min-height: 1.2em; }
.card .error:empty { display: none; }

.facts { list-style: none; padding: 0; margin: 32px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; color: var(--muted); font-size: 14px; }
.facts li { border-top: 1px solid var(--line); padding-top: 12px; }
.facts b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 2px; }

/* ---------- ящик ---------- */
.addrbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.addr-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.address { font-size: clamp(18px, 2.6vw, 26px); font-weight: 600; word-break: break-all; }
.addrbar-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 13px; color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 7px; color: var(--ok); font-weight: 600; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.mail {
  display: grid; grid-template-columns: minmax(280px, 380px) 1fr; min-height: 560px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 12px; padding: 1px 8px; }
.msg-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; max-height: 70vh; }
.msg-list li { border-bottom: 1px solid var(--line); }
.msg-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left;
  padding: 13px 16px; border: 0; background: transparent; cursor: pointer; position: relative;
}
.msg-item:hover { background: var(--bg); }
.msg-item.active { background: var(--accent-soft); }
.msg-item.unread::before { content: ""; position: absolute; left: 6px; top: 19px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.msg-item .from { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item.unread .from, .msg-item.unread .subj { font-weight: 800; }
.msg-item .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-item .subj { grid-column: 1 / -1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item .prev { grid-column: 1 / -1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item.new { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 25%, transparent); } }

.empty { padding: 40px 28px; text-align: center; color: var(--muted); font-size: 14px; }
.empty p { margin: 4px 0; }
.empty strong { color: var(--ink); font-size: 16px; }
.empty-icon svg { width: 56px; height: 56px; fill: none; stroke: var(--line); stroke-width: 2.4; stroke-linejoin: round; margin-bottom: 8px; }

.reader { min-width: 0; display: flex; flex-direction: column; }
.reader-empty { margin: auto; color: var(--muted); padding: 40px; }
.reader-body { display: flex; flex-direction: column; flex: 1; padding: 20px 24px 24px; gap: 12px; min-height: 0; }
.reader-body h2 { margin: 0; font-size: 22px; line-height: 1.25; word-break: break-word; }
.back { display: none; align-self: flex-start; }
.r-meta { font-size: 14px; display: grid; gap: 2px; color: var(--ink); word-break: break-all; }
.r-meta .k { color: var(--muted); display: inline-block; min-width: 76px; }
.r-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
.grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--paper); }
.att-list { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.att-list:empty { display: none; }
.att-list a {
  display: inline-flex; gap: 8px; align-items: center; padding: 6px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px; color: var(--ink); text-decoration: none; background: var(--bg);
}
.att-list a:hover { border-color: var(--muted); }
.att-list small { color: var(--muted); }
.r-html { flex: 1; width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.r-text { flex: 1; margin: 0; white-space: pre-wrap; word-break: break-word; font: 14px/1.6 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 16px; overflow: auto; min-height: 420px; }

.danger-zone { margin-top: 18px; text-align: right; }

/* ---------- окно с PIN ---------- */
.modal { position: fixed; inset: 0; background: rgba(20, 15, 10, .55); display: grid; place-items: center; padding: 16px; z-index: 50; backdrop-filter: blur(3px); }
.modal-card {
  background: var(--paper); border-radius: 18px; padding: 28px; width: min(480px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 14px;
}
.modal-card h2 { margin: 0; font-size: 24px; }
.warn { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.cred { display: flex; flex-direction: column; gap: 4px; }
.cred-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.cred .address { font-size: 17px; }
.pin { font-size: 28px; font-weight: 700; letter-spacing: .14em; color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 10px; font-size: 14px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- мобильные ---------- */
@media (max-width: 820px) {
  .cards, .facts { grid-template-columns: 1fr; }
  .hero { padding: 20px 0 22px; }
  .mail { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  .mail.reading .list-pane { display: none; }
  .mail:not(.reading) .reader { display: none; }
  .back { display: inline-flex; }
  .addrbar-meta { align-items: flex-start; }
  .topbar { padding: 14px 16px; }
  .view { padding: 0 16px 40px; }
  .reader-body { padding: 16px; }
  .msg-list { max-height: none; }
}
