/* ThaiSCADA Web — AutoView-style theme (light default, dark via body.dark).
   Dependency-free, responsive. All original class names + CSS variables are
   preserved so existing JS markup keeps working; new components (icon nav,
   device tree, tag cards, map, segmented control, chips) are additive. */
:root {
  --bg:        #eef1f5;   /* page background */
  --bg-2:      #ffffff;   /* bars / raised surfaces */
  --bg-3:      #f1f4f8;   /* hover / chips / inputs-alt */
  --panel:     #ffffff;   /* cards */
  --panel-2:   #f8fafc;   /* card header */
  --border:    #e4e9ef;
  --border-2:  #d3dae3;   /* stronger divider */
  --text:      #212b36;
  --text-dim:  #7b8794;
  --accent:    #2f80ed;
  --accent-2:  #1f6fd8;
  --accent-soft: rgba(47,128,237,.12);
  --good:      #1da75c;
  --good-soft: rgba(29,167,92,.13);
  --good-tint: #d6e9dd;   /* AutoView normal-card green */
  --warn:      #e0a83a;
  --bad:       #d9342b;
  --bad-soft:  rgba(217,52,43,.12);
  --bad-tint:  #efd4d3;   /* AutoView alarm-card red  */
  --stale:     #98a4b3;
  --ring:      0 0 0 3px rgba(47,128,237,.25);
  --radius:    12px;
  --radius-lg: 16px;
  --shadow:    0 8px 28px -10px rgba(16,24,40,.18);
  --shadow-sm: 0 1px 3px rgba(16,24,40,.08);
  --tr:        160ms cubic-bezier(.4,0,.2,1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  --mono: "Cascadia Code", "Fira Code", "SF Mono", Consolas, monospace;
  --chart-grid:  #e4e9ef;
  --chart-label: #7b8794;
  --chart-tip-bg: rgba(255,255,255,.96);
  --chart-tip-text: #212b36;
}
body.dark {
  --bg:        #0b0f16;
  --bg-2:      #11161f;
  --bg-3:      #1a212d;
  --panel:     #131924;
  --panel-2:   #172030;
  --border:    #262e3b;
  --border-2:  #313a49;
  --text:      #e7edf5;
  --text-dim:  #94a1b2;
  --accent:    #4a90ff;
  --accent-2:  #2f6fe0;
  --accent-soft: rgba(74,144,255,.14);
  --good:      #45c463;
  --good-soft: rgba(69,196,99,.14);
  --good-tint: rgba(69,196,99,.15);
  --bad:       #ff5d54;
  --bad-soft:  rgba(255,93,84,.14);
  --bad-tint:  rgba(255,93,84,.15);
  --stale:     #6e7a8a;
  --ring:      0 0 0 3px rgba(74,144,255,.32);
  --shadow:    0 6px 20px -6px rgba(0,0,0,.5);
  --shadow-sm: 0 2px 8px -2px rgba(0,0,0,.4);
  --chart-grid:  #2a313c;
  --chart-label: #9aa6b2;
  --chart-tip-bg: rgba(13,17,23,.92);
  --chart-tip-text: #e6edf3;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
::selection { background: rgba(47,128,237,.25); }
.tile .value, td.num, th.num, .clock, .k-value, .t-val, .tag-card .tc-val { font-variant-numeric: tabular-nums; }
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border: 2px solid transparent; background-clip: content-box; border-radius: 8px; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
svg.ico-svg { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor;
              stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- layout: top bar + main (AutoView style) ---- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 10px; flex: none; z-index: 20;
          height: 54px; padding: 0 16px; background: var(--bg-2); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 9px; padding-right: 10px; }
.brand b { font-size: 16.5px; font-weight: 700; letter-spacing: .2px; color: var(--accent); display: block; line-height: 1.05; }
.brand-sub { display: block; font-size: 9.5px; color: var(--text-dim); letter-spacing: .04em; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: #fff; object-fit: contain; padding: 2px;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.topbar .spacer { flex: 1; }
.topbar .clock { font-family: var(--mono); color: var(--text-dim); font-size: 13.5px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-dim); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--stale); transition: background var(--tr); }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

/* icon nav (desktop) */
.icon-nav { display: flex; align-items: center; gap: 2px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
            border: none; background: transparent; color: var(--text-dim); border-radius: 10px; cursor: pointer;
            transition: background var(--tr), color var(--tr); }
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }

