/* ════════════════════════════════════════════════════════════════════════
   METAL CRAFT SOLUTIONS — Industrial IoT Platform
   Design System  ·  light-default, auto day/night
   Type: IBM Plex Sans (UI) + IBM Plex Mono (numerics)
════════════════════════════════════════════════════════════════════════ */

/* ── TOKENS ──────────────────────────────────────────────────────────── */
:root, [data-theme="light"] {
  --bg:          #eef2f7;
  --bg-2:        #f6f8fb;
  --surface:     #ffffff;
  --surface-2:   #f7f9fc;
  --surface-3:   #eef2f7;
  --frost:       rgba(255,255,255,0.72);
  --rail:        #0f1d33;          /* sidebar / topbar dark rail */
  --rail-2:      #16263f;
  --rail-text:   #c3d0e4;
  --rail-sub:    #7d90ac;
  --rail-active: #2563eb;

  --text:        #0f1b2d;
  --text-2:      #475569;
  --text-3:      #94a3b8;
  --border:      #e2e8f0;
  --border-2:    #cbd5e1;
  --hairline:    rgba(15,27,45,0.06);

  --brand:       #2563eb;
  --brand-2:     #1d4ed8;
  --brand-soft:  rgba(37,99,235,0.10);
  --cyan:        #0ea5e9;
  --green:       #10b981;
  --green-soft:  rgba(16,185,129,0.12);
  --amber:       #f59e0b;
  --amber-soft:  rgba(245,158,11,0.13);
  --red:         #ef4444;
  --red-soft:    rgba(239,68,68,0.12);
  --violet:      #7c3aed;
  --violet-soft: rgba(124,58,237,0.12);

  --shadow-sm:   0 1px 2px rgba(15,27,45,0.06), 0 1px 3px rgba(15,27,45,0.04);
  --shadow-md:   0 4px 12px rgba(15,27,45,0.06), 0 2px 4px rgba(15,27,45,0.04);
  --shadow-lg:   0 18px 48px rgba(15,27,45,0.12), 0 6px 16px rgba(15,27,45,0.06);
  --shadow-rail: 0 8px 30px rgba(8,15,30,0.18);

  --r-sm: 8px;  --r-md: 12px; --r-lg: 16px; --r-xl: 22px;
  --ease: cubic-bezier(.22,.61,.36,1);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg:          #0a1422;
  --bg-2:        #0d1a2c;
  --surface:     #121f33;
  --surface-2:   #16263f;
  --surface-3:   #1c2f4a;
  --frost:       rgba(18,31,51,0.66);
  --rail:        #0a1422;
  --rail-2:      #101e33;
  --rail-text:   #cdd9ec;
  --rail-sub:    #6b7e9c;
  --rail-active: #3b82f6;

  --text:        #eef3fb;
  --text-2:      #aab8cd;
  --text-3:      #6b7e9c;
  --border:      rgba(255,255,255,0.09);
  --border-2:    rgba(255,255,255,0.14);
  --hairline:    rgba(255,255,255,0.06);

  --brand:       #3b82f6;
  --brand-2:     #2563eb;
  --brand-soft:  rgba(59,130,246,0.16);
  --cyan:        #38bdf8;
  --green:       #34d399;
  --green-soft:  rgba(52,211,153,0.15);
  --amber:       #fbbf24;
  --amber-soft:  rgba(251,191,36,0.15);
  --red:         #f87171;
  --red-soft:    rgba(248,113,113,0.16);
  --violet:      #a78bfa;
  --violet-soft: rgba(167,139,250,0.16);

  --shadow-sm:   0 1px 2px rgba(0,0,0,0.4);
  --shadow-md:   0 6px 18px rgba(0,0,0,0.4);
  --shadow-lg:   0 22px 54px rgba(0,0,0,0.55);
  --shadow-rail: 0 8px 30px rgba(0,0,0,0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--brand-soft); }

html { height: 100%; }
body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .5s var(--ease), color .5s var(--ease);
}
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-feature-settings: "tnum" 1; }
.tnum { font-variant-numeric: tabular-nums; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ── APP FRAME ───────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--rail-w, 248px) 1fr;
  height: 100vh;
  transition: grid-template-columns .32s var(--ease);
}
.app.rail-collapsed { --rail-w: 76px; }

