:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #f6821f;
  --accent-text: #ffffff;
  --selected: #fff3e8;
  --danger: #d93025;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1b1e24;
    --border: #2c3038;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --selected: #2e2418;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

button, .button, input { font: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.9rem; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--text);
}
button:disabled { opacity: 0.6; cursor: progress; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; }
.ghost:hover { background: var(--selected); }
.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }

input[type="email"], input[type="password"], input[type="search"], input[type="text"] {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus-visible, button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.notice { background: var(--selected); padding: 0.5rem 0.75rem; border-radius: 8px; margin: 0.5rem 0 0; }
.empty { color: var(--muted); padding: 1.5rem; text-align: center; }
.center { margin: auto; }

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand h1 { margin: 0; font-size: 1.5rem; }
.brand.small { min-width: 0; }
.brand.small img, .badge { flex-shrink: 0; }
button, .button { white-space: nowrap; }
.brand.small strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.8rem; font-weight: 600; }

/* Đăng nhập */
.login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem; display: grid; gap: 1rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.06);
}
.card label { display: grid; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; }
.card p { margin: 0; }

/* Ứng dụng */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .actions { display: flex; gap: 0.4rem; }
.panes { flex: 1; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; min-height: 0; }

.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); min-height: 0; }
.search { padding: 0.75rem; border-bottom: 1px solid var(--border); }
.message-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.message-list li button {
  all: unset; box-sizing: border-box; display: grid; gap: 0.15rem; width: 100%;
  padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer;
}
.message-list li button:hover { background: color-mix(in srgb, var(--selected) 60%, transparent); }
.message-list li.active button { background: var(--selected); box-shadow: inset 3px 0 var(--accent); }
.message-list .row { display: flex; justify-content: space-between; gap: 0.5rem; }
.message-list .from, .message-list .subject, .message-list .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-list .time { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }
.message-list .subject { font-size: 0.92rem; }
.message-list .snippet { color: var(--muted); font-size: 0.85rem; }
.message-list li.unread .from, .message-list li.unread .subject { font-weight: 700; }
.message-list li.unread .from::before { content: "● "; color: var(--accent); }
.load-more { margin: 0.75rem; }

.reader { display: flex; min-height: 0; min-width: 0; }
.reader article { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
.reader-head { padding: 1rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.reader-head h2 { margin: 0 0 0.5rem; font-size: 1.25rem; word-break: break-word; }
.back { display: none; margin-bottom: 0.5rem; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0 0 0.75rem; font-size: 0.88rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.toolbar .spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; color: var(--muted); cursor: pointer; }
.attachments { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attachments a {
  display: inline-flex; gap: 0.4rem; align-items: center; padding: 0.35rem 0.7rem;
  border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem; color: var(--text); text-decoration: none;
}
.attachments a:hover { border-color: var(--accent); }
.attachments .size { color: var(--muted); }

#r-html { flex: 1; width: 100%; border: 0; background: #fff; min-height: 0; }
.plain { flex: 1; margin: 0; padding: 1.25rem; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 0.92rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 760px) {
  .panes { grid-template-columns: 1fr; }
  .app.reading .list-pane { display: none; }
  .app:not(.reading) .reader { display: none; }
  .back { display: inline-flex; }
  .list-pane { border-right: 0; }
  .topbar { padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .topbar .actions button { padding: 0.4rem 0.6rem; }
}