/* avatar + user dropdown */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #35b5d8);
          color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
          font-size: 14px; cursor: pointer; user-select: none; flex: none; }
.user-wrap { position: relative; display: flex; align-items: center; }
.user-menu { position: absolute; top: 42px; right: 0; width: 230px; background: var(--bg-2);
             border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 8px;
             z-index: 40; animation: pop 160ms cubic-bezier(.34,1.4,.5,1); }
.user-menu .um-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.user-menu .um-head .nm { font-weight: 650; font-size: 14px; line-height: 1.2; }
.user-menu .um-head .rl { color: var(--text-dim); font-size: 12px; text-transform: capitalize; }
.um-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer;
           font-size: 13.5px; color: var(--text); transition: background var(--tr); }
.um-item:hover { background: var(--bg-3); }
.um-item.danger { color: var(--bad); }

/* mobile drawer nav */
.side { position: fixed; top: 0; left: 0; bottom: 0; width: 256px; z-index: 45; background: var(--bg-2);
        border-right: 1px solid var(--border); padding: 14px 10px; overflow-y: auto;
        transform: translateX(-100%); transition: transform .24s cubic-bezier(.4,0,.2,1); box-shadow: none; }
.side.open { transform: translateX(0); box-shadow: var(--shadow); }
.side-bg { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 44; }
.nav-item { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 13px; border-radius: 10px;
            color: var(--text-dim); cursor: pointer; margin-bottom: 3px; user-select: none;
            font-size: 14px; font-weight: 500; transition: background var(--tr), color var(--tr); }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 22px; text-align: center; flex: none; display: inline-flex; justify-content: center; }
.nav-sep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; font-weight: 600;
           color: var(--stale); padding: 16px 13px 6px; }

.main { flex: 1; overflow-y: auto; padding: 24px 28px; scroll-behavior: smooth; position: relative; }
.main.full { padding: 0; overflow: hidden; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
.page-sub { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; }

/* ---- tiles ---- */
.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 16px 17px; box-shadow: var(--shadow-sm); transition: border-color var(--tr), box-shadow var(--tr); }
.tile:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.tile .label { color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 7px; letter-spacing: -.02em; line-height: 1.1; }
.tile .value small { font-size: 14px; color: var(--text-dim); font-weight: 400; }
.tile .meta { margin-top: 9px; font-size: 12px; color: var(--text-dim); display: flex; gap: 8px; align-items: center; }
.tile.bad { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad-soft), var(--shadow-sm); }
.spark { display: block; width: 100%; height: 34px; margin-top: 10px; }

/* ---- panels & tables ---- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
         box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--border);
              background: var(--panel-2); flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.panel-head .spacer, .spacer { flex: 1; }
.panel-body { padding: 4px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
     position: sticky; top: 0; background: var(--panel-2); z-index: 1; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tbody tr { transition: background var(--tr); }
tbody tr:hover { background: var(--bg-3); }

/* ---- badges / status ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px;
         font-size: 12px; font-weight: 500; background: var(--bg-3); color: var(--text-dim); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; box-shadow: none; }
.badge.good { color: var(--good); background: var(--good-soft); } .badge.good .dot { background: var(--good); }
.badge.error { color: var(--bad); background: var(--bad-soft); }  .badge.error .dot { background: var(--bad); }
.badge.idle { color: var(--text-dim); }
.q-good { color: var(--good); } .q-bad { color: var(--bad); } .q-stale { color: var(--stale); }
/* solid value badges (AutoView "Normal" / "OFF") */
.vbadge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 20px;
          font-size: 11.5px; font-weight: 650; color: #fff; white-space: nowrap; }
.vbadge.ok { background: var(--good); }
.vbadge.alarm { background: var(--bad); }
.vbadge.idle { background: var(--stale); }

/* ---- buttons / forms ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
       background: var(--bg-2); color: var(--text); border: 1px solid var(--border-2);
       padding: 9px 15px; border-radius: 9px; cursor: pointer; font-size: 13.5px; font-weight: 550;
       transition: background var(--tr), border-color var(--tr), transform var(--tr); }
.btn:hover { border-color: var(--accent); background: var(--bg-3); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea { background: var(--bg-2); color: var(--text); border: 1px solid var(--border-2);
                padding: 9px 12px; border-radius: 9px; font-size: 14px; font-family: inherit; width: 100%;
                transition: border-color var(--tr), box-shadow var(--tr); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="color"] { padding: 3px; height: 38px; }
label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; color: var(--text-dim); font-size: 12.5px; font-weight: 500; margin-bottom: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* segmented control (Card | List) */
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: none; background: transparent; color: var(--text-dim); font-size: 12.5px; font-weight: 600;
              padding: 5px 14px; border-radius: 7px; cursor: pointer; transition: background var(--tr), color var(--tr); }
