/* TECHBOX V2 / Industrial Control refresh – visual layer only.
 * No changes to auth, banking, ESP 112/24, SQL or HA.
 * Light-mode users retain the existing accessible palette. */
html[data-theme="dark"]{
  color-scheme: dark;
  --bg:#0d1012;
  --surface:#181c1e;
  --surface-2:#202629;
  --line:#364044;
  --text:#f3f5f5;
  --muted:#bac4c8;
  --primary:#ffbc36;
  --primary-2:#f5a900;
  --success:#57d6a7;
  --warning:#ffc04a;
  --danger:#ff737b;
  --shadow:0 12px 34px rgba(0,0,0,.20);
  --radius:14px;
}
html[data-theme="dark"] body{
  background:
    linear-gradient(rgba(255,255,255,.012) 1px,transparent 1px),
    linear-gradient(90deg,rgba(255,255,255,.012) 1px,transparent 1px),
    var(--bg);
  background-size:32px 32px;
}
html[data-theme="dark"] .sidebar{
  background:linear-gradient(180deg,#151819,#101315);
  border-right:1px solid #343b3e;
  box-shadow:10px 0 32px rgba(0,0,0,.13);
}
html[data-theme="dark"] .brand-mark,
html[data-theme="dark"] .avatar{
  background:linear-gradient(135deg,#ffd66a,#f6aa18);
  color:#201600;
  box-shadow:0 4px 16px rgba(245,169,0,.16);
}
html[data-theme="dark"] .brand strong{color:#f6f4eb}
html[data-theme="dark"] .brand span,
html[data-theme="dark"] .nav-section{color:#aebbbf}
html[data-theme="dark"] .nav-item{color:#b8c3c7}
html[data-theme="dark"] .nav-item:hover{
  background:rgba(255,188,54,.085);
  color:#fff;
}
html[data-theme="dark"] .nav-item.active{
  background:linear-gradient(90deg,rgba(255,188,54,.18),rgba(255,188,54,.025));
  box-shadow:inset 3px 0 var(--primary);
  color:#fff;
}
html[data-theme="dark"] .nav-count{
  color:#f9e6c0;
  background:rgba(255,188,54,.12);
}
html[data-theme="dark"] .topbar{
  background:rgba(17,21,22,.93);
  border-bottom:1px solid #333a3e;
}
html[data-theme="dark"] .eyebrow,
html[data-theme="dark"] .panel-kicker{
  color:var(--primary);
  letter-spacing:.13em;
}
html[data-theme="dark"] .hero-row h2,
html[data-theme="dark"] .page-toolbar h2{
  color:#f7f4ec;
  font-weight:850;
  letter-spacing:-.035em;
}
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .panel{
  border:1px solid #363d40;
  background:linear-gradient(165deg,#1d2224,#171b1d);
}
html[data-theme="dark"] .metric-card{
  position:relative;
  overflow:hidden;
  border-top:2px solid rgba(255,188,54,.72);
}
html[data-theme="dark"] .metric-card>strong{
  color:#fff7e6;
  font-variant-numeric:tabular-nums;
  letter-spacing:-.035em;
}
html[data-theme="dark"] .metric-icon{
  background:rgba(255,188,54,.12);
  color:#ffc04a;
}
html[data-theme="dark"] .panel h3{color:#fbf6ec}
html[data-theme="dark"] .btn.primary{
  background:linear-gradient(180deg,#ffd06b,#ffb52d);
  color:#241900;
  border:1px solid #ffcd5a;
  box-shadow:0 3px 10px rgba(255,179,30,.12);
}
html[data-theme="dark"] .btn.primary:hover{
  background:#ffd779;
  color:#201600;
}
html[data-theme="dark"] .btn.secondary,
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .search-box{
  border-color:var(--line);
  background:#22282a;
  color:var(--text);
}
html[data-theme="dark"] .btn.secondary:hover,
html[data-theme="dark"] .icon-btn:hover{
  border-color:rgba(255,188,54,.65);
}
html[data-theme="dark"] .segmented button.active{
  background:#39372d;
  color:#ffcf6b;
}
html[data-theme="dark"] .control,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea{
  accent-color:var(--primary);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder{color:#98a6aa}
html[data-theme="dark"] th,
html[data-theme="dark"] .cf-table th{
  background:#22282a;
  color:#cbd3d5;
  font-size:11px;
}
html[data-theme="dark"] tbody tr:hover{background:rgba(255,188,54,.055)}
/* Revenue charts use the original WEB main blue in both themes. */
html[data-theme="dark"] .chart-bar,
html[data-theme="light"] .chart-bar{fill:var(--chart-primary)}
html[data-theme="dark"] .chart-line,
html[data-theme="dark"] .chart-dot,
html[data-theme="light"] .chart-line,
html[data-theme="light"] .chart-dot{stroke:var(--chart-primary)}
html[data-theme="dark"] .connection-card{
  background:#1b2123;
  border-color:#41494b;
}
html[data-theme="dark"] .connection-card>span,
html[data-theme="dark"] .version{color:#a6b5b9}
html[data-theme="dark"] .revenue-filters,
html[data-theme="dark"] .revenue-summary-grid>div,
html[data-theme="dark"] .cf-metric{
  background:#202628;
  border-color:#394244;
}
html[data-theme="dark"] .cf-metric strong{color:#fff1cd}
html[data-theme="dark"] .cf-payment-dialog{
  background:#1c2224;
  border-color:#4c5659;
  color:var(--text);
}
html[data-theme="dark"] .auth-brand{
  background:
    linear-gradient(180deg,rgba(14,17,18,.06),#101315),
    linear-gradient(rgba(255,188,54,.035) 1px,transparent 1px),
    linear-gradient(90deg,rgba(255,188,54,.035) 1px,transparent 1px),
    #171b1d;
  background-size:auto,32px 32px,32px 32px,auto;
  border-right:2px solid #c38a21;
}
html[data-theme="dark"] .auth-brand h1{color:#fff3d6}
html[data-theme="dark"] .auth-brand p,
html[data-theme="dark"] .auth-point{color:#d5dddf}
html[data-theme="dark"] .auth-shell{
  border-color:#3b4346;
  box-shadow:0 25px 80px rgba(0,0,0,.32);
}
html[data-theme="dark"] .auth-form .btn.primary{font-weight:800}
html[data-theme="dark"] .auth-footer a{color:#ffca62}
html[data-theme="dark"] .field input:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(255,188,54,.18);
}
:where(.btn,.icon-btn,.nav-item,.user-chip,.control,input,select,textarea,button):focus-visible{
  outline:2px solid var(--primary);
  outline-offset:2px;
}
@media(max-width:860px){
  html[data-theme="dark"] .topbar{background:rgba(17,21,22,.97)}
  html[data-theme="dark"] .metric-card{border-top-width:2px}
}
@media(prefers-reduced-motion:reduce){
  .nav-item,.btn,.chart-bar{transition:none!important}
}


/* === Operations UI contract: one accessible token set shared by desktop/mobile. === */
html[data-theme="light"]{
  color-scheme:light;
  --chart-primary:#5b84f1;
  --chart-hover:#4777ee;
  --text:#16283c;
  --muted:#40556d;
  --line:#c4cfdb;
  --success:#18734b;
  --warning:#916209;
  --danger:#b92c43;
  --control-bg:#ffffff;
  --control-border:#aebed0;
  --control-text:#172a40;
  --control-placeholder:#5a6b81;
  --status-ok-bg:#e6f5eb;
  --status-ok-text:#126740;
  --status-ok-line:#3d9370;
  --status-warn-bg:#fff1d3;
  --status-warn-text:#785006;
  --status-warn-line:#a4751b;
  --status-error-bg:#fde8ec;
  --status-error-text:#ab203b;
  --status-error-line:#c85268;
}
html[data-theme="dark"]{
  --chart-primary:#5b84f1;
  --chart-hover:#7aa2ff;
  --control-bg:#172330;
  --control-border:#455a70;
  --control-text:#eff5ff;
  --control-placeholder:#a5b7c9;
  --status-ok-bg:#123b30;
  --status-ok-text:#76e5b3;
  --status-ok-line:#328362;
  --status-warn-bg:#3c300f;
  --status-warn-text:#ffd579;
  --status-warn-line:#917327;
  --status-error-bg:#3a202b;
  --status-error-text:#ffa1ae;
  --status-error-line:#9b4859;
}
/* Contrast is semantic: never use pale foreground text on light status fills. */
.badge.online,.health-state.state-ok,.mini-tag.good,
.state-ok{
  color:var(--status-ok-text);
  background:var(--status-ok-bg);
  border:1px solid var(--status-ok-line);
}
.badge.warning,.health-state.state-warning,.mini-tag.warn,
.state-warning{
  color:var(--status-warn-text);
  background:var(--status-warn-bg);
  border:1px solid var(--status-warn-line);
}
.badge.offline,.health-state.state-error,.mini-tag.bad,
.state-error{
  color:var(--status-error-text);
  background:var(--status-error-bg);
  border:1px solid var(--status-error-line);
}
html[data-theme="light"] .panel-kicker,
html[data-theme="light"] .eyebrow{color:#365879}
html[data-theme="light"] .metric-head,
html[data-theme="light"] .metric-foot,
html[data-theme="light"] .demo-statusline>span:first-child,
html[data-theme="light"] .demo-table th,
html[data-theme="light"] .cf-mini{color:var(--muted)}
html[data-theme="light"] .panel,
html[data-theme="light"] .metric-card{border-color:#cbd5e2}
html[data-theme="light"] .demo-statusline{border-bottom-color:#cbd5e2}
html[data-theme="light"] .chart-label,
html[data-theme="light"] .chart-y-label{fill:var(--muted)}
/* Trend classes: up=green, flat=yellow, down=red across all themes. */
.trend,.growth{font-weight:800;font-variant-numeric:tabular-nums}
.trend.up,.growth--up{color:var(--status-ok-text)}
.trend.flat,.growth--flat{color:var(--status-warn-text)}
.trend.down,.growth--down{color:var(--status-error-text)}
/* Native options must use their own contrasting foreground and background. */
.control,
select,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
textarea,
.account-field select,
.account-field input,
.field input,
.cf-toolbar select,
.cf-toolbar input{
  background-color:var(--control-bg);
  border:1px solid var(--control-border);
  color:var(--control-text);
  accent-color:var(--chart-primary);
  border-radius:10px;
}
select,
.control,
.account-field select,
.field input{
  min-height:40px;
}
select option,
select optgroup{
  background-color:var(--control-bg);
  color:var(--control-text);
}
input::placeholder,textarea::placeholder{color:var(--control-placeholder);opacity:1}
:where(select,input,textarea,.control):focus-visible{
  outline:2px solid var(--chart-primary);
  outline-offset:2px;
  border-color:var(--chart-primary);
}
:where(select,input,textarea,.control):disabled{opacity:.68;cursor:not-allowed}
html[data-theme="light"] th,
html[data-theme="light"] .cf-table th{background:#f1f5fa;color:#334b64}
html[data-theme="light"] .action-menu-popover{
  color:#17283c;
  background:#fff;
  border-color:#aabdd0;
  box-shadow:0 17px 44px #1d375038;
}
html[data-theme="dark"] .action-menu-popover{
  color:var(--text);
  background:#172331;
  border-color:#4a6076;
  box-shadow:0 18px 45px #0009;
}
.action-menu-popover button{min-height:38px}
.action-menu-popover button:focus-visible{
  background:var(--surface-2);
  outline:2px solid var(--chart-primary);
  outline-offset:-2px;
}
.action-menu[open]{position:relative;z-index:85}
.action-menu.is-align-start .action-menu-popover{right:auto;left:0}
.action-menu.is-drop-up .action-menu-popover{top:auto;bottom:calc(100% + 6px)}
/* Any native dialog in the top layer must be reachable after page scrolling. */
dialog.bank-dialog[open],
dialog.cf-payment-dialog[open]{
  position:fixed;
  inset:0;
  margin:auto;
  width:min(720px,calc(100vw - 32px));
  max-width:calc(100vw - 32px);
  max-height:calc(100dvh - 32px);
  overflow:auto;
  transform:none;
  overscroll-behavior:contain;
}
dialog.bank-dialog[open] .bank-dialog-card{max-height:calc(100dvh - 40px);overflow-y:auto}
dialog.cf-payment-dialog[open]{max-width:min(780px,calc(100vw - 32px))}
dialog.bank-dialog::backdrop,dialog.cf-payment-dialog::backdrop{
  background:rgba(7,11,19,.66);
}
/* Bất kể bề rộng: menu hành động không bao giờ cao hơn màn hình, tự cuộn bên
   trong. Áp cho cả trường hợp Chrome "Desktop site" trên điện thoại (bề rộng
   CSS > 767px nhưng vẫn là màn hình cảm ứng). */
.action-menu-popover{
  max-height:calc(100vh - 24px);
  overflow-y:auto;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
}
@media (max-width:767px),(hover:none){
  html,body{max-width:100%;overflow-x:hidden}
  .workspace,.content,.panel,.metric-card{min-width:0}
  .topbar{z-index:25}
  .top-actions{flex-wrap:wrap}
  .revenue-filters,.cf-toolbar{max-width:100%}
  .cf-toolbar label{min-width:0}
  /* Menus are nonmodal. A body scrim would paint above device-category stacking
     contexts and intercept their buttons. Outside touch/Escape dismissal is
     owned by ui-overlays.js; modal dialogs keep their native ::backdrop. */
  .action-menu[open]{z-index:90}
  .action-menu[open] .action-menu-popover,
  .action-menu.is-align-start[open] .action-menu-popover,
  .action-menu.is-drop-up[open] .action-menu-popover{
    position:fixed;
    left:max(10px,env(safe-area-inset-left));
    right:max(10px,env(safe-area-inset-right));
    top:auto;
    bottom:max(8px,env(safe-area-inset-bottom));
    z-index:95;
    width:auto;
    min-width:0;
    max-width:none;
    /* Không cao quá viewport thật: sheet tự cuộn bên trong, các mục cuối
       (Wi-Fi, chuyển nhóm, tắt theo dõi, xoá) không bị đẩy ra ngoài màn hình.
       svh giữ đúng cả khi thanh địa chỉ đang hiện. */
    max-height:calc(100vh - 16px);
    max-height:calc(100svh - 16px);
    overflow-y:auto;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    touch-action:pan-y;
    scrollbar-width:thin;
    border-radius:18px;
    padding:12px;
    box-shadow:0 -12px 48px rgba(0,0,0,.32);
    display:grid;
    gap:3px;
  }
  .action-menu-popover button{font-size:14px;min-height:44px;padding:11px 13px}
  .action-menu-popover .menu-section-label{font-size:12px}
  .table-wrap:has(.action-menu[open]){overflow:auto;position:relative;z-index:100}
  .table-wrap:has(.action-menu[open]) .action-menu-popover{z-index:95}
  dialog.bank-dialog[open],dialog.cf-payment-dialog[open]{
    position:fixed;
    inset:0;
    margin:auto;
    width:calc(100vw - 20px);
    max-width:calc(100vw - 20px);
    max-height:calc(100dvh - 20px);
    min-width:0;
    min-height:0;
    resize:none;
    padding:0;
  }
  dialog.bank-dialog[open] .bank-dialog-card{
    max-height:calc(100dvh - 28px);
    overflow-x:hidden;
    overflow-y:auto;
    padding:16px;
  }
  dialog.cf-payment-dialog[open]{padding:16px}
  dialog.fleet-terminal-dialog[open]{min-width:0;width:calc(100vw - 20px);height:auto}
  .fleet-terminal-card{max-height:calc(100dvh - 28px)}
  .fleet-terminal-card .qr-terminal-log{max-height:40dvh;min-height:160px}
}
@media(max-width:480px){
  .metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .metric-card{padding:13px 11px}
  .metric-card>strong{font-size:clamp(18px,5vw,26px)}
  .dashboard-grid,.dashboard-grid.lower{grid-template-columns:minmax(0,1fr)}
  .cf-toolbar{gap:8px}
  .cf-toolbar label{flex:1 1 140px}
}


/* Remember login is opt-in. Native checkbox never uses the text-input box style. */
.remember-login{
  display:flex;
  align-items:flex-start;
  gap:10px;
  color:var(--text);
  font-size:12px;
  line-height:1.55;
  cursor:pointer;
  user-select:none;
}
.remember-login input[type="checkbox"]{
  flex:0 0 18px;
  inline-size:18px;
  block-size:18px;
  margin:1px 0 0;
  accent-color:var(--chart-primary);
  cursor:pointer;
}
.remember-login span{flex:1;min-width:0}
@media(max-width:780px){
  body.auth-page{min-height:100dvh;padding:12px}
  .auth-panel{min-height:calc(100dvh - 24px);padding:24px 18px}
}
