/* Mail Admin UI v2. Style "framed-sheet" (tasteskill v2, seed 745625813).
   Khung chrome nhuộm xám xanh hình chữ L (sidebar + topbar 48px), trang làm việc là tấm trắng
   lùi 8px khỏi mép phải và mép dưới, viền 1px, bo 16px, không đổ bóng.
   Màu chỉ đặt lên dữ liệu: thanh sức chứa cell, gạch tab 2px. Nút chính màu gần đen.
   Lưới: sheet 1440 - 228 sidebar - 8 inset = 1204; trừ 2 x 24 padding = 1156 nội dung.
   Hàng 2 thẻ: 2 x 566 + 24 = 1156. Rail chi tiết: 748 + 24 + 384 = 1156. */
:root {
  --ground: #f2f5f8;   /* face: một bậc xám xanh của hạ tầng, thay #f9fbfc */
  --surface: #ffffff;
  --raised: #f4f6f8;
  --active: #e6eaee;
  --border: #e8eaec;
  --rule: #f0f1f2;
  --control: #cdced1;
  --text: #131416;
  --muted: #5d5f60;
  --faint: #6b6d6e;
  --accent: #1b6c80;
  --primary: #1d1f20; --primary-ink: #ffffff;
  --positive: #1e7b4f; --negative: #c4242a; --warning: #92400e;
  --chart-1: #1b6c80; --chart-track: #e9edf0;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e;
  --pill-neutral-bg: #ebedee; --pill-neutral-ink: #353736;
  --pill-info-bg: #e3f1f4;    --pill-info-ink: #0f4552;

  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --fs-title: 22px; --fs-section: 16px; --fs-kpi: 28px; --fs-body: 14px; --fs-small: 12px; --fs-meta: 13px;

  --sidebar-width: 228px; --topbar: 48px; --sheet-inset: 8px;
  --radius-sheet: 16px; --radius-card: 8px; --radius-control: 6px;
  --gap: 24px; --pad: 24px; --card-pad: 20px;
  --control-height: 32px; --row-height: 48px; --nav-row: 32px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1); --t-press: 120ms; --t-hover: 150ms; --t-ui: 200ms;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: var(--fs-body)/20px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul[class], ol[class] { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table, .figure { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-meta); line-height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- khung: chữ L nhuộm + tấm trắng ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: var(--topbar) minmax(0, 1fr); min-height: 100svh; }
.sidebar { grid-row: 1 / span 2; position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; padding: 12px 12px 16px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 2px 8px; }
.brand-name { font-weight: 600; line-height: 18px; }
.brand-scope { display: block; font-size: var(--fs-small); line-height: 16px; color: var(--muted); font-weight: 400; }
.group-label { margin: 24px 8px 6px; font-size: var(--fs-small); line-height: 16px; color: var(--muted); }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; height: var(--nav-row); padding: 0 8px; border-radius: 8px; color: var(--muted); transition: background-color var(--t-hover) ease, color var(--t-hover) ease; }
.nav a svg { width: 16px; height: 16px; }
.nav a:hover { background: var(--raised); color: var(--text); }
.nav a[aria-current="page"] { background: var(--active); color: var(--text); }
.nav .count { margin-left: auto; font-size: var(--fs-small); color: var(--text); font-weight: 500; }
.sidebar .bottom { margin-top: auto; padding: 0 8px; font-size: var(--fs-small); line-height: 16px; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 16px; padding: 0 calc(var(--sheet-inset) + 16px) 0 var(--pad); }
.search { position: relative; width: 548px; max-width: 100%; margin: 0 auto; }
.search svg { position: absolute; left: 11px; top: 8px; width: 16px; height: 16px; color: var(--muted); }
.search input { width: 100%; height: 32px; padding: 0 36px 0 36px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); }
.search input::placeholder { color: var(--faint); }
.search kbd { position: absolute; right: 8px; top: 6px; height: 20px; min-width: 20px; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; font: 12px/18px var(--font); color: var(--muted); text-align: center; }
.account { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #dcebef; color: #0f4552; font-size: var(--fs-small); font-weight: 600; }

.sheet { grid-column: 2; min-width: 0; margin: 0 var(--sheet-inset) var(--sheet-inset) 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); padding: var(--pad); }