.seg button.active { background: var(--accent); color: #fff; }

/* range chips (Today / Yesterday / …) */
.chips { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--border-2); background: var(--bg-2); color: var(--text-dim); font-size: 12.5px;
        font-weight: 550; padding: 4px 13px; border-radius: 20px; cursor: pointer;
        transition: background var(--tr), color var(--tr), border-color var(--tr); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* series pill (chart legend) */
.pill { display: inline-flex; align-items: center; padding: 2px 11px; border-radius: 14px; color: #fff;
        font-size: 11.5px; font-weight: 650; }

/* search box with icon */
.searchbox { position: relative; }
.searchbox .ico-svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px;
                      color: var(--stale); pointer-events: none; }
.searchbox input { padding-left: 34px; background: var(--bg-3); border-color: var(--border); }

/* ---- device tree (Realtime sidebar / Maps panel) ---- */
.tree { font-size: 13.5px; user-select: none; }
.tree .tr-grp { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px; cursor: pointer;
                font-weight: 600; color: var(--text); }
.tree .tr-grp:hover { background: var(--bg-3); }
.tree .tr-grp .cnt { margin-left: auto; color: var(--text-dim); font-weight: 500; font-size: 12px; }
.tree .tr-grp .chev { transition: transform var(--tr); color: var(--text-dim); display: inline-flex; }
.tree .tr-grp.closed .chev { transform: rotate(-90deg); }
.tree .tr-kids { margin-left: 10px; }
.tree .tr-grp.closed + .tr-kids { display: none; }
/* top-level Site header: a touch bolder + tinted, with a divider above */
.tree .tr-site { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
                 color: var(--accent); margin-top: 4px; }
.tree .tr-site .cnt { color: var(--text-dim); }
.tree .tr-site + .tr-kids { margin-left: 8px; border-left: 1px solid var(--border); padding-left: 6px; }
.tree .tr-dev { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 8px;
                cursor: pointer; color: var(--text-dim); transition: background var(--tr), color var(--tr); }
.tree .tr-dev:hover { background: var(--bg-3); color: var(--text); }
.tree .tr-dev.active { background: var(--accent-soft); color: var(--accent); }
.tree .tr-dev b { color: var(--text); font-weight: 600; }
.tree .tr-dev.active b { color: var(--accent); }
.tree .tr-dev .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.st-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--stale); }
.st-dot.on { background: var(--good); } .st-dot.err { background: var(--bad); }

/* ---- Realtime layout (rendered inside .main.full) ---- */
.rt-layout { display: flex; gap: 0; height: 100%; }
.rt-side { width: 258px; flex: none; background: var(--bg-2); border-right: 1px solid var(--border);
           padding: 14px 10px; overflow-y: auto; }
.rt-side h4 { margin: 2px 6px 10px; font-size: 14px; display: flex; }
.rt-side h4 .cnt { margin-left: auto; color: var(--text-dim); font-weight: 500; }
.rt-main { flex: 1; overflow-y: auto; min-width: 0; }
.rt-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;
            color: var(--stale); gap: 10px; }
.rt-empty .ico-svg { width: 44px; height: 44px; stroke-width: 1.2; }

/* device panel (shared by Realtime + Maps overlay) */
.dev-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px;
            background: var(--good-tint); border-left: 4px solid var(--good); flex-wrap: wrap; }
.dev-head.alarm { background: var(--bad-tint); border-left-color: var(--bad); }
.dev-head.off { background: var(--bg-3); border-left-color: var(--stale); }
.dev-head .dh-name { font-size: 16.5px; font-weight: 700; line-height: 1.25; }
.dev-head .dh-desc { color: var(--text-dim); font-size: 13px; }
.dev-head .dh-time { font-family: var(--mono); font-size: 13px; color: var(--text-dim); }
.dev-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.dev-tabs .tab { padding: 11px 4px; margin-right: 14px; font-size: 13.5px; font-weight: 600; color: var(--text-dim);
                 border-bottom: 2px solid transparent; cursor: pointer; }
.dev-tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.dev-meta { display: flex; align-items: center; gap: 6px; padding: 8px 20px; font-size: 12.5px; color: var(--text-dim);
            justify-content: flex-end; }
