/* Master Mailbox — оформление.
   Спокойная бирюзовая гамма, шрифт Manrope (с кириллицей), цвет ящика — главный опознавательный знак. */
/* Тёмная контрастная тема — основная. Светлая включается переключателем в меню. */
:root, [data-theme="dark"] {
  --bg: #0A0E13;
  --surface: #141A22;
  --side: #0E131A;
  --ink: #F4F7FA;
  --ink-2: #DCE3EA;
  --muted: #A9B6C3;
  --line: #2C3743;
  --line-2: #222C37;
  --accent: #3FD8C5;
  --accent-hover: #72E6D8;
  --accent-soft: #10403A;
  --accent-ink: #03201C;
  --unread: #0F2A27;
  --danger: #FF8A7A;
  --danger-soft: #3D1A16;
  --ok: #7FE0A8;
  --ok-soft: #133524;
  --hover: #1B2430;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
  --mb-light: 62%;          /* насколько осветлять цвета ящиков */
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --side: #FFFFFF;
  --ink: #0E1520;
  --ink-2: #252F3D;
  --muted: #4E5A6B;
  --line: #D3DAE3;
  --line-2: #E3E8EE;
  --accent: #08665F;
  --accent-hover: #054F4A;
  --accent-soft: #D7EFEC;
  --accent-ink: #FFFFFF;
  --unread: #EAF6F4;
  --danger: #B42318;
  --danger-soft: #FDE8E6;
  --ok: #17683F;
  --ok-soft: #DFF2E7;
  --hover: #F2F5F8;
  --shadow: 0 1px 2px rgba(15, 25, 40, .08), 0 2px 10px rgba(15, 25, 40, .06);
  --mb-light: 100%;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
        stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side {
  background: var(--side); border-right: 1px solid var(--line);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px;
         margin: 0 10px 22px; letter-spacing: -0.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
              display: grid; place-items: center; }
.brand-mark svg.i { width: 17px; height: 17px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: var(--hover); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav a.compose { background: var(--accent); color: var(--accent-ink); font-weight: 700; margin-bottom: 14px;
                 justify-content: center; padding: 11px 12px; }
.nav a.compose:hover { background: var(--accent-hover); color: var(--accent-ink); }
.legend { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.legend h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
             font-weight: 700; margin: 0 12px 8px; }
.legend a {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px; color: var(--ink-2);
  font-size: 14px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.legend a:hover { background: var(--hover); text-decoration: none; }
.legend a.on { background: var(--hover); color: var(--ink); font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.side .bottom { margin-top: auto; padding-top: 18px; }
.side .bottom button { width: 100%; justify-content: flex-start; }

.main { padding: 28px 36px 60px; min-width: 0; width: 100%; max-width: 1240px; }
.main.wide { max-width: 1480px; }
h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.02em; font-weight: 800; }
h2 { font-size: 17px; margin: 30px 0 12px; font-weight: 800; }
.sub { color: var(--muted); margin: 0 0 22px; }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 600; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.warn { background: var(--danger-soft); color: var(--danger); font-size: 14px; padding: 8px 12px;
        border-radius: 8px; margin: 0 0 10px; }

/* ---------- элементы форм ---------- */
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 200px; resize: vertical; line-height: 1.6; }
button, .btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: var(--radius-sm); padding: 9px 16px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 8px; line-height: 1.4; transition: background .15s;
}
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: .6; cursor: default; }
button.ghost, .btn.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { background: var(--hover); border-color: var(--line); color: var(--ink); }
.btn.ghost.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: transparent; }
button.danger:hover { background: var(--danger-soft); border-color: transparent; }
button.link { background: none; border: none; color: var(--muted); padding: 9px 12px; font-weight: 500; }
button.link:hover { background: var(--hover); color: var(--ink); }

/* ---------- поиск ---------- */
.searchbar { position: relative; display: flex; gap: 10px; margin-bottom: 12px; }
.searchbar .field { position: relative; flex: 1; }
.searchbar .field svg.i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbar input[type=text] { font-size: 16px; padding: 13px 16px 13px 46px; border-radius: 999px;
                              box-shadow: var(--shadow); border-color: transparent; }
