:root {
    --bg: #f4f5f7; --panel: #fff; --border: #dfe1e6; --text: #1c1e21; --muted: #65676b;
    --primary: #1a66d9; --primary-text: #fff; --danger: #c9302c; --ok: #1f7a3d;
    --badge: #e9eefb; --restricted: #fdecea; --active: #e7f1ff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--primary); }

/* Thanh trên cùng */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 16px; margin: 0; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; color: var(--muted); }
.tabs button.active { background: var(--active); color: var(--primary); font-weight: 600; }

/* Nút và ô nhập */
button, .button { font: inherit; padding: 7px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); cursor: pointer; }
button:hover { border-color: #b7bcc6; }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select {
    font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--badge); font-size: 12px; margin: 1px 4px 1px 0; white-space: nowrap; }
.badge.restricted { background: var(--restricted); color: var(--danger); }
.badge.ok { background: #e6f4ea; color: var(--ok); }
.badge.off { background: #eee; color: var(--muted); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0; }
.note { color: var(--muted); margin: 0 0 12px; max-width: 900px; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* Trang hộp thư */
.inbox-page { display: flex; flex-direction: column; height: 100%; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.controls label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; padding-bottom: 8px; }
.controls .row { display: flex; gap: 6px; }
#address { font-weight: 600; color: var(--primary); background: var(--bg); width: 280px; max-width: 100%; }
.panes { flex: 1; display: flex; min-height: 0; }
.mail-list { width: 340px; flex-shrink: 0; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--border); }
.mail-item { padding: 10px 14px; border-bottom: 1px solid var(--bg); border-left: 3px solid transparent; cursor: pointer; }
.mail-item:hover { background: #fafbfc; }
.mail-item.active { background: var(--active); border-left-color: var(--primary); }
.mail-item .subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.mail-detail { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.mail-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.mail-head h2 { margin: 0 0 6px; font-size: 17px; }
.code-box { display: inline-flex; align-items: center; gap: 10px; margin-top: 10px; padding: 6px 8px 6px 14px; border: 1px solid var(--primary); border-radius: 8px; background: var(--active); }
.code-box strong { font: 700 20px ui-monospace, Consolas, monospace; letter-spacing: 3px; }
.mail-frame { flex: 1; width: 100%; border: none; background: #fff; min-height: 300px; }
.mail-text { flex: 1; margin: 0; padding: 16px 18px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.empty { display: flex; align-items: center; justify-content: center; height: 100%; padding: 24px; color: var(--muted); text-align: center; }

/* Trang quản trị */
.login { max-width: 340px; margin: 12vh auto; padding: 28px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.login h1 { font-size: 18px; margin: 0 0 16px; }
.login input { width: 100%; margin-bottom: 12px; }
.login button { width: 100%; }
main.admin { padding: 18px 16px 40px; max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar h2 { font-size: 17px; margin: 0; flex: 1; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--bg); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fafbfc; }
td.actions { white-space: nowrap; text-align: right; }
td.wrap { word-break: break-word; }

dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: min(520px, 94vw); max-height: 92vh; overflow: auto; }
dialog.wide { width: min(980px, 96vw); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin: 0 0 14px; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > span { font-size: 14px; font-weight: 400; color: var(--text); }
.options { display: flex; flex-direction: column; gap: 4px; }
.options label { display: flex; align-items: center; gap: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.key-reveal { display: flex; gap: 8px; margin: 10px 0; }
.key-reveal input { flex: 1; font-family: ui-monospace, Consolas, monospace; }
.viewer { display: flex; flex-direction: column; height: 60vh; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-top: 10px; }

@media (max-width: 768px) {
    .panes { flex-direction: column; }
    .mail-list { width: 100%; height: 38%; border-right: none; border-bottom: 1px solid var(--border); }
    #address { width: 100%; }
}