/* ── SIDEBAR ─────────────────────────────────────────────────────────── */
.rail {
  background: var(--rail);
  color: var(--rail-text);
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
  position: relative; z-index: 40;
  overflow: hidden;
}
.rail-head {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brandmark { width: 34px; height: 34px; flex-shrink: 0; display: block; }
.brand-words { min-width: 0; transition: opacity .2s; }
.brand-words .bw-name { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; color: #fff; white-space: nowrap; }
.brand-words .bw-sub  { font-size: 10.5px; color: var(--rail-sub); white-space: nowrap; letter-spacing: .3px; }
.rail-collapsed .brand-words { opacity: 0; pointer-events: none; }

.rail-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 12px 8px; }
.rail-scroll::-webkit-scrollbar { width: 0; }
.nav-group-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--rail-sub); padding: 14px 12px 7px; white-space: nowrap;
}
.rail-collapsed .nav-group-label { opacity: 0; height: 8px; padding: 6px 0; }

.nav-item {
  display: flex; align-items: center; gap: 13px;
  height: 42px; padding: 0 13px; margin: 2px 0;
  border-radius: 10px; cursor: pointer;
  color: var(--rail-text); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  position: relative; white-space: nowrap;
  transition: background .16s, color .16s;
}
.nav-item .ni-ico { width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center; }
.nav-item .ni-ico svg { width: 19px; height: 19px; stroke: currentColor; }
.nav-item .ni-label { flex: 1; transition: opacity .2s; }
.nav-item .ni-badge {
  font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 20px;
  background: var(--red); color: #fff; font-family: 'IBM Plex Mono', monospace;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: linear-gradient(100deg, rgba(37,99,235,0.30), rgba(37,99,235,0.12)); color: #fff; }
.nav-item.active::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--rail-active);
}
.rail-collapsed .nav-item { justify-content: center; padding: 0; }
.rail-collapsed .nav-item .ni-label, .rail-collapsed .nav-item .ni-badge { opacity: 0; width: 0; pointer-events: none; }

/* tooltip when collapsed */
.rail-collapsed .nav-item[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
  background: var(--rail-2); color: #fff; font-size: 12px; font-weight: 600;
  padding: 6px 11px; border-radius: 7px; white-space: nowrap; z-index: 60;
  box-shadow: var(--shadow-rail); border: 1px solid rgba(255,255,255,0.08);
}
.rail-foot { flex-shrink: 0; padding: 10px 12px 14px; border-top: 1px solid rgba(255,255,255,0.06); }
.rail-user {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 11px;
  cursor: pointer; transition: background .15s;
}
.rail-user:hover { background: rgba(255,255,255,0.06); }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
}
.rail-user-meta { min-width: 0; transition: opacity .2s; }
.rail-user-meta .ru-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; }
.rail-user-meta .ru-role { font-size: 11px; color: var(--rail-sub); white-space: nowrap; }
.rail-collapsed .rail-user-meta { opacity: 0; width: 0; }

.rail-toggle {
  position: absolute; top: 74px; right: -12px; z-index: 50;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sm); transition: transform .3s var(--ease);
}
.rail-toggle:hover { color: var(--brand); }
.rail-toggle svg { width: 14px; height: 14px; transition: transform .3s var(--ease); }
.rail-collapsed .rail-toggle svg { transform: rotate(180deg); }

/* ── MAIN COLUMN ─────────────────────────────────────────────────────── */
.col { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  height: 64px; flex-shrink: 0;
  background: var(--frost);
  backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 22px;
  position: relative; z-index: 30;
}
.tb-title { min-width: 0; }
.tb-title h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.3px; line-height: 1.1; }
.tb-title .tb-crumb { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.tb-spacer { flex: 1; }

.search {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; height: 38px; width: 260px;
  transition: border-color .15s, box-shadow .15s, width .2s;
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); width: 300px; }
.search svg { width: 16px; height: 16px; stroke: var(--text-3); flex-shrink: 0; }
.search input { border: none; background: none; outline: none; font-size: 13px; color: var(--text); width: 100%; font-family: inherit; }
.search .kbd { font-size: 10.5px; color: var(--text-3); border: 1px solid var(--border-2); border-radius: 5px; padding: 1px 5px; font-family: 'IBM Plex Mono', monospace; }