/* ---------- hàng tiêu đề ---------- */
.crumbs { display: flex; gap: 6px; margin-bottom: 8px; color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.title-row h1 { display: flex; align-items: center; gap: 10px; font-size: var(--fs-title); line-height: 28px; font-weight: 600; letter-spacing: -0.01em; }
.title-row .sub { margin-top: 4px; color: var(--muted); max-width: 72ch; }
.title-row .sub strong { color: var(--text); font-weight: 500; }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }
.stamp { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-small); margin-right: 4px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--positive); }

/* ---------- panel, lưới ---------- */
.stack > * + *, .sheet > * + * { margin-top: var(--gap); }
.sheet > .crumbs + * { margin-top: 0; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.with-rail { display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: var(--gap); align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 12px var(--card-pad); }
.panel-head h2 { font-size: var(--fs-section); line-height: 24px; font-weight: 600; }
.panel-head .meta { color: var(--muted); font-size: var(--fs-small); }
.panel-body { padding: 0 var(--card-pad) var(--card-pad); }
.panel-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px var(--card-pad); border-top: 1px solid var(--rule); color: var(--muted); }
.card-link { display: inline-flex; align-items: center; gap: 2px; color: var(--text); font-weight: 500; text-underline-offset: 3px; }
.card-link::after { content: "›"; font-size: 16px; line-height: 1; color: var(--muted); }
.card-link:hover { text-decoration: underline; }

/* ---------- bảng sức chứa cell (thành phần riêng của sản phẩm) ---------- */
.capacity { --cap-cols: 136px 96px minmax(0, 1fr) 132px 200px 88px; }
.capacity .head, .capacity .cell-row { display: grid; grid-template-columns: var(--cap-cols); column-gap: 24px; }
.capacity .head { padding-bottom: 10px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: var(--fs-small); line-height: 16px; }
.capacity .cell-row { padding: 16px 0; border-bottom: 1px solid var(--rule); }
.capacity .cell-row:last-child { border-bottom: 0; }
.capacity .cell-row > * { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.capacity .id { font-family: var(--mono); font-size: 15px; font-weight: 500; line-height: 20px; }
.capacity .host { font-family: var(--mono); font-size: var(--fs-small); color: var(--muted); line-height: 16px; }
.capacity .r { text-align: right; align-items: flex-end; }
.track { position: relative; height: 10px; border-radius: 999px; background: var(--chart-track); }
.track .fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--chart-1); }
.track .fill.over { background: var(--negative); }
.track .tick { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text); }
.track-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: var(--fs-meta); line-height: 18px; color: var(--muted); }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: var(--fs-meta); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw-fill { width: 14px; height: 8px; border-radius: 999px; background: var(--chart-1); }
.sw-tick { width: 2px; height: 14px; background: var(--text); }
.health-bad, .health-inline { color: var(--negative); font-weight: 500; }
.health-inline { display: none; font-size: var(--fs-meta); line-height: 18px; }
.capacity-total span { white-space: nowrap; }
.capacity-total { display: flex; justify-content: space-between; padding: 12px 0 0; border-top: 1px solid var(--border); color: var(--muted); }
.capacity-total strong { color: var(--text); font-weight: 500; }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 36px; padding: 0 12px; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
th:first-child, td:first-child { padding-left: 0; } th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
th.n, td.n { text-align: right; }
td .sub { display: block; margin-top: 2px; font-size: var(--fs-meta); line-height: 18px; color: var(--muted); }
td.id { width: 40%; }
.link { color: var(--text); font-weight: 500; text-underline-offset: 3px; }
.link:hover { text-decoration: underline; }
.unit { color: var(--muted); }
.dash { color: var(--muted); }
.mini-track { display: block; width: 100%; height: 4px; margin-top: 6px; border-radius: 999px; background: var(--chart-track); position: relative; }
.mini-track i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--muted); }
.mini-track i.full { background: var(--negative); }
.steps-mini { display: inline-grid; grid-template-columns: repeat(5, 14px); gap: 3px; vertical-align: middle; margin-right: 8px; }
.steps-mini i { height: 6px; border-radius: 2px; background: var(--chart-track); }
.steps-mini i.done { background: var(--chart-1); }
.steps-mini i.current { background: var(--chart-1); }
.steps-mini i.fail { background: var(--negative); }