.dev-tools { display: flex; align-items: center; gap: 10px; padding: 4px 20px 12px; flex-wrap: wrap; }
.dev-tools .searchbox { flex: 1; max-width: 300px; }
.tag-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); padding: 4px 20px 22px; }
.tag-card { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 13px 15px;
            box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 3px; min-height: 84px; }
.tag-card .tc-alarm { position: absolute; top: 6px; right: 6px; border: none; background: transparent; cursor: pointer;
                      font-size: 13px; line-height: 1; padding: 3px 5px; border-radius: 7px; opacity: 0; transition: opacity var(--tr), background var(--tr); }
.tag-card:hover .tc-alarm { opacity: .65; }
.tag-card .tc-alarm:hover { opacity: 1; background: var(--bg-3); }
.tag-card .tc-name { font-size: 13px; font-weight: 600; color: var(--text); }
.tag-card .tc-row { display: flex; align-items: flex-end; gap: 8px; margin-top: auto; }
.tag-card .tc-val { font-size: 21px; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.tag-card .tc-unit { font-size: 12px; color: var(--text-dim); padding-bottom: 2px; }
.tag-card .tc-badge { margin-left: auto; }
.tag-card.ok { background: var(--good-tint); border-color: transparent; }
.tag-card.alarm { background: var(--bad-tint); border-color: transparent; }
.tag-list tr.ok td { background: var(--good-tint); }
.tag-list tr.alarm td { background: var(--bad-tint); }

/* ---- Maps view ---- */
.map-wrap { position: absolute; inset: 0; overflow: hidden; background: #cdd6e0; touch-action: none; }
body.dark .map-wrap { background: #1a2230; }
.map-tiles { position: absolute; inset: 0; }
.map-tiles img { position: absolute; width: 256px; height: 256px; user-select: none; -webkit-user-drag: none; pointer-events: none; }
body.dark .map-tiles img { filter: brightness(.82) contrast(1.05) saturate(.85); }
.map-markers { position: absolute; inset: 0; pointer-events: none; }
.map-marker { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer;
              display: flex; flex-direction: column; align-items: center; gap: 3px; z-index: 5; }
.map-marker .mk-dot { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid #fff;
                      box-shadow: 0 1px 6px rgba(0,0,0,.35); background: var(--stale); }
.map-marker.on .mk-dot { background: var(--good); }
.map-marker.err .mk-dot { background: var(--bad); animation: mk-blink 1.2s ease-in-out infinite; }
.map-marker .mk-lbl { background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
                      font-size: 11.5px; font-weight: 650; padding: 1px 8px; border-radius: 7px;
                      box-shadow: var(--shadow-sm); white-space: nowrap; }
@keyframes mk-blink { 0%,100% { box-shadow: 0 1px 6px rgba(0,0,0,.35); } 50% { box-shadow: 0 0 0 7px var(--bad-soft); } }
.map-ui { position: absolute; z-index: 10; }
.map-legend { display: flex; align-items: center; gap: 10px; background: var(--bg-2);
              border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-sm);
              padding: 6px 14px; font-size: 12.5px; font-weight: 600; }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--text-dim); }
.map-btns { top: 12px; right: 0; left: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 0 12px; pointer-events: none; }
.map-btns > * { pointer-events: auto; }
.map-zoom { bottom: 18px; left: 12px; display: flex; flex-direction: column; gap: 6px; }
.map-zoom button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-2);
                   color: var(--text); font-size: 19px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow-sm); }
.map-zoom button:hover { border-color: var(--accent); color: var(--accent); }
.map-attr { bottom: 4px; right: 8px; font-size: 10.5px; color: var(--text-dim); background: color-mix(in srgb, var(--bg-2) 75%, transparent);
            padding: 1px 7px; border-radius: 6px; pointer-events: none; }
.map-panel { top: 58px; right: 12px; width: 300px; max-height: min(65vh, 520px); background: var(--bg-2);
             border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
             display: flex; flex-direction: column; animation: pop 160ms cubic-bezier(.34,1.4,.5,1); }
.map-panel .mp-head { display: flex; align-items: center; padding: 12px 14px 8px; font-weight: 700; font-size: 14.5px; }
.map-panel .mp-body { overflow-y: auto; padding: 4px 8px 10px; }
.map-devpanel { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 96vw); z-index: 15;
                background: var(--bg); border-left: 1px solid var(--border); box-shadow: -12px 0 32px -14px rgba(16,24,40,.3);
                overflow-y: auto; animation: slide-in .22s cubic-bezier(.4,0,.2,1); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
