:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --hover: #eef1f5;
  --selected: #e3ebfb;
  --border: #e3e6eb;
  --text: #16191f;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #e6edfc;
  --danger: #c2261d;
  --star: #e3a008;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 10px;
  --font: 'Noto Sans Georgian', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #181b20;
    --surface-2: #1f2329;
    --hover: #22262d;
    --selected: #1e2b44;
    --border: #2a2f37;
    --text: #e8eaee;
    --text-2: #b4bac4;
    --muted: #8b929d;
    --accent: #6d9cff;
    --accent-hover: #8fb3ff;
    --accent-soft: #1d2a45;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
kbd { font-family: ui-monospace, monospace; font-size: 11px; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0b1220; } }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--hover); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-block { width: 100%; }
.btn svg { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.active { color: var(--star); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.link-btn { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--text-2); cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.link-btn:hover { color: var(--text); background: var(--hover); }
.link-btn.small { font-size: 12px; padding: 2px 6px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- brand ---------- */
.brand { font-weight: 700; font-size: 19px; letter-spacing: -.02em; }
.brand span { color: var(--accent); font-weight: 600; margin-left: 1px; }
.brand-lg { font-size: 28px; }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 252px minmax(320px, 400px) 1fr;
  height: 100vh; height: 100dvh;
}
.scrim { display: none; }

.sidebar {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 12px 12px; background: var(--bg); border-right: 1px solid var(--border);
  overflow-y: auto; min-height: 0;
}
.sidebar-head { padding: 2px 8px 12px; }
.compose-btn { height: 40px; margin: 0 4px 12px; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item, .acc-item, .folder-item {
  display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 6px 10px;
  border-radius: 8px; color: var(--text); text-decoration: none; cursor: pointer; user-select: none;
}
.nav-item svg { color: var(--text-2); }
.nav-item:hover, .acc-item:hover, .folder-item:hover { background: var(--hover); }
.nav-item.active, .acc-item.active, .folder-item.active { background: var(--selected); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.count-muted { color: var(--muted); font-weight: 500; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 4px 4px 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.section-title .icon-btn { width: 28px; height: 28px; }
.section-title svg { width: 16px; height: 16px; }

.accounts { display: flex; flex-direction: column; gap: 1px; }
.acc-item { padding-left: 6px; }
.acc-toggle { display: grid; place-items: center; width: 18px; height: 18px; border: 0; padding: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px; }
.acc-toggle:hover { color: var(--text); }
.acc-toggle svg { width: 14px; height: 14px; transition: transform .15s; }
.acc-item.open .acc-toggle svg { transform: rotate(90deg); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.acc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-err { color: var(--danger); font-size: 12px; font-weight: 700; }
.folders { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 6px; }
.folder-item { min-height: 30px; padding: 4px 10px 4px 40px; font-size: 13px; color: var(--text-2); }
.folder-item.active { color: var(--text); }
.empty-accounts { padding: 8px 10px; color: var(--muted); font-size: 13px; }

.sidebar-foot { margin-top: auto; padding-top: 12px; display: flex; justify-content: space-between; border-top: 1px solid var(--border); }
.sidebar-foot svg { width: 16px; height: 16px; }

/* ---------- list ---------- */
.list-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 8px 18px; }
.pane-title { flex: 1; min-width: 0; }
.pane-title h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-sub { font-size: 12px; color: var(--muted); min-height: 16px; }
.only-narrow { display: none; }

.search { position: relative; margin: 0 12px 8px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--surface); }

.list { flex: 1; overflow-y: auto; min-height: 0; outline: none; }
.msg {
  position: relative; display: grid; grid-template-columns: 1fr auto; column-gap: 8px; row-gap: 1px;
  padding: 10px 14px 11px 20px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.msg::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--acc, transparent); opacity: .85; }
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
.msg-from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-date { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; align-self: center; }
.msg-subject { grid-column: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-icons { grid-column: 2; display: flex; justify-content: flex-end; align-items: center; gap: 4px; color: var(--muted); }
.msg-icons svg { width: 14px; height: 14px; }
.msg-icons .star { color: var(--star); fill: var(--star); }
.msg-snippet { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-acc { font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.msg.unread .msg-from { color: var(--text); font-weight: 700; }
.msg.unread .msg-subject { color: var(--text); font-weight: 600; }
.msg.unread .msg-date { color: var(--accent); font-weight: 600; }
.msg.unread::after { content: ''; position: absolute; left: 9px; top: 17px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.list-status { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.list-status .btn { margin-top: 8px; }

.skeleton { padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--border); }
.skeleton div { height: 10px; border-radius: 4px; background: var(--surface-2); margin: 6px 0; animation: pulse 1.2s ease-in-out infinite; }
.skeleton div:nth-child(1) { width: 40%; }
.skeleton div:nth-child(2) { width: 75%; }
.skeleton div:nth-child(3) { width: 90%; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- reader ---------- */
.reader-pane { min-width: 0; min-height: 0; overflow-y: auto; background: var(--surface); }
.empty-reader { height: 100%; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); }
.empty-reader svg { width: 64px; height: 64px; stroke-width: 1.2; opacity: .6; }

.reader { max-width: 980px; margin: 0 auto; padding: 0 24px 40px; }
.reader-toolbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 10px 0; background: var(--surface); border-bottom: 1px solid var(--border);
}
.reader-toolbar .spacer { flex: 1; }
.reader-toolbar .btn { height: 34px; padding: 0 12px; }
.reader-subject { margin: 20px 0 14px; font-size: 22px; line-height: 1.3; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.reader-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 15px; }
.reader-meta { flex: 1; min-width: 0; font-size: 13px; color: var(--text-2); }
.reader-from { font-size: 14.5px; color: var(--text); overflow-wrap: anywhere; }
.reader-from strong { font-weight: 600; }
.reader-from .addr { color: var(--muted); }
.reader-meta .line { overflow-wrap: anywhere; }
.reader-date { font-size: 12.5px; color: var(--muted); white-space: nowrap; text-align: right; }
.acc-badge { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; padding: 1px 8px 1px 6px; border-radius: 99px; background: var(--surface-2); font-size: 12px; color: var(--text-2); }

.images-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; margin-bottom: 12px;
  border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--text-2);
}
.mail-frame-wrap { border-radius: 8px; overflow: hidden; background: #fff; }
.mail-frame { display: block; width: 100%; border: 0; min-height: 40px; background: #fff; }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; margin: 0; font-family: var(--font); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; }
.attachment {
  display: inline-flex; align-items: center; gap: 10px; max-width: 280px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); text-decoration: none; color: var(--text); background: var(--surface);
}
.attachment:hover { background: var(--hover); }
.attachment svg { color: var(--text-2); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.att-size { font-size: 11.5px; color: var(--muted); }

.back-btn { display: none; }

/* ---------- dialogs ---------- */
.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 14, 22, .45); }
.dialog-wide { width: min(720px, calc(100vw - 32px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.dialog-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h3 { margin: 8px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); }
.field input, .field select, .field textarea, .inline-form input {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); outline: none;
}
.field textarea { height: auto; min-height: 70px; padding: 8px 12px; resize: vertical; }
.field input:focus, .field textarea:focus, .inline-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 96px; gap: 10px; margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; line-height: 1.55; }
.advanced summary { cursor: pointer; font-size: 13px; color: var(--text-2); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 140px; }

/* compose */
.dialog-compose { width: min(760px, calc(100vw - 32px)); }
.dialog-compose form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.compose-fields { padding: 4px 20px 0; }
.row-field { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); min-height: 42px; }
.row-field > span { width: 52px; font-size: 13px; color: var(--muted); flex: none; }
.row-field input, .row-field select { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; height: 40px; }
.row-field select { cursor: pointer; }
.row-field select option { background: var(--surface); }
.compose-body { flex: 1; min-height: 280px; padding: 14px 20px; border: 0; resize: none; outline: none; background: transparent; line-height: 1.6; }
.compose-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px; }
.compose-attachments:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--surface-2); font-size: 12.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; }
.chip button:hover { background: var(--hover); color: var(--text); }
.dialog-foot label.btn { cursor: pointer; }