.shift-pill {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 13px; height: 38px;
}
.shift-pill .sp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.shift-pill .sp-meta { line-height: 1.15; }
.shift-pill .sp-k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); }
.shift-pill .sp-v { font-size: 12.5px; font-weight: 600; }
.clock { text-align: right; line-height: 1.15; padding-right: 2px; }
.clock .clk-time { font-size: 14px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; letter-spacing: .5px; }
.clock .clk-date { font-size: 10.5px; color: var(--text-3); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; display: grid; place-items: center;
  position: relative; transition: all .15s;
}
.icon-btn:hover { color: var(--brand); border-color: var(--border-2); background: var(--surface); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; }
.icon-btn .dot-badge {
  position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); border: 2px solid var(--surface);
}

/* ── PAGE / SCROLL AREA ──────────────────────────────────────────────── */
.page { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }
.page-in { max-width: 1560px; margin: 0 auto; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.view { animation: viewIn .4s var(--ease) both; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 4px 2px 14px; }
.section-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.2px; }
.section-head .sh-sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.section-head + .section-head { margin-top: 26px; }

/* ── BUTTONS / CHIPS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border-radius: 9px; padding: 8px 15px; border: 1px solid transparent;
  transition: all .15s; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; stroke: currentColor; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 12px var(--brand-soft); }
.btn-primary:hover { background: var(--brand-2); transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface); border-color: var(--border-2); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  border: none; background: none; color: var(--text-3);
  padding: 6px 13px; border-radius: 7px; transition: all .15s; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.active { background: var(--surface-3); }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; }

/* status semantic */
.s-run    { --c: var(--green);  --cs: var(--green-soft); }
.s-idle   { --c: var(--amber);  --cs: var(--amber-soft); }
.s-alarm  { --c: var(--red);    --cs: var(--red-soft); }
.s-maint  { --c: var(--brand);  --cs: var(--brand-soft); }
.s-off    { --c: var(--text-3); --cs: var(--surface-3); }
.chip.byst { background: var(--cs); color: var(--c); }
.chip.byst .chip-dot { background: var(--c); }

