/*
 * Оформление веб-почты promail.
 *
 * Палитра общая с админкой: один продукт. Ни одного внешнего ресурса —
 * системные шрифты и встроенная графика, потому что у сервера может не быть
 * выхода в интернет.
 */

:root {
  color-scheme: light dark;

  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --hover: #eef2f5;
  --selected: #e3edf5;
  --border: #d9dee4;
  --border-strong: #c3cbd4;
  --text: #1b2127;
  --muted: #5e6a76;
  --accent: #2f6690;
  --accent-hover: #27567a;
  --accent-text: #ffffff;
  --accent-soft: #e5eff7;
  --danger: #9d2b2b;
  --danger-soft: #fbeded;
  --ok: #2c6b40;
  --warn-soft: #fcf3e4;
  --warn: #8a5a12;
  --flag: #c7811a;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 12px rgba(16, 24, 32, .05);
  --shadow-strong: 0 8px 32px rgba(16, 24, 32, .22);
  --radius: 6px;
  --topbar: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --surface: #1b2025;
    --surface-2: #21272d;
    --hover: #242b32;
    --selected: #243444;
    --border: #2e363e;
    --border-strong: #3d4750;
    --text: #dde3e9;
    --muted: #94a0ab;
    --accent: #5b9bc6;
    --accent-hover: #6fabd4;
    --accent-text: #10171d;
    --accent-soft: #1f3040;
    --danger: #de7b7b;
    --danger-soft: #33201f;
    --ok: #77c48c;
    --warn-soft: #2c2519;
    --warn: #d9ac63;
    --flag: #e2a14a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-strong: 0 8px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }

/* --- кнопки --- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.wide { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.active { color: var(--flag); }
.icon-btn svg { width: 18px; height: 18px; }

.link-btn {
  border: 0; background: none; padding: 0; color: var(--accent);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.alert { margin: 0; padding: 8px 10px; border-radius: var(--radius); }
.alert.error { background: var(--danger-soft); color: var(--danger); }

/* --- вход --- */

.login-screen {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  width: 100%; max-width: 360px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-logo { color: var(--accent); }
.login-card h1 { font-size: 22px; }
.login-subtitle { margin: -8px 0 4px; color: var(--muted); }
.login-hint { margin: 0; font-size: 12px; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); }
.field input {
  height: 36px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2);
}

/* --- раскладка клиента --- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 220px minmax(300px, 400px) 1fr;
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas: "top top top" "side list reader";
}

.topbar {
  grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; width: 196px; flex: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px; background: var(--accent);
  -webkit-mask: none;
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px 5px; border: 1.5px solid var(--accent-text); border-radius: 1px;
}
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 17px; background: var(--surface-2);
}
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-address { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar {
  grid-area: side; padding: 12px 8px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.compose-button { height: 38px; margin-bottom: 12px; font-weight: 600; }

.folders { list-style: none; margin: 0; padding: 0; }
.folders button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px; border: 0; border-radius: var(--radius);
  background: transparent; cursor: pointer; text-align: left;
}
.folders button:hover { background: var(--hover); }
.folders button.current { background: var(--selected); font-weight: 600; }
.folders svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.folders .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folders .count { font-size: 12px; font-weight: 600; color: var(--accent); }

.list-pane {
  grid-area: list; display: flex; flex-direction: column; min-height: 0; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.list-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.list-head h2 { font-size: 16px; }
.list-count { color: var(--muted); font-size: 12px; margin-right: auto; }
.search-note {
  display: flex; gap: 8px; align-items: center; padding: 8px 16px;
  background: var(--accent-soft); font-size: 13px;
}

.messages { list-style: none; margin: 0; padding: 0; }
.messages li {
  display: grid; grid-template-columns: 10px 1fr auto; column-gap: 8px; row-gap: 1px;
  padding: 10px 12px 10px 8px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.messages li:hover { background: var(--hover); }
.messages li.selected { background: var(--selected); }
.messages .dot { grid-row: 1; align-self: center; width: 8px; height: 8px; border-radius: 50%; }
.messages li.unread .dot { background: var(--accent); }
.messages .who { grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages li.unread .who, .messages li.unread .subj { font-weight: 600; }
.messages .when { grid-column: 3; font-size: 12px; color: var(--muted); white-space: nowrap; }
.messages .subj { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .prev { grid-column: 2 / 4; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .marks { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: -2px; color: var(--muted); }
.messages .marks svg { width: 13px; height: 13px; }
.messages .marks .flag { color: var(--flag); }

.empty { margin: 32px 16px; text-align: center; color: var(--muted); }
#more-button { margin: 8px 0 16px; }

.reader-pane { grid-area: reader; min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); padding: 0 12px; }
.reader-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--border-strong); gap: 8px;
}
.reader-empty p { color: var(--muted); margin: 0; }

.reader {
  max-width: 980px; margin: 12px auto 24px; padding: 0 20px 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.toolbar {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin: 0 -20px; padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0;
}
.toolbar-gap { flex: 1; }
.subject { font-size: 20px; line-height: 1.3; margin: 18px 0 14px; overflow-wrap: anywhere; }

.meta { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 16px; background: var(--accent);
}
.meta-lines { flex: 1; min-width: 0; }
.meta-from, .meta-to { overflow-wrap: anywhere; }
.meta-to { font-size: 13px; margin-top: 2px; }
.meta-date { white-space: nowrap; font-size: 13px; }

.banner {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
  padding: 8px 12px; margin-bottom: 12px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--warn); font-size: 13px;
}

.body { border-top: 1px solid var(--border); padding-top: 14px; }
.body iframe { width: 100%; border: 0; display: block; min-height: 120px; background: #fff; border-radius: 4px; }
.body .text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55;
}
.body .text .quote { color: var(--muted); }

.attachments {
  list-style: none; margin: 16px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px;
}
.attachments button {
  display: flex; align-items: center; gap: 8px; max-width: 280px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer; text-align: left;
}
.attachments button:hover { border-color: var(--accent); }
.attachments svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.attachments .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachments .file-size { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* --- окна --- */

