/* Khảo sát và quản trị: biểu mẫu rõ, dùng được trên điện thoại và khi in QR. */
:root{color-scheme:light dark;--bg:#f4f7fb;--card:#fff;--ink:#172434;--line:#dbe3ed;--accent:#126b60}*{box-sizing:border-box}body{margin:0;font:16px/1.6 system-ui;background:var(--bg);color:var(--ink)}header,main,footer{max-width:1160px;margin:auto;padding:20px}header{display:flex;align-items:center;gap:18px;flex-wrap:wrap}a{color:var(--accent)}h1{line-height:1.2}h2{margin-top:0}fieldset,article,.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:22px;margin:18px 0}legend{font-weight:700}label{display:block;margin:12px 0}input,select,textarea,button{font:inherit;border:1px solid var(--line);border-radius:8px;padding:10px}input:not([type=checkbox]),select,textarea{width:100%;background:var(--card);color:var(--ink)}input[type=checkbox]{width:20px;height:20px;vertical-align:middle;margin-right:8px}textarea{min-height:85px}button,.button{display:inline-block;background:var(--accent);color:white;cursor:pointer;text-decoration:none;padding:10px 18px;border-radius:8px}button:disabled{opacity:.55;cursor:wait}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:18px}.muted{color:#57697a}.message{white-space:pre-wrap}.error{color:#b82727}.trap{display:none}.tabs{display:flex;gap:10px;flex-wrap:wrap}.scroll{overflow:auto}table{width:100%;border-collapse:collapse}th,td{text-align:left;vertical-align:top;padding:12px;border-bottom:1px solid var(--line)}details{padding:10px;border-bottom:1px solid var(--line)}summary{cursor:pointer}pre{white-space:pre-wrap;word-break:break-word;font-family:inherit}.badge{display:inline-block;background:#d9ece7;color:#124e43;padding:3px 9px;border-radius:20px;font-size:14px}#qr img{width:294px;max-width:100%;background:white}dialog{border:1px solid var(--line);border-radius:14px;max-width:750px;width:95%;max-height:90vh;overflow:auto;background:var(--card);color:var(--ink)}@media(prefers-color-scheme:dark){:root{--bg:#101b25;--card:#192935;--ink:#e7eef7;--line:#3a4b5b;--accent:#39a491}.muted{color:#a9bdcf}}@media print{header,form,.tabs,footer{display:none}#qr{display:block!important}body{background:white;color:black}#qr button{display:none}}
.card a{overflow-wrap:anywhere}@media(prefers-color-scheme:dark){button,.button{color:#081f1b}}

/* Portal Admin: khung điều hành, không đụng trang khảo sát. */
body.admin-shell{--bg:#f3f5f8;--card:#fff;--ink:#172033;--line:#dbe3ed;--accent:#126b60;margin:0;min-height:100vh;background:#f3f5f8;color:#172033;color-scheme:light;font:14px/1.5 "Segoe UI",system-ui,sans-serif}
body.admin-shell [hidden]{display:none !important}
body.admin-shell .console{display:grid;grid-template-columns:248px minmax(0,1fr);min-height:100vh}
body.admin-shell .rail{min-width:0;background:#0e1628;color:#d5deea;padding:18px 12px 24px;display:flex;flex-direction:column;gap:8px}
body.admin-shell .brand{display:flex;align-items:center;gap:10px;color:#fff;text-decoration:none;padding:4px 8px 12px}
body.admin-shell .brand img{width:36px;height:36px;border-radius:10px;background:#fff}
body.admin-shell .brand strong{display:block;font-size:16px;letter-spacing:-.02em;line-height:1.2}
body.admin-shell .brand small{display:block;color:#93a3b8;font-size:12px;font-weight:500}
body.admin-shell .nav-label{margin:16px 10px 6px;font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:#7f90a6;font-weight:700}
body.admin-shell .rail button{display:flex;align-items:center;gap:10px;width:100%;text-align:left;background:transparent;color:#d5deea;border:0;border-radius:10px;padding:9px 12px;font:600 14px/1.3 "Segoe UI",system-ui,sans-serif;cursor:pointer}
body.admin-shell .rail button svg{width:18px;height:18px;flex:none}
body.admin-shell .rail button:hover:not([aria-current="page"]){background:rgba(255,255,255,.06);color:#fff}
body.admin-shell .rail button[aria-current="page"]{background:#2f6fed;color:#fff}
body.admin-shell .stage{min-width:0;display:flex;flex-direction:column;background:#f3f5f8}
body.admin-shell .topbar,body.admin-shell main{max-width:none;margin:0}
body.admin-shell .topbar{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;padding:16px 28px;background:#fff;border-bottom:1px solid #e6ebf2;position:sticky;top:0;z-index:4}
body.admin-shell .crumb{margin:0;color:#66758a;font-size:12px;font-weight:700;letter-spacing:.06em;text-transform:uppercase}
body.admin-shell .topbar h1{margin:2px 0 0;font-size:22px;letter-spacing:-.02em;line-height:1.25}
body.admin-shell .lede{margin:4px 0 0;color:#66758a;font-size:13px;max-width:640px}
body.admin-shell .topbar-tools{display:flex;align-items:center;gap:10px;flex-shrink:0}
body.admin-shell #refresh,body.admin-shell #logout{background:#fff;color:#1e293b;border:1px solid #d7e0ea;border-radius:10px;padding:8px 12px;font-weight:600}
body.admin-shell #refresh:hover,body.admin-shell #logout:hover{border-color:#2f5bd3;color:#2f5bd3}
body.admin-shell .account{display:flex;align-items:center;gap:10px}
body.admin-shell #identity{display:flex;align-items:center;gap:10px}
body.admin-shell .avatar{width:36px;height:36px;border-radius:50%;background:#e8eefc;color:#2f5bd3;display:grid;place-items:center;font-weight:700}
body.admin-shell .who{display:flex;flex-direction:column;line-height:1.2}
body.admin-shell .who b{font-size:14px}
body.admin-shell .who small{color:#66758a;font-size:12px}
body.admin-shell main{min-width:0;width:100%;padding:22px 28px 48px;flex:1}
body.admin-shell .kpis{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}
body.admin-shell .kpi{display:flex;gap:14px;align-items:flex-start;background:#fff;border:1px solid #e7edf3;border-radius:16px;padding:16px;margin:0;box-shadow:0 1px 2px rgba(16,24,40,.04)}
body.admin-shell .kpi strong{display:block;font-size:28px;letter-spacing:-.03em;line-height:1.1}
body.admin-shell .kpi-label{color:#526173;font-size:13px}
body.admin-shell .kpi small{display:block;color:#8b98a8;font-size:12px;margin-top:2px}
body.admin-shell .kpi-icon{width:40px;height:40px;border-radius:12px;display:grid;place-items:center;flex:none}
body.admin-shell .kpi-icon svg{width:20px;height:20px}
body.admin-shell .kpi-ok{background:#e7f6ef;color:#0f6b45}
body.admin-shell .kpi-run{background:#e8eefc;color:#2f5bd3}
body.admin-shell .kpi-keep{background:#f3e8ff;color:#6d28d9}
body.admin-shell .kpi-home{background:#fff4e5;color:#c2410c}
body.admin-shell .kpi-form{background:#e7f6f4;color:#0f766e}
body.admin-shell .kpi-mail{background:#fde8e8;color:#b42318}
body.admin-shell .charts{display:grid;grid-template-columns:1.4fr .9fr;gap:14px;align-items:start}
body.admin-shell .charts .panel{margin:16px 0}
body.admin-shell .legend{display:flex;gap:14px;padding:0 18px 4px;color:#526173;font-size:12px;font-weight:600}
body.admin-shell .legend i{display:inline-block;width:8px;height:8px;border-radius:99px;margin-right:6px}
body.admin-shell .chart-svg{width:100%;height:auto;display:block}
body.admin-shell .bars{padding:4px 18px 16px}
body.admin-shell .bar-row{display:grid;grid-template-columns:minmax(120px,180px) 1fr 36px;gap:10px;align-items:center;margin:8px 0;font-size:13px}
body.admin-shell .bar{height:8px;background:#eef2f6;border-radius:99px;overflow:hidden}
body.admin-shell .bar > span{display:block;height:100%;border-radius:99px}
body.admin-shell .bar-row b{text-align:right;font-variant-numeric:tabular-nums}
body.admin-shell .callout svg{width:18px;height:18px;flex:none;margin-top:2px}
body.admin-shell .callout p{margin:0}
body.admin-shell .panel{background:#fff;border:1px solid #e7edf3;border-radius:16px;margin:16px 0;box-shadow:0 1px 2px rgba(16,24,40,.04);overflow:hidden}
body.admin-shell .panel-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;padding:16px 18px 8px}
body.admin-shell .panel-head h2{margin:0;font-size:16px}
body.admin-shell .panel-head p{margin:4px 0 0;color:#66758a;font-size:13px}
body.admin-shell .btn-primary{background:#2f5bd3;color:#fff;border:0;border-radius:10px;padding:9px 14px;font-weight:700;cursor:pointer}
body.admin-shell .btn-primary:hover{background:#244ab8}
body.admin-shell .panel th{font-size:12px;letter-spacing:.04em;text-transform:uppercase;color:#6b7c90;font-weight:700;background:#f8fafc;border-bottom:1px solid #e7edf3;padding:10px 14px}
body.admin-shell .panel td{border-bottom:1px solid #eef2f6;padding:12px 14px;vertical-align:middle}
body.admin-shell .panel tr:last-child td{border-bottom:0}
body.admin-shell .panel tbody tr:hover td{background:#f8fafc}
body.admin-shell .primary{font-weight:700}
body.admin-shell .sub{color:#66758a;font-size:13px;margin-top:2px}
body.admin-shell .empty{text-align:center;color:#8b98a8;padding:28px 14px !important}
body.admin-shell .tag{display:inline-flex;align-items:center;border-radius:999px;padding:2px 8px;font-size:12px;font-weight:700;line-height:1.5}
body.admin-shell .tag-ok{background:#e7f6ef;color:#0f6b45}
body.admin-shell .tag-info{background:#e8eefc;color:#2346b0}
body.admin-shell .tag-warn{background:#fff4e5;color:#9a4d0f}
body.admin-shell .tag-keep{background:#f3e8ff;color:#6d28d9}
body.admin-shell .tag-danger{background:#fde8e8;color:#b42318}
body.admin-shell .tag-muted{background:#eef2f6;color:#526173}
body.admin-shell .stack{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px}
body.admin-shell td.row-actions,body.admin-shell .row-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
body.admin-shell .row-actions button{background:#fff;color:#1e3a5f;border:1px solid #d7e0ea;border-radius:8px;padding:6px 10px;font-size:13px;font-weight:600}
body.admin-shell .row-actions button:hover{border-color:#2f5bd3;color:#2f5bd3}
body.admin-shell .login-card{background:#fff;border:1px solid #e7edf3;border-radius:18px;padding:28px;box-shadow:0 16px 40px rgba(15,23,42,.06)}
body.admin-shell .login-card h2{margin:0 0 8px;font-size:22px}
body.admin-shell .login-card p{margin:0 0 8px;color:#66758a}
body.admin-shell .login-card button{width:100%;margin-top:8px;background:#2f5bd3;color:#fff;border:0;border-radius:10px;padding:11px 14px;font-weight:700}
body.admin-shell.is-guest .topbar{display:none}
body.admin-shell.is-guest .stage{background:linear-gradient(180deg,#f7f8fb,#eef2f7)}
body.admin-shell.is-guest main{display:grid;place-items:center}
body.admin-shell.is-guest #admin{width:min(440px,100%)}
body.admin-shell #editor{border:0;border-radius:16px;padding:22px 24px 18px;width:min(720px,calc(100vw - 32px));box-shadow:0 24px 80px rgba(15,23,42,.28)}
body.admin-shell #editor::backdrop{background:rgba(15,23,42,.45)}
body.admin-shell #editor h2{margin:0 0 8px;font-size:18px}
body.admin-shell #editor label{font-size:13px;font-weight:600;color:#526173}
body.admin-shell #editor input,body.admin-shell #editor select,body.admin-shell #editor textarea{margin-top:6px;border:1px solid #d5deea;border-radius:10px;padding:10px 12px;background:#fff}
body.admin-shell #editor pre{background:#f8fafc;border:1px solid #e7edf3;border-radius:10px;padding:12px;font-size:13px}
body.admin-shell #editor .dlg-actions{display:flex;justify-content:flex-end;gap:8px;position:sticky;bottom:0;margin:12px -24px 0;padding:12px 24px;background:#fff;border-top:1px solid #e7edf3}
body.admin-shell #editor .dlg-actions button{background:#fff;color:#1e293b;border:1px solid #d5deea;border-radius:10px;padding:9px 14px;font-weight:700}
body.admin-shell #editor .dlg-actions button[type="submit"]{background:#2f5bd3;color:#fff;border-color:#2f5bd3}
body.admin-shell #editor button[data-action]{background:#fff;color:#b42318;border:1px solid #f0c4c4}
@media(max-width:1100px){body.admin-shell .kpis{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:860px){
  body.admin-shell .console{grid-template-columns:minmax(0,1fr)}
  body.admin-shell .rail{position:sticky;top:0;z-index:6;flex-direction:column;align-items:stretch;padding:10px 12px;gap:8px}
  body.admin-shell .brand{padding:0 4px}
  body.admin-shell .brand small{display:none}
  body.admin-shell #nav{display:flex;gap:6px;align-items:center;overflow:auto;padding-bottom:2px}
  body.admin-shell .nav-label{display:none}
  body.admin-shell .rail button{width:auto;white-space:nowrap;flex:none}
  body.admin-shell .topbar{padding:14px 16px;flex-wrap:wrap}
  body.admin-shell main{padding:16px}
  body.admin-shell .kpis{grid-template-columns:1fr}
  body.admin-shell .charts{grid-template-columns:1fr}
  body.admin-shell .bar-row{grid-template-columns:minmax(0,1fr) 2fr 28px}
  body.admin-shell .panel-head{flex-wrap:wrap}
  body.admin-shell .panel table{min-width:680px}
}

.analysis-actions { display:flex; flex-wrap:wrap; gap:8px; margin:16px 0; }
#analysis-content { width:100%; min-height:300px; resize:vertical; }
#analysis-context, #analysis-instruction { width:100%; }