/* ── CARD ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  transition: box-shadow .25s var(--ease), transform .25s var(--ease), border-color .2s;
}
.card-pad { padding: 18px; }

/* ── KPI ─────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 15px 16px 13px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: transform .22s var(--ease), box-shadow .22s var(--ease);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--cs, var(--brand-soft)); color: var(--c, var(--brand)); }
.kpi-ico svg { width: 18px; height: 18px; stroke: currentColor; }
.kpi-trend { font-size: 11.5px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; display: inline-flex; align-items: center; gap: 3px; }
.kpi-trend.up { color: var(--green); } .kpi-trend.down { color: var(--red); } .kpi-trend.flat { color: var(--text-3); }
.kpi-val { font-size: 28px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; line-height: 1; letter-spacing: -0.5px; }
.kpi-val .ku { font-size: 14px; color: var(--text-3); font-weight: 600; margin-left: 2px; }
.kpi-lbl { font-size: 11.5px; color: var(--text-3); margin-top: 6px; font-weight: 500; }
.kpi-spark { position: absolute; right: 0; bottom: 0; width: 86px; height: 38px; opacity: .9; }

/* ── MACHINE CARD ────────────────────────────────────────────────────── */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.mcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); overflow: hidden; position: relative;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .2s;
  display: flex; flex-direction: column;
}
.mcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c, var(--text-3)); }
.mcard:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.mcard.alarm { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.mc-head { padding: 15px 17px 12px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.mc-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.mc-thumb {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.mc-thumb svg { width: 22px; height: 22px; stroke: currentColor; }
.mc-name { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-model { font-size: 11px; color: var(--text-3); font-family: 'IBM Plex Mono', monospace; margin-top: 1px; }
.mc-live { font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; display: inline-flex; align-items: center; gap: 5px; color: var(--c); }
.mc-live .lv-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.mc-live .lv-dot.beat { animation: beat 2s ease infinite; box-shadow: 0 0 0 0 var(--c); }
@keyframes beat { 0%{box-shadow:0 0 0 0 var(--cs);} 60%{box-shadow:0 0 0 7px transparent;} 100%{box-shadow:0 0 0 0 transparent;} }

.mc-alarm-banner { background: var(--red-soft); color: var(--red); font-size: 11.5px; font-weight: 600; padding: 6px 17px; display: flex; align-items: center; gap: 7px; border-top: 1px solid color-mix(in srgb, var(--red) 25%, transparent); }
.mc-alarm-banner svg { width: 14px; height: 14px; }

.mc-metrics { padding: 6px 17px 4px; display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; }
.mc-metric { text-align: center; padding: 7px 4px; }
.mc-metric .mm-val { font-size: 19px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; line-height: 1; letter-spacing: -0.5px; }
.mc-metric .mm-lbl { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); margin-top: 4px; }

.mc-bars { padding: 10px 17px 6px; display: flex; flex-direction: column; gap: 9px; border-top: 1px solid var(--hairline); }
.bar-row .bar-hd { display: flex; justify-content: space-between; font-size: 10.5px; margin-bottom: 4px; }
.bar-row .bar-k { color: var(--text-3); text-transform: uppercase; letter-spacing: .4px; }
.bar-row .bar-v { font-weight: 700; font-family: 'IBM Plex Mono', monospace; }
.track { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.track .fill { height: 100%; border-radius: 4px; transition: width .9s var(--ease); }

.mc-foot { margin-top: auto; padding: 11px 17px; border-top: 1px solid var(--hairline); display: flex; align-items: center; gap: 9px; }
.op { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; }
.op .op-av { width: 26px; height: 26px; border-radius: 7px; background: var(--surface-3); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--text-2); flex-shrink: 0; }
.op .op-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op .op-k { font-size: 9.5px; color: var(--text-3); }

/* ── MACHINE CARD v2 (rich, reference-matched) ──────────────────────── */
.mc-badges { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; align-content: flex-start; max-width: 150px; }
.badge2 {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px; background: var(--cs); color: var(--c); white-space: nowrap;
}
.badge2 .b2-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.badge2 .b2-dot.beat { animation: beat 2s ease infinite; }

.mc-banner {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 17px; font-size: 11.5px; font-weight: 500;
  border-top: 1px solid var(--hairline);
}
.mc-banner .bn-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.mc-banner.off  { background: var(--red-soft);  color: var(--red); }
.mc-banner.off .bn-dot { background: var(--red); animation: beat 1.4s infinite; }
.mc-banner.late { background: var(--amber-soft); color: var(--amber); }
.mc-banner.late .bn-dot { background: var(--amber); animation: beat 1.4s infinite; }
.mc-banner b { font-weight: 700; }

.mc-soft-grid { padding: 6px 14px 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mc-soft { border-radius: 11px; padding: 9px 11px; text-align: center; border: 1px solid var(--border); }
.mc-soft .ms-lbl { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }
.mc-soft .ms-val { font-size: 17px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; margin: 4px 0 2px; line-height: 1; }
.mc-soft .ms-sub { font-size: 9.5px; color: var(--text-3); }
.mc-soft.tint-green  { background: var(--green-soft);  border-color: color-mix(in srgb, var(--green) 18%, transparent); }
.mc-soft.tint-green  .ms-val { color: var(--green); }
.mc-soft.tint-blue   { background: var(--brand-soft);  border-color: color-mix(in srgb, var(--brand) 18%, transparent); }
.mc-soft.tint-blue   .ms-val { color: var(--brand); }
.mc-soft.tint-violet { background: var(--violet-soft); border-color: color-mix(in srgb, var(--violet) 18%, transparent); }
.mc-soft.tint-violet .ms-val { color: var(--violet); }
.mc-soft.tint-cyan   { background: rgba(14,165,233,.1); border-color: rgba(14,165,233,.2); }
.mc-soft.tint-cyan   .ms-val { color: var(--cyan); }

.mc-parts2 { padding: 10px 14px; display: grid; grid-template-columns: 1fr 1fr; }
.mc-parts2 .part2 { text-align: center; }
.mc-parts2 .part2 + .part2 { border-left: 1px solid var(--hairline); }
.mc-parts2 .p2-val { font-size: 24px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; line-height: 1; letter-spacing: -0.5px; }
.mc-parts2 .p2-lbl { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }

.mc-alarm-row { display: flex; align-items: center; gap: 7px; padding: 8px 14px; font-size: 12.5px; font-weight: 600; border-top: 1px solid var(--hairline); }
.mc-alarm-row svg { width: 16px; height: 16px; }
.mc-alarm-row.ok  { color: var(--green); }
.mc-alarm-row.bad { color: var(--red); background: var(--red-soft); }

.bar-row .bar-sep { color: var(--text-3); font-weight: 500; }
.track.dual { background: color-mix(in srgb, var(--amber) 22%, var(--surface-3)); }

.op-input {
  flex: 1; min-width: 0; border: 1px solid transparent; background: transparent;
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--text);
  border-radius: 7px; padding: 5px 8px; outline: none; transition: all .14s;
}
.op-input:hover { border-color: var(--border); background: var(--surface-2); }
.op-input:focus { border-color: var(--brand); background: var(--surface-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.op-input::placeholder { color: var(--text-3); font-weight: 500; }
.mc-gear { width: 32px; height: 32px; flex-shrink: 0; }
.mc-gear svg { width: 16px; height: 16px; }
.mc-ts { font-size: 10px; color: var(--text-3); text-align: center; padding: 7px 14px; border-top: 1px solid var(--hairline); font-family: 'IBM Plex Mono', monospace; }

/* ── TABLE ───────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 600; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.tbl td { font-size: 13px; padding: 12px 14px; border-bottom: 1px solid var(--hairline); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* ── GAUGE / CHART HELPERS ───────────────────────────────────────────── */
.gauge-wrap { display: grid; place-items: center; position: relative; }
.gauge-center { position: absolute; text-align: center; }
.gauge-center .gc-val { font-size: 26px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; line-height: 1; }
.gauge-center .gc-lbl { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; }
.legend .lg { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); }
.legend .lg-sq { width: 10px; height: 10px; border-radius: 3px; }

/* ── AI PANEL ────────────────────────────────────────────────────────── */
/* Floating AI logo — orb with halo + gentle bob animation */
/* OLD simple AI FAB — only tooltip appears on hover */
.ai-fab {
  position: fixed; bottom: 26px; right: 26px; z-index: 80;
  width: 56px; height: 56px; border-radius: 17px; cursor: pointer; border: none;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(37,99,235,.45);
  transition: transform .2s var(--ease), box-shadow .2s;
}
.ai-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 16px 40px rgba(37,99,235,.55);
}
.ai-fab svg { width: 25px; height: 25px; }
.ai-fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* "Lumo Bot" tooltip — appears only on hover */
.ai-fab-tip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  padding: 8px 14px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #fff;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 10px;
  border: 1px solid rgba(124,58,237,0.4);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45), 0 0 18px rgba(124,58,237,0.25);
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .22s var(--ease), transform .28s var(--ease);
}
.ai-fab-tip::after {
  /* arrow */
  content: '';
  position: absolute; right: -5px; top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 9px; height: 9px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-right: 1px solid rgba(124,58,237,0.4);
  border-top:   1px solid rgba(124,58,237,0.4);
}
.ai-fab:hover .ai-fab-tip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* AI panel header buttons (clear, fullscreen, close) */
.ai-head-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  cursor: pointer; flex-shrink: 0;
  transition: all .18s var(--ease);
}
.ai-head-btn:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  transform: translateY(-1px);
}
.ai-head-btn svg { width: 16px; height: 16px; }