dialog {
  padding: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-strong);
}
dialog::backdrop { background: rgba(10, 16, 22, .45); }

.compose { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.compose form { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border);
}
.compose-head h2 { font-size: 16px; }
.compose-fields { padding: 0 18px; }
.compose .row {
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border);
  min-height: 40px;
}
.compose .row > span:first-child { width: 64px; color: var(--muted); flex: none; }
.compose .row input { flex: 1; min-width: 0; height: 38px; border: 0; background: transparent; outline: none; }
.compose .from-address { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.compose textarea {
  flex: 1; min-height: 260px; margin: 0; padding: 14px 18px;
  border: 0; resize: vertical; background: transparent; outline: none;
  font-size: 15px; line-height: 1.55;
}
.compose-note { margin: 0 18px 8px; font-size: 13px; }
.compose-files { list-style: none; margin: 0; padding: 0 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.compose-files li {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); font-size: 13px;
}
.compose-files .icon-btn { width: 22px; height: 22px; }
.compose-files .icon-btn svg { width: 12px; height: 12px; }
#compose-error { margin: 8px 18px 0; }
.compose-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 18px;
  border-top: 1px solid var(--border); margin-top: 8px;
}
.compose-hint { margin-left: auto; font-size: 12px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.raw { width: min(980px, calc(100vw - 24px)); height: min(80vh, 900px); }
.raw[open] { display: flex; flex-direction: column; }
.raw pre {
  flex: 1; margin: 0; padding: 14px 18px; overflow: auto;
  font: 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}

.toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: var(--radius); background: #1f2933; color: #fff;
  box-shadow: var(--shadow-strong); max-width: min(90vw, 560px);
}
.toast.error { background: var(--danger); color: #fff; }

.only-narrow { display: none; }

/* --- узкий экран: одна колонка за раз --- */

@media (max-width: 980px) {
  .app { grid-template-columns: 220px 1fr; grid-template-areas: "top top" "side list"; }
  .reader-pane { display: none; }
  body.show-reader .app { grid-template-areas: "top top" "side reader"; }
  body.show-reader .list-pane { display: none; }
  body.show-reader .reader-pane { display: block; }
  #back-button { display: inline-flex; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "list"; }
  body.show-reader .app { grid-template-areas: "top" "reader"; }
  .sidebar {
    position: fixed; top: var(--topbar); bottom: 0; left: 0; width: 260px; z-index: 5;
    transform: translateX(-100%); transition: transform .15s ease-out; box-shadow: var(--shadow-strong);
  }
  body.show-sidebar .sidebar { transform: none; }
  #menu-button { display: inline-flex; }
  .scrim { position: fixed; inset: var(--topbar) 0 0 0; background: rgba(10, 16, 22, .35); z-index: 4; }
  body.show-sidebar .scrim { display: block; }
  body:not(.show-sidebar) .scrim { display: none; }
  .brand { width: auto; }
  .brand span:last-child, .account-address { display: none; }
  .reader-pane { padding: 0; }
  .reader { margin: 0; border-radius: 0; border-width: 0; padding: 0 12px 16px; }
  .toolbar { margin: 0 -12px; padding: 8px 12px; border-radius: 0; }
  .toolbar .btn { padding: 0 8px; }
  .compose { width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; border-radius: 0; margin: 0; }
  .compose form { max-height: 100%; height: 100%; }
  .compose-hint { display: none; }
}
