/* Почта BizHub — палитра Cartographic Quiet (бумага, лес, золото). */
:root {
  --paper: #f0efe8;
  --surface: #fbfaf6;
  --line: #dcd9cc;
  --ink: #1d2420;
  --muted: #6b7068;
  --forest: #1d3027;
  --forest-ink: #f4f2ea;
  --gold: #c1a35f;
  --gold-soft: #f3ead2;
  --danger: #a33a2c;
  --unread: #2f6b4f;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141a17;
    --surface: #1b2420;
    --line: #2d3a33;
    --ink: #e7e5dc;
    --muted: #9aa198;
    --forest: #2b4a3b;
    --forest-ink: #f4f2ea;
    --gold: #d2b56f;
    --gold-soft: #3a3322;
    --danger: #e0786a;
    --unread: #7cc4a0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 12px 16px; }
.error { color: var(--danger); margin: 8px 0 0; }
.grow { flex: 1; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: none; min-height: 40px; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-solid { background: var(--forest); color: var(--forest-ink); }
.btn-gold { background: var(--gold); color: #1d2420; font-weight: 600; }
.btn-gold.on { background: var(--forest); color: var(--forest-ink); }
.btn-line { border-color: var(--line); background: var(--surface); }
.btn-ghost:hover, .btn-line:hover { background: rgba(127, 127, 110, .12); }
.btn.danger { color: var(--danger); }
.wide { width: 100%; }

.brand { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--gold); font-size: 20px; }

/* Вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: grid; gap: 12px;
}
.field { display: grid; gap: 4px; }
.field span { font-size: 13px; color: var(--muted); }
.field input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--paper); min-height: 44px;
}
.field input:focus, .search input:focus { outline: 2px solid var(--gold); outline-offset: 0; }

/* Каркас */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--forest); color: var(--forest-ink);
}
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .1); }
.topbar .brand { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#refreshAll { font-size: 20px; padding: 4px 12px; }
.topbar-actions { display: flex; gap: 4px; }
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(320px, 420px) 1fr; }
.pane { min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); }
.pane-boxes { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.pane-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 4px 0; }
.back { display: none; }

/* Ящики */
.boxes { display: grid; gap: 8px; }
.box {
  text-align: left; width: 100%; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 10px 12px; cursor: pointer; display: grid; gap: 4px;
}
.box.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.box-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.box-email { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--unread); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; font-weight: 600; }
.box-meta { font-size: 12px; color: var(--muted); }
.box-warn { font-size: 12px; color: var(--danger); }
.usage { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.usage i { display: block; height: 100%; background: var(--gold); }
.box-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.box-actions .btn { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.box-fwd { font-size: 12px; color: var(--muted); word-break: break-all; }

.folders { display: grid; gap: 2px; }
.folder {
  display: flex; justify-content: space-between; border: 0; background: none; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; text-align: left; min-height: 40px; align-items: center;
}
.folder.active { background: var(--gold-soft); font-weight: 600; }
.folder:hover { background: rgba(127, 127, 110, .12); }

.manage { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.manage h3 { margin: 0; font-size: 14px; }

/* Список писем */
.pane-list { display: flex; flex-direction: column; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; min-height: 44px; }
.list-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { display: flex; gap: 8px; padding: 10px 12px; position: sticky; top: 0; background: var(--paper); z-index: 2; }
.search input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  background: var(--surface); min-height: 40px;
}
.waitbar { margin: 0 12px 8px; font-size: 13px; color: var(--muted); }
.code-banner {
  margin: 0 12px 10px; border-radius: 12px; background: var(--forest); color: var(--forest-ink);
  padding: 14px 16px; display: grid; gap: 6px;
}
.code-banner .code-big {
  font: 700 34px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em;
  background: none; border: 0; color: inherit; padding: 0; cursor: pointer; text-align: left;
}
.code-banner .small { opacity: .85; }
.messages { display: grid; }
.msg {
  text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none;
  padding: 10px 14px; cursor: pointer; display: grid; gap: 2px; width: 100%;
}
.msg:hover { background: rgba(127, 127, 110, .08); }
.msg.active { background: var(--gold-soft); }
.msg-top { display: flex; gap: 8px; align-items: baseline; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .msg-from, .msg.unread .msg-subj { font-weight: 700; }
.msg.unread .msg-from::before { content: "● "; color: var(--unread); }
.msg-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snip { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip {
  display: inline-block; font: 600 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--gold-soft);
  border: 1px solid var(--gold); border-radius: 6px; padding: 0 8px; margin-right: 6px; cursor: pointer; color: var(--ink);
}

/* Письмо */
.pane-message { border-right: 0; background: var(--surface); }
.message { padding: 8px 20px 24px; }
.message h1 { font-size: 20px; margin: 8px 0 12px; overflow-wrap: anywhere; }
.meta { display: grid; gap: 2px; font-size: 13px; color: var(--muted); margin-bottom: 12px; overflow-wrap: anywhere; }
.meta b { color: var(--ink); font-weight: 600; }
.codes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.codes .chip { font-size: 20px; padding: 2px 12px; }
.view-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.view-switch .btn { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.view-switch .btn.on { background: var(--gold-soft); border-color: var(--gold); }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.html-body { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.atts { margin-top: 16px; display: grid; gap: 6px; }
.att { display: flex; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; text-decoration: none; }
.att span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); padding: 20px; }
.dialog::backdrop { background: rgba(10, 15, 12, .45); }
.dialog form { display: grid; gap: 12px; }
.dialog h3 { margin: 0; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--forest); color: var(--forest-ink); padding: 10px 16px; border-radius: 10px; z-index: 50;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}

/* Телефон и узкий экран: одна панель за раз. */
@media (max-width: 899px) {
  .panes { display: block; position: relative; }
  .pane { border-right: 0; height: 100%; }
  body[data-view="boxes"] .pane-list, body[data-view="boxes"] .pane-message,
  body[data-view="list"] .pane-boxes, body[data-view="list"] .pane-message,
  body[data-view="message"] .pane-boxes, body[data-view="message"] .pane-list { display: none; }
  .back { display: inline-flex; padding-left: 0; }
  .message { padding: 4px 16px 24px; }
  .html-body { height: 75vh; }
  .topbar { padding-left: 12px; padding-right: 8px; }
  .topbar .btn { padding: 6px 10px; }
  .topbar .brand { font-size: 15px; }
}