/* settings accounts */
.set-acc { display: grid; grid-template-columns: auto 1fr auto; gap: 10px 12px; align-items: start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.set-acc + .set-acc { margin-top: 8px; }
.set-acc input[type=color] { width: 30px; height: 30px; padding: 0; border: 0; background: none; cursor: pointer; }
.set-acc-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.set-acc-main .email { font-weight: 600; overflow-wrap: anywhere; }
.set-acc-main .server { font-size: 12px; color: var(--muted); }
.set-acc-main .error { font-size: 12px; color: var(--danger); overflow-wrap: anywhere; }
.set-acc-main input, .set-acc-main textarea { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); outline: none; }
.set-acc-main textarea { min-height: 54px; resize: vertical; }
.set-acc-actions { display: flex; flex-direction: column; gap: 6px; }
.set-acc-actions .btn { height: 32px; padding: 0 12px; font-size: 13px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 13.5px; box-shadow: var(--shadow);
  transition: opacity .18s, transform .18s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { margin-left: 12px; border: 0; background: none; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

/* login */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 32px 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.login-card p { margin: -8px 0 6px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 240px 1fr; }
  .app[data-pane="list"] .reader-pane { display: none; }
  .app[data-pane="reader"] .list-pane { display: none; }
  .back-btn { display: inline-grid; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .only-narrow { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; background: var(--surface);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 19; background: rgba(10, 14, 22, .4); }
  .pane-head { padding-left: 8px; }
  .reader { padding: 0 16px 32px; }
  .reader-subject { font-size: 19px; }
  .reader-head { flex-wrap: wrap; }
  .reader-date { order: 3; width: 100%; padding-left: 52px; text-align: left; margin-top: -10px; }
  .reader-toolbar .btn-label { display: none; }
  .grid-2 { grid-template-columns: 1fr 80px; }
  .set-acc { grid-template-columns: auto 1fr; }
  .set-acc-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .dialog-compose { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .dialog-compose form { height: 100%; max-height: none; }
}