/* pill: nền nhạt, chữ đậm cùng sắc, một pill mỗi dòng */
.pill { display: inline-flex; flex: none; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: var(--fs-small); font-weight: 500; line-height: 22px; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; }
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.pill.info { background: var(--pill-info-bg); color: var(--pill-info-ink); }

/* ---------- danh sách gọn trong thẻ ---------- */
.rows { display: grid; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 56px; padding: 10px 0; }
.row + .row { border-top: 1px solid var(--rule); }
.row .t { font-weight: 500; }
.row .s { display: block; margin-top: 2px; color: var(--muted); font-size: var(--fs-meta); line-height: 18px; }
.row .s .mono { font-size: 12.5px; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); }
.kv dt, .kv dd { padding: 8px 0; border-top: 1px solid var(--rule); }
.kv dt:first-of-type, .kv dd:first-of-type { border-top: 0; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.check { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--rule); }
.check:first-child { border-top: 0; }
.ok-mark { color: var(--positive); font-weight: 500; }
.bad-mark { color: var(--negative); font-weight: 500; }

/* ---------- điều khiển ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out); }
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { background: #3a3d40; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--negative); border-color: #e7b3b5; }
.btn.danger:hover { background: var(--pill-negative-bg); }
.btn.danger-solid { background: var(--negative); color: #fff; border-color: transparent; }
.btn.sm { height: 28px; padding: 0 10px; }
.btn:disabled { color: var(--muted); background: var(--raised); border-color: var(--border); cursor: not-allowed; transform: none; }
.field { display: grid; gap: 8px; }
.field label { font-weight: 500; }
.field .hint { color: var(--muted); font-size: var(--fs-small); line-height: 16px; }
.input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); }
.input::placeholder { color: var(--faint); }
.suffix { display: flex; } .suffix .input { border-radius: var(--radius-control) 0 0 var(--radius-control); }
.suffix span { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--control); border-left: 0; border-radius: 0 var(--radius-control) var(--radius-control) 0; background: var(--raised); color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.toolbar .input { width: 300px; height: 32px; }
.webmail-host-form { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.webmail-host-form label { flex: none; font-weight: 500; }
.webmail-host-form .input { max-width: 360px; height: 32px; }
.webmail-host-form .small { margin-right: auto; }
.audit-toolbar { flex-wrap: wrap; }
.audit-toolbar .input { flex: 1 1 132px; min-width: 0; width: 132px; }
.toolbar .count { margin-left: auto; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs a { position: relative; display: inline-flex; gap: 6px; padding: 10px 0; color: var(--muted); font-weight: 500; transition: color var(--t-hover) ease; }
.tabs a:hover { color: var(--text); }
.tabs a .n { font-weight: 400; color: var(--muted); }
.tabs a[aria-current="page"] { color: var(--text); }
.tabs a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }

/* thông báo trong tấm, không phải banner toàn màn */
.notice { display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-radius: var(--radius-card); background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.notice.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.notice .secret { font-family: var(--mono); font-size: 14px; font-weight: 500; padding: 2px 8px; border-radius: 4px; background: #fff; color: var(--text); }
.notice .btn { margin-left: auto; }
.notice code { font-family: var(--mono); font-size: 13px; }

/* vùng nguy hiểm: cuối trang, mục riêng */
section.danger { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 16px var(--card-pad); border: 1px solid #f0c9cb; border-radius: var(--radius-card); }
section.danger p { color: var(--muted); margin-top: 2px; }
section.danger h2 { font-size: var(--fs-section); line-height: 24px; font-weight: 600; }

/* dialog: thứ duy nhất được đổ bóng vì nó nổi */
dialog { width: min(480px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 8px 24px rgba(16, 20, 24, 0.08); }
dialog::backdrop { background: rgba(19, 20, 22, 0.32); }
dialog form { display: grid; gap: 16px; padding: 20px; }
dialog h2 { font-size: var(--fs-section); line-height: 24px; font-weight: 600; }
dialog .lead { color: var(--muted); margin-top: 4px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.opt { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--control); border-radius: var(--radius-control); }
.opt + .opt { margin-top: 8px; }
.opt.disabled { color: var(--muted); background: var(--raised); border-color: var(--border); }
.opt input { margin: 0; accent-color: var(--text); }

/* stepper migration */
.steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.steps li { padding-top: 12px; border-top: 3px solid var(--chart-track); color: var(--muted); }
.steps li.done { border-top-color: var(--chart-1); color: var(--text); }
.steps li.current { border-top-color: var(--chart-1); color: var(--text); font-weight: 500; }
.steps li.fail { border-top-color: var(--negative); color: var(--negative); font-weight: 500; }
.steps .at { display: block; font-size: var(--fs-meta); line-height: 18px; color: var(--muted); font-weight: 400; }
.log { margin: 0; font-family: var(--mono); font-size: 13px; line-height: 22px; white-space: pre-wrap; color: var(--text); }
.log .t { color: var(--muted); }

.empty { display: grid; place-items: center; min-height: 64px; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-control); color: var(--muted); text-align: center; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100svh; display: grid; place-items: center; padding: 24px 16px; }
.login .panel { width: min(400px, 100%); padding: 32px; display: grid; gap: 24px; border-radius: var(--radius-sheet); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand svg { width: 36px; height: 36px; }
.login-name { font-size: var(--fs-section); line-height: 20px; font-weight: 600; }
.login-name .brand-scope { margin-top: 2px; }
.login-head { display: grid; gap: 4px; }
.login h1 { font-size: var(--fs-title); line-height: 28px; font-weight: 600; letter-spacing: -0.01em; }
.login .sub { color: var(--muted); font-size: var(--fs-meta); line-height: 18px; }
.login form { display: grid; gap: 16px; }
.login .field { font-weight: 500; }
.login .btn { width: 100%; height: 40px; margin-top: 4px; }

/* ---------- điện thoại và máy tính bảng ---------- */
.menu-toggle { display: none; }
@media (max-width: 1100px) {
  .capacity { --cap-cols: 96px 88px minmax(0, 1fr) 120px; }
  .capacity .c-store, .capacity .c-act { display: none !important; }
  .with-rail { grid-template-columns: minmax(0, 1fr); }
  .health-inline { display: block; }
  .capacity-total { flex-wrap: wrap; gap: 4px 16px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--topbar) auto; }
  .sidebar { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 20; background: var(--surface); transform: translateX(-100%); transition: transform var(--t-ui) var(--ease-out); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .search { display: none; }
  .topbar .title-sm { font-weight: 600; margin-right: auto; }
  .sheet { grid-column: 1; margin: 0; border-radius: 0; border-width: 1px 0 0; padding: 16px; }
  .title-row { flex-direction: column; }
  .actions { flex-wrap: wrap; }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .capacity { --cap-cols: 84px minmax(0, 1fr) auto; }
  .capacity .head, .capacity .cell-row { column-gap: 12px; }
  .capacity .c-state, .capacity .host, .capacity .track-legend .dcount, .panel-head .legend, .steps-mini { display: none !important; }
  .webmail-host-form { align-items: stretch; flex-wrap: wrap; gap: 8px; }
  .webmail-host-form .input { flex: 1 1 100%; max-width: none; }
  .kv { grid-template-columns: 96px minmax(0, 1fr); }
  .toolbar .input { width: 100%; }
  .toolbar { flex-wrap: wrap; }
  .audit-toolbar { align-items: stretch; }
  .audit-toolbar .input { flex: 1 1 145px; width: auto; }
  .audit-toolbar .btn { align-self: flex-end; }
  section.danger { flex-direction: column; align-items: flex-start; }
  /* bảng thành dòng 2 tầng */
  table.stackable thead { display: none; }
  table.stackable tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
  table.stackable tbody tr:last-child { border-bottom: 0; }
  table.stackable td { padding: 0; border: 0; text-align: left; }
  table.stackable td.n { text-align: right; }
  table.stackable td.hide-sm { display: none; }
  table.stackable td.act { grid-column: 2; grid-row: 1; }
  table.stackable td.line2 { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin-top: 4px; }
}
@media (min-width: 861px) { .topbar .title-sm { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; } }
.audit-detail { display: block; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