.map-note { top: 58px; left: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
            padding: 8px 13px; font-size: 12.5px; color: var(--text-dim); box-shadow: var(--shadow-sm); max-width: 300px; }

/* ---- Charts gallery (compact cards) ---- */
.chart-card { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
              box-shadow: var(--shadow-sm); padding: 13px 14px; cursor: pointer;
              transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr); }
.chart-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.chart-card .cc-ico { width: 34px; height: 34px; border-radius: 9px; flex: none;
                      display: inline-flex; align-items: center; justify-content: center; }
.chart-card .cc-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px;
                        background: var(--panel); border-radius: 8px; opacity: 0; transition: opacity var(--tr); }
.chart-card:hover .cc-tools { opacity: 1; }
.chart-card .cc-tools .icon-btn { width: 28px; height: 28px; }

/* ---- global alarm bell (top bar) ---- */
#alarm-bell { position: relative; }
#alarm-bell.has-alarm { color: var(--warn); }
#alarm-bell.critical { color: var(--bad); animation: bell-pulse 1.1s ease-in-out infinite; }
#alarm-bell .bell-count { position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px; background: var(--bad); color: #fff; font-size: 9.5px; font-weight: 700; line-height: 15px;
  text-align: center; display: none; }
#alarm-bell.has-alarm:not(.critical) .bell-count { background: var(--warn); }
@keyframes bell-pulse { 0%, 100% { transform: none; } 50% { transform: scale(1.14); } }

/* ---- HMI full-page viewer ---- */
.hmi-stage { position: absolute; inset: 0; overflow: hidden; background: #0d1117; }
.hmi-alarmbar { position: absolute; top: 0; left: 0; right: 0; z-index: 15; display: flex; align-items: center;
  gap: 14px; flex-wrap: wrap; padding: 9px 130px 9px 16px; font-size: 13px; color: #fff;
  background: linear-gradient(90deg, rgba(224,168,58,.96), rgba(224,168,58,.82)); box-shadow: 0 2px 12px rgba(0,0,0,.3); }
.hmi-alarmbar.critical { background: linear-gradient(90deg, rgba(217,52,43,.97), rgba(217,52,43,.85)); animation: alarmbar-flash 1.3s ease-in-out infinite; }
@keyframes alarmbar-flash { 0%, 100% { filter: none; } 50% { filter: brightness(1.18); } }
.hmi-alarmbar .hmi-alarm-ico { font-size: 16px; }
.hmi-alarmbar .hmi-alarm-item { background: rgba(0,0,0,.18); border-radius: 20px; padding: 2px 11px; font-size: 12px; white-space: nowrap; }
.hmi-alarmbar .btn { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.5); color: #fff; }
.hmi-ctl { position: absolute; top: 10px; right: 12px; z-index: 20; display: flex; gap: 5px; align-items: center;
           background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px 6px;
           box-shadow: var(--shadow-sm); opacity: .3; transition: opacity .18s; }
.hmi-ctl:hover, .hmi-ctl:focus-within { opacity: 1; }
.hmi-ctl select { width: auto; max-width: 180px; padding: 4px 8px; font-size: 12.5px; }
.hmi-ctl .icon-btn { width: 30px; height: 30px; font-size: 15px; }

/* ---- login (AutoView style) ---- */
#login-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
                 background: var(--bg); z-index: 100; flex-direction: column; gap: 0; }
.login-card { width: 360px; max-width: 92vw; background: var(--bg-2); border: 1px solid var(--border);
              border-radius: 18px; box-shadow: var(--shadow); padding: 34px 32px 26px; text-align: center; }
.login-card .lc-logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 14px;
                       display: block; background: #fff; object-fit: contain; padding: 4px;
                       box-shadow: var(--shadow-sm); }
.login-card h1 { margin: 0; font-size: 24px; font-weight: 800; color: var(--accent); letter-spacing: -.01em; }
.login-card .lc-sub { color: var(--text-dim); font-size: 13px; margin: 4px 0 22px; }
.login-card label.field { text-align: left; }
.login-card label.field > span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }
.login-foot { margin-top: 18px; color: var(--stale); font-size: 12px; }