/* AI panel fullscreen mode */
.ai-panel.fullscreen {
  top: 0 !important; right: 0 !important;
  width: 100vw !important; max-width: 100vw !important;
  height: 100vh !important;
  border-left: none;
  border-radius: 0;
}
.ai-panel.fullscreen .ai-body { max-width: 900px; margin: 0 auto; width: 100%; }
.ai-panel.fullscreen .ai-presets { max-width: 900px; margin: 0 auto; width: 100%; }
.ai-panel.fullscreen .ai-input { max-width: 900px; margin: 0 auto; width: 100%; }

/* AI thinking animation — three bouncing dots */
.ai-thinking {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 12px 16px !important;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.ai-thinking .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--brand);
  animation: aiThink 1.3s ease-in-out infinite;
}
.ai-thinking .dot:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking .dot:nth-child(3) { animation-delay: 0.30s; }
.ai-thinking .label {
  font-size: 11.5px; color: var(--text-3); margin-left: 4px;
  font-style: italic;
}
@keyframes aiThink {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-7px); opacity: 1; }
}


.ai-scrim { position: fixed; inset: 0; background: rgba(8,15,30,.4); backdrop-filter: blur(2px); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .3s; }
.ai-scrim.open { opacity: 1; pointer-events: auto; }
.ai-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw; z-index: 100;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .36s var(--ease);
}
.ai-panel.open { transform: none; }
.ai-head { padding: 16px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); background: linear-gradient(120deg, var(--brand-soft), transparent); }
.ai-head .ai-ava { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg,#2563eb,#7c3aed); display: grid; place-items: center; color: #fff; }
.ai-head .ai-ava svg { width: 20px; height: 20px; }
.ai-head h3 { font-size: 14px; font-weight: 700; }
.ai-head .ai-sub { font-size: 11px; color: var(--text-3); display: flex; align-items: center; gap: 5px; }
.ai-head .ai-sub .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: beat 2s infinite; }
.ai-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 13px; }
.ai-msg { max-width: 86%; padding: 11px 14px; border-radius: 14px; font-size: 13px; line-height: 1.55; }
.ai-msg.bot { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; align-self: flex-start; }
.ai-msg.me { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.ai-msg.bot strong { color: var(--brand); }
.ai-presets { padding: 0 18px 8px; display: flex; gap: 7px; flex-wrap: wrap; }
.ai-preset { font-size: 11.5px; font-weight: 600; padding: 6px 11px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; transition: all .15s; }
.ai-preset:hover { border-color: var(--brand); color: var(--brand); }
.ai-input { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; gap: 9px; align-items: flex-end; }
.ai-input textarea { flex: 1; resize: none; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 10px 13px; font-family: inherit; font-size: 13px; color: var(--text); outline: none; max-height: 90px; }
.ai-input textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.ai-send { width: 40px; height: 40px; border-radius: 12px; border: none; background: var(--brand); color: #fff; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.ai-send svg { width: 18px; height: 18px; }

/* ── MODAL ───────────────────────────────────────────────────────────── */
.modal-scrim { position: fixed; inset: 0; background: rgba(8,15,30,.5); backdrop-filter: blur(3px); z-index: 110; display: none; align-items: center; justify-content: center; padding: 24px; }
.modal-scrim.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); width: 100%; max-width: 960px; max-height: 90vh; overflow: hidden; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: viewIn .26s var(--ease); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-body { overflow-y: auto; padding: 22px; }

/* ── MISC ────────────────────────────────────────────────────────────── */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--rail); color: #fff; font-size: 13px; font-weight: 500; padding: 11px 17px; border-radius: 11px; box-shadow: var(--shadow-rail); display: flex; align-items: center; gap: 9px; animation: viewIn .3s var(--ease); }
.toast svg { width: 16px; height: 16px; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────── */
@media (max-width: 1180px) { .kpi-grid { grid-template-columns: repeat(3,1fr); } }
@media (max-width: 980px) {
  .app { grid-template-columns: 0 1fr; }
  .rail { position: fixed; left: 0; top: 0; bottom: 0; width: 248px; transform: translateX(-100%); transition: transform .3s var(--ease); }
  .app.rail-open .rail { transform: none; }
  .rail-toggle { display: none; }
  .search { width: 150px; } .search:focus-within { width: 180px; }
}
@media (max-width: 720px) {
  .page { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .shift-pill, .search .kbd, .clock .clk-date { display: none; }
  .mgrid { grid-template-columns: 1fr; }
}
.hide-mobile { }
@media (max-width: 980px) { .menu-btn { display: grid !important; } }
.menu-btn { display: none; }

/* ── FORMS / SETTINGS ────────────────────────────────────────────────── */
.sfield {
  width: 220px; max-width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 9px 12px; font-size: 13px; font-family: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.sfield:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--surface); }
select.sfield { width: 100%; cursor: pointer; }
.flbl { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); margin-bottom: 6px; }

.tg { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.tg input { opacity: 0; width: 0; height: 0; }
.tg-track { position: absolute; inset: 0; background: var(--border-2); border-radius: 20px; transition: background .25s; }
.tg-track::before { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .25s var(--ease); }
.tg input:checked + .tg-track { background: var(--brand); }
.tg input:checked + .tg-track::before { transform: translateX(18px); }

.theme-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 8px; }
.theme-opt {
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 13px;
  padding: 18px 12px; cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  transition: all .18s;
}
.theme-opt svg { width: 24px; height: 24px; stroke: currentColor; }
.theme-opt:hover { border-color: var(--border-2); color: var(--text); }
.theme-opt.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-soft); }

.set-cat {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  font-family: inherit; font-size: 13px; font-weight: 500; color: var(--text-2);
  background: none; border: none; border-radius: 10px; padding: 10px 11px; cursor: pointer;
  transition: background .14s, color .14s;
}
.set-cat .ni-ico { width: 18px; height: 18px; display: grid; place-items: center; }
.set-cat .ni-ico svg { width: 17px; height: 17px; stroke: currentColor; }
.set-cat:hover { background: var(--surface-2); color: var(--text); }
.set-cat.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
