/* --------------------------------------------------------------------------
   Webmail - stylesheet
   Layout: topbar + 3 columns (folders / list / reader), collapsing on narrow
   screens. Colours live in custom properties so the dark theme is a token swap.
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eceff5;
  --border: #dfe3ec;
  --border-strong: #c8cede;
  --text: #171a20;
  --text-soft: #5c6474;
  --text-faint: #8a93a5;
  --accent: #2456d6;
  --accent-soft: #e6edfd;
  --accent-text: #ffffff;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warning: #a86400;
  --shadow: 0 1px 2px rgba(16, 22, 38, .06), 0 8px 24px rgba(16, 22, 38, .08);
  --radius: 10px;
  --radius-sm: 7px;
  --topbar-h: 56px;
  --sidebar-w: 232px;
  --list-w: 380px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1c2029;
    --surface-3: #232833;
    --border: #2a303c;
    --border-strong: #3a4252;
    --text: #e8ebf2;
    --text-soft: #a3abbb;
    --text-faint: #767f92;
    --accent: #6d97ff;
    --accent-soft: #1e2a47;
    --accent-text: #0b0e14;
    --danger: #ff7b72;
    --danger-soft: #38191a;
    --warning: #e0a656;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

/* Several elements below are laid out with flex, which would otherwise win over
   the `hidden` attribute the scripts toggle. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* -------------------------------------------------------------- buttons -- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-weight: 500;
  line-height: 1.2;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { border-color: var(--border); background: var(--surface); color: var(--text-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-danger { border-color: var(--border); background: var(--surface); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-block { width: 100%; }
.btn-small { padding: 5px 9px; font-size: 13px; }
.btn-icon { padding: 6px 9px; font-size: 16px; line-height: 1; }

.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--accent); cursor: pointer; font-size: 13px;
}
.link-btn:hover { text-decoration: underline; }

input[type="text"], input[type="password"], input[type="search"], input[type="email"], textarea, select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select-small { width: auto; padding: 5px 8px; font-size: 13px; }

/* ---------------------------------------------------------------- login -- */
.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 0%, var(--accent-soft), var(--bg) 55%);
}
.auth-card {
  width: min(400px, 100%);
  padding: 30px 30px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { font-size: 34px; display: block; }
.auth-brand h1 { margin: 6px 0 2px; font-size: 21px; letter-spacing: -.01em; }
.auth-server { margin: 0; color: var(--text-faint); font-size: 13px; }
.auth-form { display: grid; gap: 6px; }
.auth-form label { font-size: 13px; color: var(--text-soft); margin-top: 8px; }
.auth-form .btn { margin-top: 18px; padding: 10px; }
.auth-note { margin: 20px 0 0; font-size: 12px; line-height: 1.55; color: var(--text-faint); }

.alert {
  padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* --------------------------------------------------------------- topbar -- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; width: calc(var(--sidebar-w) - 16px); }
.brand-mark { font-size: 20px; color: var(--accent); }
.brand-name { font-weight: 650; letter-spacing: -.01em; }

.search { flex: 1; display: flex; gap: 6px; max-width: 620px; }
.search input { background: var(--surface-2); }

.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.account-address {
  font-size: 13px; color: var(--text-soft);
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --------------------------------------------------------------- layout -- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  height: calc(100vh - var(--topbar-h));
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  overflow-y: auto;
}
.folders { display: flex; flex-direction: column; gap: 1px; margin-top: 6px; flex: 1; }
.folder {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 0; background: none;
  border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; width: 100%;
  color: var(--text-soft);
}
.folder:hover { background: var(--surface-3); color: var(--text); }
.folder.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-icon { width: 18px; text-align: center; flex: none; }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-badge {
  flex: none; font-size: 11px; font-weight: 700;
  background: var(--accent); color: var(--accent-text);
  padding: 1px 6px; border-radius: 9px;
}
.folder[data-depth="1"] { padding-left: 26px; }
.folder[data-depth="2"] { padding-left: 40px; }

/* ------------------------------------------------------------ list pane -- */
.list-pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-width: 0;
}
.list-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.checkbox { display: inline-flex; align-items: center; }
.filters { display: flex; gap: 4px; }
.chip {
  border: 1px solid transparent; background: none; cursor: pointer;
  padding: 4px 10px; border-radius: 99px; font-size: 13px; color: var(--text-soft);
}
.chip:hover { background: var(--surface-3); }
.chip.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.bulk-actions {
  display: flex; gap: 5px; flex-wrap: wrap; width: 100%;
  padding-top: 8px; border-top: 1px solid var(--border);
}
.bulk-actions .select-small { min-width: 0; flex: 1 1 90px; }

.list-status { padding: 7px 12px; font-size: 12px; color: var(--text-faint); border-bottom: 1px solid var(--border); }

.messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.message-row {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.message-row:hover { background: var(--surface-2); }
.message-row.is-selected { background: var(--accent-soft); }
.message-row.is-unread .message-from,
.message-row.is-unread .message-subject { font-weight: 700; color: var(--text); }
.message-row.is-unread { border-left: 3px solid var(--accent); padding-left: 9px; }

.message-star {
  border: 0; background: none; cursor: pointer; padding: 0 2px;
  color: var(--text-faint); font-size: 15px; line-height: 1.3;
}
.message-star.is-on { color: var(--warning); }

.message-main { min-width: 0; }
.message-from, .message-subject, .message-meta {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-from { color: var(--text-soft); font-size: 13px; }
.message-subject { color: var(--text); margin-top: 1px; }
.message-meta { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.message-side { text-align: right; font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.message-clip { display: block; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--text-faint); }

.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft); background: var(--surface-2);
}

/* ---------------------------------------------------------- reader pane -- */
.reader-pane {
  display: flex; flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  min-width: 0;
}
.reader-empty {
  margin: auto; text-align: center; color: var(--text-faint);
}
.reader-empty-mark { font-size: 44px; display: block; opacity: .5; }

.reader-toolbar {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 9px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.reader-scroll { overflow-y: auto; flex: 1; padding: 18px 20px 40px; }

.reader-subject { margin: 0 0 12px; font-size: 19px; line-height: 1.3; letter-spacing: -.01em; }
.reader-meta { display: grid; gap: 3px; font-size: 13px; color: var(--text-soft); margin-bottom: 14px; }
.reader-meta .row { display: flex; gap: 8px; }
.reader-meta .label { color: var(--text-faint); min-width: 46px; flex: none; }
.reader-meta .value { min-width: 0; word-break: break-word; }

.reader-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--text-soft);
}

.reader-body {
  width: 100%; border: 0; background: #fff;
  border-radius: var(--radius-sm);
  min-height: 220px;
}

.attachments { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.attachments h3 { margin: 0 0 8px; font-size: 13px; color: var(--text-faint); font-weight: 600; }
.attachment-grid { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.attachment {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); max-width: 100%;
}
.attachment-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
  color: var(--text);
}
.attachment-size { color: var(--text-faint); font-size: 12px; flex: none; }
.attachment a { color: var(--accent); text-decoration: none; font-size: 13px; flex: none; }
.attachment a:hover { text-decoration: underline; }

/* -------------------------------------------------------------- compose -- */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 13, 20, .45); }

.compose { width: min(720px, 94vw); max-height: 92vh; }
.compose form { display: flex; flex-direction: column; max-height: 92vh; }
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.compose-head h2 { margin: 0; font-size: 15px; }
.compose-body { padding: 14px 16px; overflow-y: auto; display: grid; gap: 10px; }
.field { display: flex; align-items: center; gap: 10px; }
.field label { width: 58px; flex: none; font-size: 13px; color: var(--text-soft); }
.field-static span { font-size: 13px; color: var(--text-soft); }
/* ------------------------------------------------------------ rich editor -- */
.editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.editor-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 5px 6px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.tool {
  min-width: 28px; height: 28px; padding: 0 7px;
  border: 1px solid transparent; border-radius: 5px;
  background: none; cursor: pointer; color: var(--text-soft);
  font-size: 13px; line-height: 1;
}
.tool:hover { background: var(--surface-3); color: var(--text); }
.tool.is-on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.tool b, .tool i, .tool u, .tool s { font-size: 13px; }
.tool-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.tool-mode { margin-left: auto; font-size: 12px; padding: 0 9px; }

.editor-area {
  min-height: 230px; max-height: 46vh; overflow-y: auto;
  padding: 12px 13px;
  border: 0; border-radius: 0;
  background: var(--surface);
  font: 14px/1.6 var(--font);
  outline: none;
  width: 100%;
}
.editor-area:focus { box-shadow: none; }
textarea.editor-plain { resize: vertical; display: block; }

/* Placeholder for the contenteditable, which has none of its own. */
#compose-rich:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}
#compose-rich > *:first-child { margin-top: 0; }
#compose-rich p { margin: 0 0 .7em; }
#compose-rich ul, #compose-rich ol { margin: 0 0 .7em; padding-left: 1.6em; }
#compose-rich a { color: var(--accent); }
#compose-rich blockquote {
  margin: 0 0 .7em; padding: 2px 0 2px .9em;
  border-left: 3px solid var(--border-strong); color: var(--text-soft);
}
#compose-rich pre {
  margin: 0 0 .7em; padding: 9px 11px;
  background: var(--surface-3); border-radius: var(--radius-sm);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap; word-wrap: break-word;
}
#compose-rich img { max-width: 100%; height: auto; }
.compose-attachments { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.compose-attachments > label { cursor: pointer; }
.attachment-chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.attachment-chips li {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-3); border-radius: 99px; padding: 4px 6px 4px 10px; font-size: 12px;
}
.attachment-chips button {
  border: 0; background: none; cursor: pointer; color: var(--text-faint); font-size: 14px; line-height: 1;
}
.attachment-chips button:hover { color: var(--danger); }

.compose-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.compose-status { font-size: 13px; color: var(--text-faint); margin-left: auto; }

.confirm { width: min(420px, 92vw); padding: 20px; }
.confirm p, .confirm label { margin: 0 0 14px; display: block; font-size: 14px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* --------------------------------------------------------------- toasts -- */
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 13px; max-width: 380px;
  animation: toast-in .16s ease;
}
.toast.is-error { border-color: var(--danger); color: var(--danger); }
.toast.is-ok { border-color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.is-busy { opacity: .55; pointer-events: none; }

.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- responsive -- */
@media (max-width: 1100px) {
  :root { --list-w: 320px; --sidebar-w: 200px; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .sidebar {
    flex-direction: row; align-items: center; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar .folders { flex-direction: row; flex: 1; }
  .sidebar .btn-block { width: auto; flex: none; }
  .folder { width: auto; }
  .folder[data-depth] { padding-left: 10px; }
  .list-pane { border-right: 0; max-height: 55vh; }
  .reader-pane { border-top: 1px solid var(--border); }
  .brand-name { display: none; }
  .brand { width: auto; }
  .account-address { display: none; }
}