.searchbar button { border-radius: 999px; padding: 0 22px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 26px; font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); cursor: pointer;
  user-select: none; font-weight: 500;
}
.pill:hover { border-color: var(--muted); }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill:has(input:checked) { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }
.pill:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill input[type=date] { position: static; opacity: 1; pointer-events: auto; border: none; padding: 0;
                         background: transparent; width: auto; font-size: 14px; box-shadow: none; }
.filters .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.filters a.reset { color: var(--muted); padding: 6px 8px; }

/* ---------- список переписок ---------- */
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
        border: 1px solid var(--line-2); }
.row {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 4px 14px; align-items: center;
  padding: 13px 20px 13px 16px; border-top: 1px solid var(--line-2); color: var(--ink);
  border-left: 4px solid color-mix(in srgb, var(--mb, transparent) var(--mb-light), #fff); position: relative;
}
.row:first-child { border-top: none; }
.row:hover { background: var(--hover); text-decoration: none; }
.row.unread { background: var(--unread); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800;
  font-size: 15px; color: color-mix(in srgb, var(--mb, var(--accent)) var(--mb-light), #fff);
  background: color-mix(in srgb, var(--mb, var(--accent)) 24%, var(--surface));
  grid-row: span 2;
}
.row .top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .who { font-weight: 800; }
.row .count { color: var(--muted); font-size: 13px; font-weight: 600; }
.mbtag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 2px 9px;
  border-radius: 999px; color: color-mix(in srgb, var(--mb) var(--mb-light), #fff); white-space: nowrap; flex: none;
  background: color-mix(in srgb, var(--mb) 22%, var(--surface));
}
.row .date { color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right; }
.row.unread .date { color: var(--accent); font-weight: 700; }
.row .line2 { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 14.5px; }
.row .line2 b { color: var(--ink-2); font-weight: 600; }
.row.unread .line2 b { color: var(--ink); font-weight: 800; }
.row .unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.more { display: flex; justify-content: center; margin-top: 16px; }

/* ---------- переписка ---------- */
.thread-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.thread-head .meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.msg { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px;
       border: 1px solid var(--line-2); overflow: hidden; }
.msg > summary { list-style: none; cursor: pointer; }
.msg > summary::-webkit-details-marker { display: none; }
.msg-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 2px 14px; align-items: center; padding: 14px 20px; }
.msg-head .avatar { --mb: var(--who-color); }
.msg-head .name { font-weight: 800; }
.msg-head .addr { color: var(--muted); font-weight: 500; font-size: 14px; }
.msg-head .to { grid-column: 2 / 4; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.msg:not([open]) .msg-head .to { display: none; }
.msg .snip { display: none; grid-column: 2 / 4; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg:not([open]) .snip { display: block; }
.msg:not([open]) > summary:hover { background: var(--hover); }
.msg.mine { border-left: 4px solid color-mix(in srgb, var(--mb) var(--mb-light), #fff); }
.mine-tag { font-size: 12px; font-weight: 700; color: color-mix(in srgb, var(--mb) var(--mb-light), #fff); margin-left: 6px; }
.msg-body { border-top: 1px solid var(--line-2); background: #fff; }
.msg iframe { width: 100%; border: 0; display: block; height: 80px; background: #fff; }
.atts { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; flex-wrap: wrap; gap: 8px; font-size: 14px; }
.atts a { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm);
          padding: 7px 12px; color: var(--ink-2); background: var(--surface); }
.atts a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.atts .size { color: var(--muted); }
.collapsed-note { text-align: center; margin: 4px 0 12px; }
.tools { display: flex; gap: 8px; margin: 24px 0 12px; flex-wrap: wrap; }

/* ---------- форма письма ---------- */
.composer { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
            border: 1px solid var(--line-2); }
.grid2 { display: grid; grid-template-columns: 96px 1fr; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.grid2 label { color: var(--muted); font-size: 14px; font-weight: 600; }
.from-pick { border-left: 5px solid var(--mb, var(--line)); font-weight: 600; }
.composer .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 12px; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.file-btn { position: relative; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-list { font-size: 13px; color: var(--muted); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
              border: 1px solid var(--line-2); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 12px 18px; text-align: left; border-top: 1px solid var(--line-2); font-size: 14px; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; border-top: none; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 800; background: var(--hover); }

/* ---------- статистика ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border: 1px solid var(--line-2); }
.card .k { color: var(--muted); font-size: 13px; font-weight: 600; }
.card .v { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bar-cell { width: 34%; }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line-2); }
.bar .new { background: var(--accent); }
.bar .fu { background: color-mix(in srgb, var(--accent) 35%, var(--surface)); }
.key { display: inline-flex; align-items: center; gap: 6px; margin-right: 16px; font-size: 13px; color: var(--muted); }
.key i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.trend { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border: 1px solid var(--line-2); }
.trend svg { width: 100%; height: auto; display: block; }
.loading { color: var(--muted); padding: 24px 0; }

/* ---------- ящики ---------- */
.mb-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
           border: 1px solid var(--line-2); border-left: 5px solid color-mix(in srgb, var(--mb) var(--mb-light), #fff);
           padding: 16px 20px; margin-bottom: 12px; }
.mb-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.mb-name { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; }
.mb-card form.edit { display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; }
.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.mb-card input[type=text] { width: 240px; }
.swatches { display: flex; gap: 6px; padding: 7px 0; }
.swatches label { position: relative; }
.swatches label input { position: absolute; opacity: 0; }
.swatches label span { width: 22px; height: 22px; border-radius: 50%; display: block; cursor: pointer;
                       box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.swatches label input:checked + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.swatches label input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line-2);
         padding: 20px; margin-top: 18px; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline input[type=email] { max-width: 340px; }

.center-box { max-width: 400px; margin: 12vh auto; background: var(--surface); border-radius: var(--radius);
              box-shadow: var(--shadow); border: 1px solid var(--line-2); padding: 32px; }
.center-box p { color: var(--muted); }
.center-box input { margin-bottom: 12px; }
.center-box button { width: 100%; justify-content: center; padding: 11px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .legend, .side .bottom { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav a.compose { margin-bottom: 0; }
  .main { padding: 18px 14px 40px; }
  .row { padding: 12px 14px 12px 10px; }
  .grid2 { grid-template-columns: 1fr; }
  .mbtag { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* цитата предыдущей переписки внутри письма */
.quote { border-top: 1px dashed #CBD3DC; background: #fff; }
.quote > summary { list-style: none; cursor: pointer; padding: 10px 22px; color: #3E4A5A; font-size: 13px; font-weight: 700; }
.quote > summary::-webkit-details-marker { display: none; }
.quote > summary:hover, .quote[open] > summary { color: #08665F; }
.msg .subj b { color: var(--ink-2); font-weight: 700; }
.msg:not([open]) .msg-head .subj { display: none; }
.newest { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
          color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; margin-right: 6px; }
.composer + h2 { margin-top: 28px; }

/* переключатель темы */
.theme-toggle { width: 100%; justify-content: flex-start; }
[data-theme="dark"] .dot { filter: brightness(1.45) saturate(1.15); }

/* вход и двухэтапная проверка */
.center-box .field-label { margin-bottom: 12px; }
.center-box .field-label input { margin-bottom: 0; }
.center-box h1 { margin-bottom: 10px; }
.steps { padding-left: 20px; color: var(--ink-2); font-size: 14px; }
.steps li { margin-bottom: 6px; }
.qr { background: #fff; border-radius: 12px; padding: 12px; width: 220px; margin: 8px auto 10px; }
.qr svg { width: 100%; height: auto; display: block; }
code.secret { font-size: 14px; letter-spacing: .08em; word-break: break-all; color: var(--ink); }
.whoami { display: flex; align-items: center; gap: 10px; padding: 9px 12px; color: var(--ink-2); font-weight: 600; }