/* ---- modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(3px); display: flex;
            align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; animation: fade var(--tr); }
body.dark .modal-bg { background: rgba(3,6,12,.66); }
.modal { background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius-lg);
         width: 560px; max-width: 100%; box-shadow: 0 24px 60px -12px rgba(16,24,40,.4); max-height: 86vh; overflow-y: auto;
         animation: pop 180ms cubic-bezier(.34,1.4,.5,1); }
.modal-head { display: flex; align-items: center; padding: 17px 20px; border-bottom: 1px solid var(--border);
              position: sticky; top: 0; background: var(--bg-2); z-index: 2; }
.modal-head h3 { margin: 0; flex: 1; font-size: 16px; font-weight: 650; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border);
              position: sticky; bottom: 0; background: var(--bg-2); }
.x { cursor: pointer; color: var(--text-dim); font-size: 22px; line-height: 1; padding: 0 4px; border-radius: 6px; transition: color var(--tr); }
.x:hover { color: var(--text); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }

.empty { color: var(--text-dim); text-align: center; padding: 44px 20px; font-size: 14px; }

/* HMI symbol animations (pump impeller spin, motor running pulse) */
@keyframes hmi-spin { to { transform: rotate(360deg); } }
@keyframes hmi-pulse { 0%,100% { filter: none; } 50% { filter: drop-shadow(0 0 7px var(--good)); } }
.hmi-spin { animation: hmi-spin 1.3s linear infinite; }
.hmi-pulse { animation: hmi-pulse 1.1s ease-in-out infinite; }
@keyframes hmi-flowbg { to { background-position: 24px 0; } }
@keyframes hmi-blink { 0%,49% { opacity: 1; } 50%,100% { opacity: .22; } }
@keyframes hmi-walk {
  0%   { transform: translateX(-38%) scaleX(1); }
  49%  { transform: translateX(38%)  scaleX(1); }
  50%  { transform: translateX(38%)  scaleX(-1); }
  99%  { transform: translateX(-38%) scaleX(-1); }
  100% { transform: translateX(-38%) scaleX(1); }
}
@keyframes hmi-alarm-glow { 0%, 100% { filter: none; } 50% { filter: brightness(1.14) saturate(1.1); } }
.hmi-alarm-glow { animation: hmi-alarm-glow 1.4s ease-in-out infinite; }
.hmi-flowbg { animation: hmi-flowbg .6s linear infinite; }
.hmi-blink  { animation: hmi-blink 1s steps(1) infinite; }
.hmi-walk   { animation: hmi-walk 2.4s ease-in-out infinite; }

.toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg-2); color: var(--text);
         border: 1px solid var(--border-2); border-left: 3px solid var(--accent); padding: 13px 17px;
         border-radius: 11px; box-shadow: var(--shadow); z-index: 60; max-width: 360px; font-size: 14px;
         animation: pop 200ms cubic-bezier(.34,1.4,.5,1); }
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--good); }

/* ---- responsive ---- */
.hamburger { display: none; align-items: center; justify-content: center; width: 38px; height: 38px;
             cursor: pointer; color: var(--text-dim); border-radius: 10px; flex: none; }
.hamburger:hover { color: var(--text); background: var(--bg-3); }

@media (max-width: 1080px) {
  .icon-nav { display: none; }
  .hamburger { display: inline-flex; }
}
@media (max-width: 1024px) {
  .main { padding: 22px 22px; }
  .page-title { font-size: 21px; }
}
@media (max-width: 820px) {
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  /* wide tables become horizontally scrollable instead of clipping/overflowing */
  .panel { overflow-x: auto; }
  .rt-layout { flex-direction: column; }
  .rt-side { width: 100%; max-height: 260px; border-right: none; border-bottom: 1px solid var(--border); }
  .modal-bg { padding: 20px 10px; align-items: flex-start; }
  .modal { border-radius: 14px; }
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; }   /* prevent iOS zoom */
  .page-title { font-size: 20px; }
  .toast { left: 12px; right: 12px; max-width: none; }
  .conn #conn-text { display: none; }
  .topbar .clock { display: none; }
  .tag-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); padding: 4px 14px 18px; }
  .dev-head, .dev-tabs, .dev-tools, .dev-meta { padding-left: 14px; padding-right: 14px; }
  .map-panel { width: min(300px, calc(100vw - 24px)); }
}
@media (max-width: 420px) {
  .main { padding: 13px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 13px; }
  .tile .value { font-size: 24px; }
  th, td { padding: 9px 12px; }
}

/* respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
      transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
