:root {
    --bg: #f8fafc; --panel: #ffffff; --line: #e2e8f0; --text: #253247; --muted: #718096;
    --brand: #0f8f83; --brand-d: #0b746b; --brand-soft: #e8f8f5; --up: #22a35a; --down: #dc5a67; --warn: #e59b32;
    --radius: 12px; --sidebar: 240px;
}
* { box-sizing: border-box; }
/* Loading toàn cục khi POST (body.sl-busy) — thanh tiến trình trên cùng + con trỏ chờ. */
body.sl-busy { cursor: progress; }
body.sl-busy::before {
    content: ""; position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 9999;
    background: linear-gradient(90deg, var(--brand), #38bdf8, var(--brand));
    background-size: 200% 100%; animation: sl-progress 1s linear infinite;
}
body.sl-busy::after { content: "Đang xử lý yêu cầu…"; position: fixed; right: 22px; bottom: 22px; z-index: 9998; padding: 12px 16px 12px 42px; border: 1px solid #bce8df; border-radius: 12px; background: rgba(255,255,255,.96); color: var(--brand-d); box-shadow: 0 18px 45px rgba(15,23,42,.18); font-size: 13px; font-weight: 800; backdrop-filter: blur(10px); }
body.sl-busy .main::after { content: ""; position: fixed; right: 190px; bottom: 35px; z-index: 9999; width: 16px; height: 16px; border: 2px solid #bce8df; border-top-color: var(--brand); border-radius: 50%; animation: box-spin .65s linear infinite; }
@keyframes sl-progress { 0% { background-position: 200% 0; } 100% { background-position: 0 0; } }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: #f6f8fb; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.inline { display: inline; }

/* Buttons */
/* Thuộc tính `hidden` phải luôn thắng.

   Trình duyệt chỉ đặt `[hidden]{display:none}` ở UA stylesheet, nên bất kỳ class nào
   của app có set `display` (điển hình `.btn{display:inline-block}`) đều đè lên và làm
   phần tử VẪN HIỆN dù đã gắn `hidden`. Đó là lý do nút "Cấp SSL" và "Gia hạn SSL"
   hiện cùng lúc. Đặt rule toàn cục ở đây để mọi chỗ dùng `hidden` đều đúng. */
[hidden] { display: none !important; }

.btn { display: inline-block; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; background: #e2e8f0; color: var(--text); }
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn:disabled { cursor: not-allowed; opacity: .58; filter: grayscale(.08); }
body.sl-busy .btn:disabled { cursor: wait; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-d); }
.btn-ghost { background: #fff; border-color: var(--line); }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; text-align: center; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font-size: 13px; }

/* Auth */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(900px 520px at 20% 0%, #dff7f2, transparent 65%), linear-gradient(145deg,#f8fafc,#eef3f8); padding: 24px; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.auth-brand { font-weight: 800; color: var(--brand); margin-bottom: 16px; text-align: center; }
.auth-brand img { width: auto; max-width: 200px; height: auto; }
.auth-title { font-size: 22px; margin: 0 0 8px; }
.secret { font-family: ui-monospace, monospace; background: #f1f5f9; padding: 10px; border-radius: 8px; text-align: center; word-break: break-all; }
.qr { display: grid; place-items: center; margin: 10px 0; }
.qr img, .qr canvas { border: 8px solid #fff; border-radius: 8px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.codes code { font-family: ui-monospace, monospace; background: #f1f5f9; padding: 8px; border-radius: 8px; text-align: center; }

/* Forms */
.form label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.form input, .form select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.form .btn { margin-top: 18px; }
.form-wide { max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.stack-sm { display: grid; gap: 8px; }
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px auto; gap: 8px; align-items: center; }
.form-row .btn { margin-top: 0; white-space: nowrap; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 18px 18px; margin: 0 0 18px; }
legend { font-weight: 700; padding: 0 6px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500 !important; }
.checkbox input { width: auto; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: 10px; margin: 12px 0; font-size: 14px; }
.alert-error { background: #fee2e2; color: #b91c1c; }
.alert-success { background: #dcfce7; color: #15803d; }

/* Admin layout */
.admin-body { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: #fff; color: #475569; padding: 20px 14px; flex-shrink: 0; border-right: 1px solid var(--line); box-shadow: 8px 0 28px rgba(15,23,42,.035); }
.sidebar-brand { font-weight: 800; color: #172033; padding: 6px 10px 18px; font-size: 16px; }
.sidebar-brand img { width: auto; max-width: 200px; height: auto; display: block; }
.nav-link { display: block; padding: 10px 12px; border-radius: 10px; color: #64748b; margin-bottom: 4px; font-weight: 600; }
.nav-link:hover { background: #f1f7f6; color: var(--brand-d); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-d); box-shadow: inset 3px 0 0 var(--brand); }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.content { padding: 24px; }
.page-title { margin: 0 0 18px; font-size: 24px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* Cards / panels / table */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.text-up { color: var(--up); } .text-down { color: var(--down); }
.panel { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-body { padding: 14px 18px; }
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; }
tr.dragging { opacity: .5; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-up, .badge-enabled { background: #dcfce7; color: #15803d; }
.badge-down { background: #fee2e2; color: #b91c1c; }
.badge-warn { background: #fff3d8; color: #a9630b; }
.badge-unknown, .badge-disabled { background: #e2e8f0; color: #475569; }

.toast { position: fixed; right: 20px; bottom: 20px; background: #1e293b; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 50; max-width: 360px; }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.mt { margin-top: 16px; }

.tabs { display: flex; gap: 4px; margin: 8px 0 18px; border-bottom: 1px solid var(--line); }
.tab { padding: 9px 14px; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tab:hover { text-decoration: none; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* SafeLine-like application detail */
.safeline-app-card { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 18px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.safeline-app-main { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.safeline-domain-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 800; flex: 0 0 auto; }
.safeline-app-main h2 { margin: 0 0 7px; font-size: 18px; overflow-wrap: anywhere; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.chip { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 9px; border-radius: 8px; background: #f8fafc; border: 1px solid var(--line); color: #334155; font-size: 12px; font-weight: 700; overflow-wrap: anywhere; }
.safeline-mode-summary { min-width: 180px; }
.safeline-mode-summary .btn { width: 100%; text-align: center; margin-bottom: 4px; }
.safeline-mini-stats { display: grid; grid-template-columns: repeat(2, minmax(76px, 1fr)); gap: 8px; }
.safeline-mini-stats div { padding: 9px 10px; border-radius: 8px; background: #f8fafc; border: 1px solid var(--line); }
.safeline-mini-stats span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; }
.safeline-mini-stats strong { display: block; margin-top: 3px; font-size: 18px; }
.safeline-basic { margin-bottom: 16px; }
.basic-grid { display: grid; gap: 14px; padding: 16px 18px; }
.basic-row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; align-items: start; }
.basic-label { color: var(--muted); font-size: 13px; font-weight: 800; }
.feature-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.feature-group { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.feature-group h3 { margin: 0 0 10px; font-size: 14px; }
.feature-button { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 38px; padding: 9px 10px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; text-align: left; }
.feature-button span:first-child { margin-right: 12px; }
.feature-button:hover { border-color: #bce8df; background: #f0fbf8; }
.mode-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; margin-bottom: 10px; }
.mode-card { display: grid; gap: 5px; min-height: 82px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); cursor: pointer; text-align: left; }
.mode-card strong { font-size: 14px; }
.mode-card span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.mode-card.active { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px rgba(15,143,131,.14); }
.mode-card:disabled { cursor: not-allowed; opacity: .7; }
.panel-kicker { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; background: #fee2e2; color: #b91c1c; font-size: 12px; font-weight: 700; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pill.is-on { background: #dcfce7; color: #15803d; }
.setting-list { padding: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px; border-bottom: 1px solid var(--line); }
.setting-row-compact { margin: -14px -18px 14px; padding: 16px 18px; background: #fbfdff; }
.setting-copy { display: grid; gap: 4px; }
.setting-copy strong { font-size: 14px; }
.setting-copy span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.setting-footnote { margin: 0; padding: 12px 18px; color: var(--muted); background: #f8fafc; font-size: 12px; }
.switch-control { position: relative; display: inline-flex; flex: 0 0 auto; cursor: pointer; }
.switch-control input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.switch-track { position: relative; display: block; width: 46px; height: 26px; border-radius: 999px; background: #dc2626; box-shadow: inset 0 0 0 1px rgba(15,23,42,.1); transition: background .18s, opacity .18s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(15,23,42,.28); transition: transform .18s; }
.switch-control input:checked + .switch-track { background: #16a34a; }
.switch-control input:checked + .switch-track::after { transform: translateX(20px); }
.switch-control input:focus-visible + .switch-track { outline: 3px solid rgba(15,143,131,.24); outline-offset: 2px; }
.switch-control input:disabled + .switch-track { cursor: not-allowed; opacity: .5; }
.table-switch { appearance: none; position: relative; width: 40px !important; min-width: 40px; height: 22px; margin: 0; border: 0 !important; border-radius: 999px !important; background: var(--down); cursor: pointer; vertical-align: middle; transition: background .18s; }
.table-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(15,23,42,.3); transition: transform .18s; }
.table-switch:checked { background: var(--up); }
.table-switch:checked::after { transform: translateX(18px); }
.table-switch:focus-visible { outline: 3px solid rgba(15,143,131,.24); outline-offset: 2px; }

/* Per-surface loading: giữ nguyên kích thước box, che dữ liệu dở dang bằng skeleton. */
.load-overlay { position: absolute; inset: 0; z-index: 8; display: grid; align-content: center; gap: 12px; min-height: 116px; padding: 22px; background: rgba(255,255,255,.96); backdrop-filter: blur(3px); }
.load-overlay[hidden] { display: none; }
.load-skeleton { display: grid; gap: 10px; }
.load-skeleton span { display: block; height: 12px; border-radius: 999px; background: linear-gradient(90deg,#e9eef5 20%,#f8fafc 45%,#e9eef5 70%); background-size: 240% 100%; animation: box-shimmer 1.15s ease-in-out infinite; }
.load-skeleton span:nth-child(1) { width: 38%; height: 16px; }
.load-skeleton span:nth-child(2) { width: 92%; }
.load-skeleton span:nth-child(3) { width: 72%; }
.load-caption { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.load-caption::before { content: ""; width: 15px; height: 15px; border: 2px solid #cbd5e1; border-top-color: var(--brand); border-radius: 50%; animation: box-spin .7s linear infinite; }
.load-overlay.is-error { align-content: center; background: rgba(255,255,255,.98); }
.load-overlay.is-error .load-skeleton { display: none; }
.load-overlay.is-error .load-caption { color: #b91c1c; }
.load-overlay.is-error .load-caption::before { content: "!"; display: grid; place-items: center; width: 20px; height: 20px; border: 0; background: #fee2e2; animation: none; font-size: 12px; }
.is-loading { min-height: 132px; }
@keyframes box-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -120% 0; } }
@keyframes box-spin { to { transform: rotate(360deg); } }
.security-rule-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr); gap: 16px; }
.rule-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 14px 18px; }
.rule-preset { min-height: 92px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; color: var(--text); cursor: pointer; text-align: left; }
.rule-preset strong { display: block; font-size: 13px; margin-bottom: 6px; }
.rule-preset span { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.rule-preset:hover { border-color: #bce8df; background: #f0fbf8; }
.rate-limit-intro { padding: 0 18px 14px; color: var(--muted); font-size: 13px; }
.rate-limit-mode { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 18px 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.rate-limit-mode strong { display: block; font-size: 14px; }
.rate-limit-mode span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.rate-limit-groups { display: grid; gap: 14px; padding: 0 18px 18px; }
.rate-limit-groups[hidden] { display: none !important; }
.rate-limit-group { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.rate-limit-group-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.rate-limit-group-head h3 { margin: 0; font-size: 15px; }
.rate-limit-group-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.rate-limit-list { display: grid; }
.rate-limit-list > .muted { padding: 18px; }
.rate-limit-rule { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rate-limit-rule:last-child { border-bottom: 0; }
.rate-limit-rule.is-disabled { background: #fafafa; opacity: .72; }
.rate-limit-rule-copy { display: grid; gap: 6px; min-width: 0; }
.rate-limit-rule-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rate-limit-rule-title strong { font-size: 14px; }
.rate-limit-rule-summary { color: #475569; font-size: 12px; line-height: 1.5; }
.rate-limit-rule-conditions { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.rate-limit-rule-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.rate-limit-system-badge { display: inline-flex; padding: 3px 7px; border-radius: 999px; background: #e0f2fe; color: #0369a1; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.acl-rule-modal { max-width: 760px; }
.acl-condition-card { margin: 18px 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.acl-condition-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.acl-cond-list { display: grid; gap: 8px; }
.acl-cond-row { display: grid; grid-template-columns: minmax(130px,1fr) minmax(130px,1fr) minmax(180px,1.5fr) auto; gap: 8px; align-items: center; }
.acl-cond-row input, .acl-cond-row select { width: 100%; min-height: 39px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); font: inherit; }
.acl-cond-joiner { color: var(--muted); font-size: 11px; font-weight: 800; text-align: center; }
.acl-condition-card > .btn { margin-top: 12px; }
.acl-metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; margin: 16px 0; }
.acl-metric { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.acl-input-suffix { display: flex; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.acl-input-suffix input, .acl-input-suffix select { width: 100%; min-width: 0; min-height: 39px; padding: 8px 10px; border: 0; background: transparent; color: var(--text); font: inherit; }
.acl-input-suffix small { flex: 0 0 auto; padding: 0 9px; color: var(--muted); font-weight: 700; }
.bot-config-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin: 12px 0; }
.bot-config-grid label, .bot-pattern-label { display: grid; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.bot-config-grid .checkbox { display: flex; align-items: center; color: var(--text); font-size: 13px; }
.bot-config-grid input, .bot-config-grid select, .bot-pattern-label textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--text); background: #fff; }
.bot-pattern-label textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
.bot-condition-builder { margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; padding: 10px; }
.bot-builder-head, .bot-group-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.bot-groups { display: grid; gap: 10px; }
.bot-group { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 10px; }
.bot-cond-list { display: grid; gap: 8px; }
.bot-cond-row { display: grid; grid-template-columns: minmax(90px, 1fr) 110px minmax(90px, 1fr) minmax(140px, 1.4fr) auto; gap: 8px; align-items: start; }
.bot-cond-row input, .bot-cond-row select, .bot-cond-row textarea { width: 100%; min-height: 34px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 12px; background: #fff; }
.bot-cond-row textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.log-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 14px; }

/* Alerts (warn) */
.alert-warn { background: #fef3c7; color: #92400e; }

/* Portal: charts / tabs / settings (task06) */
.chart { height: 280px; padding: 8px 12px 12px; }
.chart-empty { display: grid; place-items: center; height: 100%; min-height: 220px; }
.tab-panel { margin-top: 8px; }
.sel-sm { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.form textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; font-family: inherit; }
.form textarea + .btn { margin-top: 12px; }

/* Usage billing (task08) */
.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.usage-card .panel-head h2 { max-width: 70%; overflow-wrap: anywhere; }
.usage-meter { height: 9px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.usage-meter span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .45s ease; }
.usage-meter-safe span { background: linear-gradient(90deg,#36b66d,#22a35a); }
.usage-meter-warn span { background: linear-gradient(90deg,#f6bd55,#e59b32); }
.usage-meter-danger span { background: linear-gradient(90deg,#ef7a78,#dc5a67); }
.usage-health { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.usage-health::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.usage-health-safe { color: #17834a; background: #e7f8ee; }
.usage-health-warn { color: #a9630b; background: #fff3d8; }
.usage-health-danger { color: #b63e4a; background: #ffe8ea; }
.usage-number { font-size: 22px; font-weight: 800; margin-top: 2px; }
.usage-bars { height: 58px; display: flex; align-items: end; gap: 4px; }
.usage-bars span { width: 10px; background: var(--brand); border-radius: 4px 4px 0 0; opacity: .9; }
.usage-bars span.missing { background: #d97706; opacity: .55; }

/* Modal (thuần) */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal-overlay[hidden] { display: none !important; }
.modal-card { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 480px; box-shadow: 0 30px 80px rgba(0,0,0,.4); max-height: 86vh; overflow: auto; }
.modal-card h3 { margin: 0 0 8px; }
.log-detail { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; font-size: 12px; overflow: auto; max-height: 60vh; }
.modal-card.modal-wide { max-width: 860px; }
.modal-card > label:not(.checkbox) { display: block; margin: 14px 0 6px; color: #475569; font-size: 12px; font-weight: 700; }
.modal-card > input, .modal-card > select { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text); font: inherit; }
.ad-action-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 18px; }
.ad-action-card { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: #f8fafc; }
.ad-action-card:has(input:checked) { border-color: var(--brand); background: #f0fbf8; box-shadow: 0 0 0 1px rgba(15,143,131,.12); }
.ad-action-card input { accent-color: var(--brand); }
.ad-action-card span { display: grid; gap: 2px; }
.ad-action-card strong { font-size: 13px; }
.ad-action-card small { color: var(--muted); font-size: 11px; }
.record-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 8px 0 14px; }
.record-meta-row { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.record-meta-row span:first-child { text-transform: uppercase; letter-spacing: .03em; font-size: 11px; }
.record-block-title { margin: 14px 0 6px; font-size: 13px; }
.auth-config { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.auth-config > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.auth-sources { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 6px; }
.auth-sources .checkbox { margin: 0; }
.ad-groups { display: flex; flex-direction: column; gap: 10px; margin: 6px 0; }
.ad-group { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: rgba(0,0,0,.02); }
.ad-cond-list { display: flex; flex-direction: column; gap: 6px; }
.ad-cond-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1.6fr auto; gap: 6px; align-items: center; }
.ad-cond-row input, .ad-cond-row select { width: 100%; min-height: 38px; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.ad-group-bar { display: flex; gap: 8px; margin-top: 8px; }
@media (max-width: 720px) { .ad-cond-row { grid-template-columns: 1fr; } }

@media (max-width: 920px) { .safeline-app-card, .feature-groups, .mode-cards, .security-rule-grid, .rule-presets { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
    .rate-limit-mode, .rate-limit-group-head, .rate-limit-rule { align-items: stretch; flex-direction: column; grid-template-columns: 1fr; }
    .rate-limit-rule-actions { justify-content: flex-start; }
}
@media (max-width: 720px) { .cards { grid-template-columns: 1fr 1fr; } .grid-2, .usage-grid, .form-row, .basic-row, .bot-config-grid, .bot-cond-row, .record-meta { grid-template-columns: 1fr; } }

/* ── UI polish (task19) — additive, không đổi layout sẵn có ── */
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f8fafc; }
.table thead th { position: sticky; top: 0; z-index: 1; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 30%, transparent); outline-offset: 1px; border-color: var(--brand); }
.btn { transition: filter .15s, transform .05s, box-shadow .15s; }
.btn:active { transform: translateY(1px); }
.panel { box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 6px 18px rgba(15,23,42,.05); }
.alert-warning { background: #fef9c3; border: 1px solid #fde68a; color: #854d0e; border-radius: 10px; }
.alert-danger { background: #fee2e2; border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.secret { user-select: all; }

/* Application Detail — polished SaaS surface */
[data-app-detail] .panel { border-color: #dbe4ef; box-shadow: 0 10px 28px rgba(15,23,42,.065); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
[data-app-detail] .panel:hover { border-color: #cbd9e8; box-shadow: 0 14px 34px rgba(15,23,42,.085); }
[data-app-detail] .panel-head { min-height: 58px; padding: 15px 18px; background: linear-gradient(180deg,#fff 0%,#fbfdff 100%); }
[data-app-detail] .panel-head h2 { color: #14213a; font-size: 15px; letter-spacing: -.01em; }
[data-app-detail] .tabs { position: sticky; top: 0; z-index: 12; gap: 8px; padding: 7px; border: 1px solid #dbe4ef; border-radius: 12px; background: rgba(255,255,255,.9); box-shadow: 0 8px 22px rgba(15,23,42,.06); backdrop-filter: blur(12px); }
[data-app-detail] .tab { border: 0; border-radius: 8px; padding: 9px 15px; }
[data-app-detail] .tab.active { color: #fff; background: linear-gradient(135deg,var(--brand),#15aa9c); box-shadow: 0 5px 13px rgba(15,143,131,.24); }
[data-app-detail] .table thead { background: #f8fafc; }
[data-app-detail] .table th { padding-top: 12px; padding-bottom: 12px; color: #64748b; }
[data-app-detail] .table td { height: 54px; }
[data-app-detail] .table tbody tr:hover { background: #f7fbff; }
[data-app-detail] .card { position: relative; overflow: hidden; border-color: #dbe4ef; box-shadow: 0 8px 24px rgba(15,23,42,.055); }
[data-app-detail] .card::after { content: ""; position: absolute; right: -24px; bottom: -34px; width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle,rgba(14,165,233,.11),transparent 70%); }
.modal-overlay { backdrop-filter: blur(7px); background: rgba(15,23,42,.58); animation: modal-fade .16s ease-out; }
.modal-card { border: 1px solid rgba(255,255,255,.7); box-shadow: 0 30px 90px rgba(15,23,42,.34); animation: modal-rise .2s ease-out; }
.modal-card.modal-wide { padding: 26px; }
.modal-card.modal-wide > h3 { margin-bottom: 16px; color: #14213a; font-size: 21px; letter-spacing: -.02em; }
.ad-group { padding: 14px; border-color: #dbe4ef; background: #f8fafc; }
.ad-group + .ad-group { position: relative; margin-top: 15px; }
.ad-group + .ad-group::before { content: "OR"; position: absolute; top: -23px; left: 18px; padding: 2px 7px; border-radius: 999px; background: #dff7f2; color: var(--brand-d); font-size: 10px; font-weight: 800; }
.ad-cond-row + .ad-cond-row { padding-top: 8px; border-top: 1px dashed #dbe4ef; }
@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(10px) scale(.985); } }

.segmented { display: inline-flex; gap: 2px; padding: 5px; border: 1px solid #d8e1ea; border-radius: 6px; background: #fff; }
.segmented button { min-width: 38px; padding: 6px 10px; border: 0; border-radius: 4px; background: transparent; color: #4b5563; font-size: 12px; font-weight: 700; text-transform: uppercase; cursor: pointer; }
.segmented button.active { color: #fff; background: #60c1c0; box-shadow: 0 2px 7px rgba(51,176,175,.2); }
.trend-toolbar { margin: 14px 0; padding: 10px 0; border-bottom: 0; }
@media (max-width: 600px) {
  .segmented button { padding: 5px 7px; }
  .trend-toolbar { align-items: flex-start; gap: 10px; }
}
.wizard-form { padding: 18px; }
.wizard-progress { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 24px; }
.wizard-progress span { padding: 10px 12px; border-radius: 8px; background: #f1f5f9; color: #94a3b8; font-size: 12px; font-weight: 800; text-align: center; }
.wizard-progress span.active { color: var(--brand-d); background: var(--brand-soft); }
.wizard-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.wizard-status { margin: 16px 0; padding: 13px 14px; border: 1px solid var(--line); border-radius: 9px; background: #f8fafc; }

/* ── Responsive shell: giữ nguyên markup/form, thích ứng từ 320px tới desktop ── */
html { min-width: 0; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-width: 0; overflow-x: hidden; }
img, svg, video, canvas { max-width: 100%; }
input, select, textarea, button { max-width: 100%; font-family: inherit; }
textarea { resize: vertical; }
pre, code, .secret { max-width: 100%; overflow-wrap: anywhere; }

.sidebar {
    position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
    overscroll-behavior: contain; scrollbar-width: thin;
}
.mobile-nav-toggle {
    display: none; width: 42px; height: 42px; padding: 10px; border: 1px solid var(--line);
    border-radius: 11px; background: #fff; color: var(--text); cursor: pointer;
    align-items: center; justify-content: center; flex-direction: column; gap: 4px;
    box-shadow: 0 4px 14px rgba(15,23,42,.07);
}
.mobile-nav-toggle span { display: block; width: 19px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .2s, opacity .2s; }
.nav-open .mobile-nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-open .mobile-nav-toggle span:nth-child(2) { opacity: 0; }
.nav-open .mobile-nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.nav-backdrop {
    position: fixed; inset: 0; z-index: 69; width: 100%; height: 100%; margin: 0; padding: 0;
    border: 0; border-radius: 0; background: rgba(15,23,42,.48); backdrop-filter: blur(2px); cursor: pointer;
}
.nav-backdrop[hidden] { display: none !important; }

.table-scroll {
    width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden;
    overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.table-scroll:focus-visible { outline: 3px solid rgba(15,143,131,.25); outline-offset: -3px; }
.table-scroll .table { margin: 0; }

.tabs { max-width: 100%; overflow-x: auto; overflow-y: hidden; overscroll-behavior-inline: contain; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; white-space: nowrap; }

@media (max-width: 1024px) {
    .admin-body { display: block; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 70; width: min(86vw, 300px); height: 100dvh;
        padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
        transform: translateX(-105%); visibility: hidden;
        box-shadow: 24px 0 55px rgba(15,23,42,.22); transition: transform .22s ease, visibility .22s;
    }
    .nav-open { overflow: hidden; }
    .nav-open .sidebar { transform: translateX(0); visibility: visible; }
    body:not([data-responsive-ready="1"]) .sidebar {
        position: static; width: 100%; height: auto; transform: none; visibility: visible; box-shadow: none;
    }
    .mobile-nav-toggle { display: inline-flex; }
    .main { width: 100%; min-height: 100vh; min-height: 100dvh; }
    .topbar {
        position: sticky; top: 0; z-index: 40; min-height: 62px; padding: 9px clamp(14px, 3vw, 24px);
        padding-left: max(clamp(14px, 3vw, 24px), env(safe-area-inset-left));
        padding-right: max(clamp(14px, 3vw, 24px), env(safe-area-inset-right));
        box-shadow: 0 5px 18px rgba(15,23,42,.055);
    }
    .content {
        width: 100%; padding: clamp(16px, 3vw, 24px);
        padding-left: max(clamp(16px, 3vw, 24px), env(safe-area-inset-left));
        padding-right: max(clamp(16px, 3vw, 24px), env(safe-area-inset-right));
        padding-bottom: max(clamp(20px, 4vw, 32px), env(safe-area-inset-bottom));
    }
    [data-app-detail] .tabs { top: 70px; }
    .safeline-mode-summary { min-width: 0; width: 100%; }
}

@media (max-width: 768px) {
    .page-title { font-size: clamp(20px, 6vw, 24px); overflow-wrap: anywhere; }
    .page-head { align-items: flex-start; flex-direction: column; gap: 12px; }
    .page-head > .actions, .page-head > .btn { width: 100%; }
    .panel-head { align-items: flex-start; flex-wrap: wrap; gap: 10px; padding: 13px 14px; }
    .panel-head > .actions { justify-content: flex-start; }
    .panel-body { padding: 14px; }
    .filter-bar { align-items: stretch; }
    .filter-bar > input, .filter-bar > select { flex: 1 1 min(220px, 100%); min-width: 0; }
    .filter-bar > .btn, .filter-bar > button { flex: 0 1 auto; min-height: 42px; }
    .table-scroll .table { min-width: 680px; }
    .table-scroll.table-compact .table { min-width: 100%; }
    .table th, .table td { padding: 10px 12px; }
    .chart { height: clamp(230px, 58vw, 300px); padding-inline: 6px; }
    .modal-overlay { align-items: end; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .modal-card, .modal-card.modal-wide {
        width: 100%; max-width: none; max-height: min(90vh, 90dvh); padding: 18px;
        border-radius: 18px 18px 12px 12px;
    }
    .modal-card.modal-wide > h3 { font-size: 19px; }
    .ad-action-picker { grid-template-columns: 1fr; }
    .actions { row-gap: 8px; }
    .wizard-actions { flex-wrap: wrap; }
    .safeline-mini-stats { width: 100%; }
}

@media (max-width: 600px) {
    .topbar-user { min-width: 0; justify-content: flex-end; }
    .topbar-user > span { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
    .card { padding: 14px; }
    .card-value { font-size: 24px; }
    .filter-bar { display: grid; grid-template-columns: minmax(0, 1fr); }
    .filter-bar > input, .filter-bar > select, .filter-bar > button, .filter-bar > .btn { width: 100%; }
    .tabs { margin-inline: -4px; padding-inline: 4px; }
    [data-app-detail] .tabs { border-radius: 10px; }
    [data-app-detail] .tab { padding: 9px 12px; }
    .form input, .form select, .form textarea, .filter-bar input, .filter-bar select,
    .modal-card input, .modal-card select, .modal-card textarea { font-size: 16px; }
    .form-row .btn { width: 100%; }
    fieldset { padding: 7px 13px 14px; }
    .toast { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: none; }
    body.sl-busy::after { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); padding-left: 44px; }
    body.sl-busy .main::after { left: 28px; right: auto; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 13px); }
}

@media (max-width: 420px) {
    .content { padding-top: 14px; }
    .topbar { min-height: 58px; }
    .topbar-user { gap: 6px; }
    .topbar-user > span { display: none; }
    .cards { grid-template-columns: 1fr; }
    .auth-body { padding: 14px; }
    .auth-card { padding: 22px 18px; border-radius: 14px; }
    .codes { grid-template-columns: 1fr; }
    .wizard-progress { grid-template-columns: 1fr; gap: 6px; }
    .wizard-actions { display: grid; grid-template-columns: 1fr; }
    .wizard-actions .btn { width: 100%; }
    .safeline-mini-stats { grid-template-columns: 1fr 1fr; }
    .panel { border-radius: 10px; }
    .modal-overlay { padding: 0; }
    .modal-card, .modal-card.modal-wide { max-height: 94dvh; border-radius: 18px 18px 0 0; padding: 16px; }
}

@media (max-height: 520px) and (orientation: landscape) {
    .sidebar { padding-top: 12px; padding-bottom: 12px; }
    .sidebar-brand { padding-bottom: 10px; }
    .nav-link { padding-block: 8px; }
    .modal-overlay { align-items: center; padding: 8px; }
    .modal-card, .modal-card.modal-wide { max-height: 96dvh; border-radius: 12px; }
}

@media (hover: none) and (pointer: coarse) {
    .btn, .nav-link, .tab, .feature-button { min-height: 44px; }
    .table-switch { min-height: 24px; }
    .btn:hover, .nav-link:hover, [data-app-detail] .panel:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ── Trang chứng chỉ SSL (ACME dns-01) ─────────────────────────────── */
.alert-info { background: #e0f2fe; color: #075985; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.stat-row .stat { flex: 1 1 120px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 14px; }
.stat-row .stat-label { display: block; font-size: 12px; color: #64748b; }
.stat-row .stat-value { display: block; font-size: 22px; font-weight: 700; line-height: 1.2; }
@media (max-width: 640px) { .stat-row .stat { flex-basis: 100%; } }
