:root {
  --brand: #0e7fb8;
  --brand-deep: #0b6a9a;
  --brand-soft: #e3f3fc;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #5f6b77;
  --line: #e2e8ef;
  --ok: #15803d;
  --ok-soft: #e3f6ea;
  --warn: #b45309;
  --warn-soft: #fdf2e0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4ec5ff;
    --brand-deep: #8ad8ff;
    --brand-soft: #10293a;
    --bg: #0f1419;
    --surface: #182029;
    --text: #e8eef3;
    --muted: #9aa8b5;
    --line: #2a3541;
    --ok: #6ee7a0;
    --ok-soft: #12301f;
    --warn: #fbbf6a;
    --warn-soft: #33240f;
    --danger: #ff9b8f;
    --danger-soft: #3a1814;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* khung */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; padding: 4px 10px 18px; }
.logo img { width: 28px; height: 28px; }
.side a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.side a:hover { background: var(--bg); }
.side a.on { background: var(--brand-soft); color: var(--brand); }
.side .grow { flex: 1; }
.side .who { font-size: 12px; color: var(--muted); padding: 8px 12px; word-break: break-all; }
.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* thẻ, bảng */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.stat .n { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--bg); }
tr.unread td:first-child { box-shadow: inset 3px 0 var(--brand); }
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* nhãn */
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill.new { background: var(--brand-soft); color: var(--brand); }
.pill.replied { background: var(--ok-soft); color: var(--ok); }
.pill.archived { background: var(--bg); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* điều khiển */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06202e; } }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
input[type=text], input[type=email], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
textarea { min-height: 220px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--brand-soft); color: var(--brand); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 13px; color: var(--muted); }

/* chi tiết */
.detail { display: grid; gap: 14px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.msg-body { white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: 10px; padding: 14px; line-height: 1.6; }
.back { display: inline-flex; gap: 6px; margin-bottom: 12px; font-weight: 600; text-decoration: none; }

/* biểu đồ đăng ký */
.bars { display: flex; align-items: end; gap: 3px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars .bar:hover { opacity: 1; }
.bars-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; display: grid; gap: 16px; }
.login .logo { padding: 0; }
.note { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.err { background: var(--danger-soft); color: var(--danger); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .logo { padding: 4px 8px; width: 100%; }
  .side .grow, .side .who { display: none; }
  .side a { padding: 7px 10px; font-size: 14px; }
  .main { padding: 18px 16px 48px; }
  .two { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

.gbtn { min-height: 44px; display: flex; justify-content: center; }
.side .group { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 12px 4px; }
@media (max-width: 860px) { .side .group { display: none; } }
