/* MailVN – CSS hợp nhất từ giao diện gốc (MailVN_ISO_MASTER.html, L1 & L26),
   gom về một bộ token, bỏ !important, thang z-index cố định. */
:root {
  --bg: #f5f8fd;
  --surface: #fff;
  --surface-2: #f8fbff;
  --ink: #13234b;
  --ink-2: #172b4d;
  --muted: #71809b;
  --line: #e3eaf5;
  --line-2: #e9eff7;
  --primary: #0866ff;
  --primary-ink: #1754a0;
  --primary-soft: #eaf1fc;
  --primary-softer: #e4f0ff;
  --ok: #16874c;
  --ok-soft: #e5f8ee;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --danger: #c62f3f;
  --danger-soft: #fdecee;
  --radius: 12px;
  --radius-lg: 19px;
  --shadow: 0 10px 30px #24518a0c;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  /* z-index: base 0 · sticky 10 · compose 100 · menu 200 · overlay 1000 · toast 1100 */
  --z-compose: 100; --z-menu: 200; --z-overlay: 1000; --z-toast: 1100;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1 { font-size: 29px; margin: 0; line-height: 1.2; }
h2 { font-size: 21px; margin: 0 0 var(--space-3); }
h3 { font-size: 16px; margin: 0 0 var(--space-3); }
.muted { color: var(--muted); }
.primary-text { color: var(--primary); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.hidden { display: none !important; } /* tiện ích duy nhất được phép dùng !important */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Nút ---------- */
button, .btn {
  border: 0; border-radius: var(--radius); padding: 10px 15px; background: var(--primary-soft); color: var(--primary-ink);
  cursor: pointer; transition: transform .15s, box-shadow .15s, background .15s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
button:hover:not(:disabled), .btn:hover { transform: translateY(-1px); box-shadow: 0 7px 18px #12233322; }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid #0866ff55; outline-offset: 2px; }
.blue, .btn.blue { background: var(--primary); color: #fff; }
.ghost { background: transparent; }
.danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 6px 10px; min-height: 32px; font-size: 13px; }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* ---------- Form ---------- */
input, select, textarea { border: 1px solid #dce5f2; border-radius: 11px; padding: 11px 12px; background: var(--surface); width: 100%; }
textarea { resize: vertical; min-height: 90px; }
input[type=checkbox], input[type=radio] { width: auto; }
.field { display: block; margin: var(--space-3) 0; }
.field > span { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.field .hint { display: block; margin-top: 4px; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.check { display: flex; gap: 8px; align-items: center; margin: var(--space-3) 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.input-suffix { display: flex; align-items: center; gap: 6px; }
.input-suffix span { color: var(--muted); white-space: nowrap; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: var(--space-3) 0; }
.search { max-width: 420px; }

/* ---------- Bố cục quản trị ---------- */
.layout { display: flex; min-height: 100vh; }
.side { width: 230px; flex-shrink: 0; background: var(--surface); padding: 24px 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: block; width: 145px; max-height: 45px; margin: 0 9px 23px; }
.nav { display: flex; width: 100%; text-align: left; margin: 2px 0; background: transparent; justify-content: flex-start; }
.nav.on { background: var(--primary-softer); color: var(--primary); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; }
.side .spacer { flex: 1; }
.side .who { padding: 10px 9px; border-top: 1px solid var(--line-2); margin-top: 10px; font-size: 13px; }
.main { padding: 25px; flex: 1; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.top p { margin: 4px 0 0; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 19px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 15px; }
.grid > .panel { margin-top: 0; }
a.card { color: inherit; text-decoration: none; display: block; transition: border-color .15s, box-shadow .15s; }
a.card:hover { border-color: #bed2f1; box-shadow: 0 12px 30px #24518a1a; }
a.card .metric { color: var(--primary); }
.metric { font-size: 29px; font-weight: 800; }
.grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 15px; margin-top: 15px; }
.line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.line:last-child { border-bottom: 0; }

.pill { display: inline-block; background: var(--ok-soft); color: var(--ok); border-radius: 30px; padding: 3px 10px; font-size: 12.5px; white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.gray { background: #eef2f8; color: var(--muted); }

.bar { height: 8px; background: #eef2f8; border-radius: 8px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 8px; }
.bar.warn > i { background: #e6a100; }
.bar.bad > i { background: var(--danger); }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.table tr.click { cursor: pointer; }
.table tr.click:hover { background: #f4f8ff; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* Wizard bước (từ mv50) */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 20px 0; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.step b { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); margin-bottom: 8px; }
.step.on { border-color: var(--primary); box-shadow: 0 0 0 3px #0866ff22; }
.step.done b { background: var(--ok-soft); color: var(--ok); }

.dns-row { display: grid; grid-template-columns: 70px 1fr 2fr auto; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.dns-row .mono { background: var(--surface-2); padding: 6px 8px; border-radius: 8px; }

/* ---------- Trang khách ---------- */
.public { max-width: 1200px; margin: auto; padding: 22px; }
.public-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.hero { background: linear-gradient(120deg, #e7f2ff, #fff); padding: 50px; border-radius: 26px; display: grid; grid-template-columns: 1.1fr 1fr; gap: 25px; align-items: center; }
.hero h1 { font-size: clamp(32px, 4vw, 52px); }
.hero p { font-size: 16px; color: #3c4c6b; }
.hero img { width: 100%; height: auto; border-radius: 18px; }
.auth { max-width: 460px; margin: 7vh auto; padding: 30px; background: var(--surface); border-radius: 24px; box-shadow: 0 20px 55px #24518a18; }
.auth .brand { margin: 0 0 22px; }
.auth h1 { font-size: 24px; margin-bottom: 6px; }
.auth .links { display: flex; justify-content: space-between; margin-top: 14px; font-size: 13px; }
.guide h2 { margin-top: 28px; }
.guide li { margin: 6px 0; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: #12233388; display: grid; place-items: center; padding: 15px; z-index: var(--z-overlay); }
.modal { background: var(--surface); border-radius: 22px; padding: 25px; width: min(520px, 100%); max-height: 92vh; overflow: auto; animation: up .2s; }
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.secret-box { background: var(--warn-soft); padding: 12px; border-radius: 10px; font-size: 18px; letter-spacing: 1px; text-align: center; user-select: all; }
#toast { position: fixed; right: 20px; bottom: 20px; z-index: var(--z-toast); display: grid; gap: 8px; }
#toast .t { background: #152b54; color: #fff; padding: 13px 20px; border-radius: 12px; max-width: 380px; animation: up .2s; }
#toast .t.err { background: var(--danger); }
@keyframes up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Webmail (từ L26, mv32, mv39) ---------- */
.mail-layout { display: flex; height: 100vh; overflow: hidden; background: var(--surface); color: var(--ink-2); }
.mail-side { width: 235px; flex-shrink: 0; background: var(--surface-2); border-right: 1px solid #e5ebf5; padding: 18px 12px; overflow: auto; display: flex; flex-direction: column; }
.mail-side .brand { margin-bottom: 18px; }
.mail-side .compose-btn { width: 100%; justify-content: center; margin-bottom: 14px; }
.mail-folder { display: flex; width: 100%; justify-content: space-between; text-align: left; background: transparent; margin: 2px 0; min-height: 38px; }
.mail-folder.on { background: #e5f0ff; color: var(--primary); font-weight: 700; }
.mail-folder .count { font-size: 12px; color: var(--primary); font-weight: 700; }
.mail-col { width: 38%; min-width: 300px; display: flex; flex-direction: column; border-right: 1px solid #e8edf6; }
.mail-toolbar { padding: 12px; border-bottom: 1px solid #e8edf6; display: flex; gap: 8px; align-items: center; }
.mail-toolbar input { flex: 1; }
.mail-scroll { overflow: auto; flex: 1; }
.mail-row { padding: 13px 15px; border-bottom: 1px solid #eef2f8; cursor: pointer; display: flex; gap: 12px; transition: background .15s; width: 100%; text-align: left; background: transparent; border-radius: 0; min-height: 0; align-items: flex-start; }
.mail-row:hover { background: #f4f8ff; transform: none; box-shadow: none; }
.mail-row.selected { background: #eaf3ff; }
.mail-row.unseen .subj, .mail-row.unseen .who { font-weight: 700; }
.mail-row .meta { flex: 1; min-width: 0; }
.mail-row .who, .mail-row .subj { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mail-row .flags { font-size: 12px; color: var(--muted); }
.mail-avatar { height: 35px; width: 35px; border-radius: 50%; background: #d9eaff; color: var(--primary); display: grid; place-items: center; flex-shrink: 0; font-weight: 700; }
.mail-reader { flex: 1; min-width: 0; overflow: auto; padding: 0 28px 28px; display: flex; flex-direction: column; }
.mail-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid #e8edf6; position: sticky; top: 0; background: var(--surface); z-index: 10; }
.mail-actions button { padding: 7px 11px; min-height: 36px; }
.mail-head h2 { margin: 18px 0 8px; font-size: 20px; }
.mail-head .addr { color: var(--muted); font-size: 13px; }
.mail-frame { width: 100%; border: 0; flex: 1; min-height: 360px; margin-top: 14px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.attachment { padding: 9px 12px; border: 1px solid #dce8f7; border-radius: 12px; display: inline-flex; gap: 8px; align-items: center; text-decoration: none; color: var(--ink); font-size: 13px; }
.reader-empty { margin: auto; color: var(--muted); text-align: center; }

.compose { position: fixed; right: 24px; bottom: 16px; width: min(600px, calc(100vw - 35px)); height: min(620px, 92vh); background: var(--surface); z-index: var(--z-compose); display: flex; flex-direction: column; border-radius: 18px; overflow: hidden; box-shadow: 0 15px 75px #19355a55; animation: up .2s; }
.compose form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.mail-actions select { width: auto; min-height: 36px; padding: 6px 10px; }
.compose input, .compose textarea { border: 0; border-bottom: 1px solid #e8edf6; border-radius: 0; padding: 12px 14px; }
.compose textarea { flex: 1; resize: none; min-height: 0; }
.compose-top, .compose-bottom { padding: 10px 12px; background: #f2f7ff; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.compose .cc-toggle { font-size: 12.5px; padding: 4px 8px; min-height: 0; }
.drop { border: 2px dashed #bed2f1; border-radius: 12px; margin: 8px 12px; padding: 8px; text-align: center; color: var(--muted); font-size: 12.5px; }
.drop.over { background: var(--primary-softer); border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 6px; }
.chip { background: var(--primary-soft); border-radius: 20px; padding: 4px 6px 4px 10px; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { min-height: 0; padding: 0 6px; background: transparent; }

.ctx { position: fixed; z-index: var(--z-menu); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px #19355a33; padding: 6px; min-width: 220px; }
.ctx button { display: flex; width: 100%; background: transparent; justify-content: flex-start; min-height: 34px; padding: 6px 10px; border-radius: 8px; }
.ctx button:hover { background: #f1f6ff; transform: none; box-shadow: none; }
.ctx hr { border: 0; border-top: 1px solid var(--line-2); margin: 4px 0; }

.sig-preview { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; font-size: 13px; color: #4a5a78; }
.sig-preview img { width: 64px; height: 64px; object-fit: contain; display: block; margin-bottom: 6px; }

.mail-side .spacer { flex: 1; }
.mobile-back { display: none; }

@media print {
  .mail-side, .mail-col, .mail-actions, .side, .compose, #toast, .ctx { display: none !important; }
  .mail-layout, .mail-reader { display: block; height: auto; overflow: visible; }
  .mail-frame { height: 80vh; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) { .cards { grid-template-columns: repeat(2, 1fr); } .grid, .hero { grid-template-columns: 1fr; } }
@media (max-width: 850px) {
  .side { width: 64px; padding: 16px 6px; }
  /* Thanh bên thu gọn chỉ còn biểu tượng: chữ ẩn bằng mắt nhưng VẪN là tên của nút/liên kết cho trình đọc màn hình
     (display:none làm nút mất tên – lỗi tìm thấy khi kiểm thử Playwright trên điện thoại 16/11/2026). */
  .side .brand { display: none; }
  .nav .txt, .side .who .txt, .mail-side .txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav { justify-content: center; }
  .mail-side { width: 64px; padding: 12px 6px; }
  .mail-side .brand, .mail-side #quota-box { display: none; }
  .mail-folder { justify-content: center; }
  .mail-col { width: 42%; min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .dns-row { grid-template-columns: 60px 1fr; }
}
@media (max-width: 620px) {
  .main { padding: 12px; }
  .cards, .steps { grid-template-columns: 1fr; }
  .hero { padding: 22px; }
  .mail-col { width: calc(100% - 64px); }
  .mail-reader { display: none; position: fixed; inset: 0 0 0 64px; background: var(--surface); z-index: 50; padding: 0 14px 14px; }
  .mail-reader.visible { display: flex; }
  .mobile-back { display: inline-flex; }
  .compose { right: 4px; bottom: 4px; width: calc(100vw - 8px); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ===== V1: Marketing, Central Admin, webmail (A5–A7) ===== */
.side-tag { margin: -6px 0 10px 4px; }
.tpl-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tpl-edit textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.tpl-preview { width: 100%; min-height: 300px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.quota-box { margin: 8px 4px; }
.quota-box p { margin: 4px 0 0; }
.quota-box.warning p { color: var(--warn); }
.quota-box.critical p { color: var(--danger); font-weight: 600; }
.note { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin: 0 0 10px; }
.pre { white-space: pre-wrap; margin: 4px 0 0; }
fieldset.field { border: 0; padding: 0; }
fieldset.field legend { font-weight: 600; margin-bottom: 4px; }
@media (max-width: 760px) { .tpl-edit { grid-template-columns: 1fr; } }
