:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --muted-bg: #f3f4f6;
  --hover: #f5f7fa;
  --selected: #eef2f7;
  --border: #e5e7eb;
  --field-border: #94a3b8;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;
  --blue: #1a8cff;
  --blue-2: #0b6ad9;
  --red: #e03131;
  --green: #16a34a;
  --amber: #d97706;
  --radius: 6px;
  color-scheme: light;
}
body.dark {
  --bg: #0f141b;
  --panel: #141a22;
  --muted-bg: #1a212b;
  --hover: #1c2430;
  --selected: #213044;
  --border: #283240;
  --field-border: #475569;
  --text: #e5e7eb;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --faint: #64748b;
  color-scheme: dark;
}
* { 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;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* ---------- đăng nhập ---------- */
.login {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 110px 16px 40px;
}
.envelope { width: 104px; height: 76px; color: var(--text); fill: none; margin-bottom: 70px; }
.login-form { width: 100%; max-width: 425px; display: flex; flex-direction: column; gap: 26px; }
.field {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 57px;
  padding: 0 16px;
  border: 2px solid var(--field-border);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color .15s, box-shadow .15s;
}
.field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26, 140, 255, .15); }
.field .ico { width: 22px; height: 22px; fill: #9e9e9e; }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; }
.field input::placeholder { color: #8d99ab; }
.error { min-height: 18px; margin: -14px 0 -10px; color: var(--red); font-size: 13px; }
.primary {
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: .65; cursor: default; }
.primary.big { height: 57px; font-size: 17px; }
.primary.small { height: 28px; padding: 0 11px; font-size: 13px; border-radius: 4px; }
.primary.small svg { width: 14px; height: 14px; }

/* ---------- khung ứng dụng ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 54px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 600; white-space: nowrap; }
.brand svg { width: 20px; height: 20px; }
.top-right { display: flex; align-items: center; gap: 16px; min-width: 0; }
.me { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { padding: 2px 8px; border-radius: 10px; background: #fff3cd; color: #8a5a00; font-size: 12px; white-space: nowrap; }
.langs { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--faint); }
.link.active { color: var(--blue); font-weight: 600; }
.sep { color: var(--faint); }
.icon-btn { border: 0; background: none; padding: 4px; color: var(--text-2); display: inline-flex; border-radius: 4px; }
.icon-btn:hover { background: var(--hover); }
.danger {
  border: 0;
  border-radius: 4px;
  background: var(--red);
  color: #fff;
  height: 28px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}
.danger svg { width: 15px; height: 15px; }
.danger:hover { filter: brightness(1.08); }

.layout { flex: 1; min-height: 0; display: flex; }
.list-pane { width: 375px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); }
.list-head { height: 46px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--border); }
.box-title { display: flex; align-items: center; gap: 2px; font-weight: 600; }
.box-title select { border: 0; background: transparent; font-weight: 600; padding: 2px 2px; cursor: pointer; outline: none; }
.box-title select option { background: var(--panel); color: var(--text); }
.count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--blue); color: #fff; font-size: 12px; text-align: center; }
.pager { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; color: var(--text-2); font-size: 13px; border-bottom: 1px solid var(--border); }
.pager-btns { display: flex; gap: 8px; }
.pg { width: 28px; height: 28px; border: 0; border-radius: 4px; background: var(--muted-bg); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.pg svg { width: 16px; height: 16px; }
.pg:disabled { opacity: .45; cursor: default; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--selected); }
.item .row1 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item .subject { font-size: 15px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .subject { font-weight: 700; color: var(--text); }
.item .date { color: var(--faint); font-size: 12px; white-space: nowrap; }
.item .from { margin-top: 6px; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .preview { margin-top: 4px; color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list-empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.view-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.view-head { min-height: 70px; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--muted-bg); border-bottom: 1px solid var(--border); }
.view-head h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.ghost { border: 1px solid var(--border); background: var(--panel); border-radius: 4px; height: 30px; padding: 0 10px; display: inline-flex; align-items: center; gap: 4px; }
.danger-text { color: var(--red); }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 4px; }
.empty svg { width: 54px; height: 54px; fill: #8b8f96; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.meta { display: grid; grid-template-columns: 56px 1fr; gap: 4px 10px; margin: 0; padding: 14px 24px; border-bottom: 1px solid var(--border); font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; color: var(--text-2); word-break: break-all; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 24px; border-bottom: 1px solid var(--border); }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 14px; color: var(--text-2); text-decoration: none; font-size: 12.5px; }
.att:hover { border-color: var(--blue); color: var(--blue); }
.frame { flex: 1; width: 100%; border: 0; background: #fff; }
.text { flex: 1; margin: 0; padding: 16px 24px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 6px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10; }

@media (max-width: 820px) {
  .topbar { padding: 0 10px 0 4px; }
  .brand span { font-size: 15px; }
  .me, .langs, .badge { display: none; }
  .list-pane { width: 100%; border-right: 0; }
  .view-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .view-pane { display: flex; }
  .back { display: inline-flex; }
  .view-head { padding: 0 12px; min-height: 56px; }
  .login { padding-top: 70px; }
  .envelope { margin-bottom: 48px; }
}

/* ---------- trang quản trị ---------- */
.admin-main { flex: 1; overflow: auto; padding: 22px; background: var(--muted-bg); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; max-width: 1280px; margin: 0 auto 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 18px; max-width: 1280px; margin: 0 auto 18px; }
.grid .card { margin: 0; }
.card h2 { margin: 0 0 14px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h2 .input { font-weight: 400; font-size: 14px; }
.card .hint { color: var(--muted); font-size: 12.5px; margin: -6px 0 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.input { height: 36px; padding: 0 10px; border: 1px solid var(--field-border); border-radius: 4px; background: var(--panel); min-width: 0; }
.input:focus { outline: 2px solid rgba(26,140,255,.3); border-color: var(--blue); }
.input.grow { flex: 1; }
.suffix { color: var(--muted); }
.btn { height: 36px; padding: 0 14px; border-radius: 4px; }
.btn.secondary { border: 1px solid var(--border); background: var(--panel); }
.result { margin-top: 10px; padding: 10px 12px; border-radius: 6px; background: var(--muted-bg); font-family: Consolas, Menlo, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
textarea.result { width: 100%; min-height: 140px; border: 1px solid var(--border); resize: vertical; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.mono { font-family: Consolas, Menlo, monospace; word-break: break-all; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.mini { height: 26px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); font-size: 12px; white-space: nowrap; }
.mini:hover { border-color: var(--blue); color: var(--blue); }
.mini.red:hover { border-color: var(--red); color: var(--red); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.bad { background: #fee2e2; color: #991b1b; }
.pill.warn { background: #fef3c7; color: #92400e; }
body.dark .pill.ok { background: #14532d; color: #bbf7d0; }
body.dark .pill.bad { background: #7f1d1d; color: #fecaca; }
body.dark .pill.warn { background: #78350f; color: #fde68a; }
.dns-val { font-family: Consolas, Menlo, monospace; font-size: 12px; word-break: break-all; max-width: 520px; }
.small-muted { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv b { font-weight: 600; }
