/* GEM Smart Infrastructure Dashboard — dark operations console */
:root {
  --bg:        #0b0f16;
  --bg-alt:    #10151f;
  --panel:     #141b27;
  --panel-2:   #1a2231;
  --line:      #232d3f;
  --line-soft: #1b2433;
  --text:      #e6edf7;
  --muted:     #8d9bb2;
  --dim:       #5f6d84;

  --ok:      #2ee6a8;
  --ok-dim:  rgba(46,230,168,.12);
  --warn:    #ffc247;
  --warn-dim:rgba(255,194,71,.12);
  --crit:    #ff5c7a;
  --crit-dim:rgba(255,92,122,.12);
  --info:    #4da3ff;
  --info-dim:rgba(77,163,255,.12);
  --accent:  #6f8cff;

  --r: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.chip, a.btn { color: inherit; text-decoration: none; }
a.chip:hover { border-color: var(--accent); color: var(--text); }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-2);
  padding: 1px 5px; border-radius: 4px; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-alt); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px 16px; border-bottom: 1px solid var(--line); }
.brand h1 { margin: 0; font-size: 15px; letter-spacing: .2px; font-weight: 650; }
.brand .sub { color: var(--dim); font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.4px; margin-top: 3px; }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 9px 12px; border-radius: 8px;
  color: var(--muted); cursor: pointer; margin-bottom: 2px; font-size: 13.5px;
}
.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.active { background: var(--panel-2); color: var(--text); font-weight: 550; }
.nav button.active .ic { color: var(--accent); }
.nav .ic { width: 16px; display: inline-flex; align-items: center;
  justify-content: center; color: var(--dim); }
.nav button:hover .ic { color: var(--muted); }
.btn svg, .chip svg { flex: none; }
#logout { display: inline-flex; align-items: center; gap: 6px; }
.nav .badge {
  margin-left: auto; background: var(--crit); color: #16060c; font-size: 10.5px;
  font-weight: 700; padding: 1px 6px; border-radius: 999px; min-width: 18px;
  text-align: center;
}
.nav .badge.zero { display: none; }
.nav-sep { color: var(--dim); font-size: 10px; text-transform: uppercase;
  letter-spacing: 1.2px; padding: 16px 12px 6px; }

.side-foot { padding: 12px 16px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--dim); }
.side-foot .row { display: flex; justify-content: space-between; margin-bottom: 4px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 22px;
  border-bottom: 1px solid var(--line); background: rgba(11,15,22,.85);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.content { padding: 22px; max-width: 1680px; width: 100%; }

/* ------------------------------------------------------------- primitives */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.panel-h {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-h h3 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .2px; }
.panel-h .spacer { flex: 1; }
.panel-b { padding: 16px; }

.grid { display: grid; gap: 14px; }
.g-auto { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

/* KPI row: equal-size tiles in a fixed 3×2 arrangement so none is orphaned. */
.g-kpi {
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
}
@media (min-width: 1500px) { .g-kpi { grid-template-columns: repeat(6, 1fr); } }
/* A fixed count, for rows whose tile number is known and shouldn't reflow. */
.g-4 { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 1fr; }
@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .g-4 { grid-template-columns: 1fr; } }
@media (max-width: 820px)  { .g-kpi { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .g-kpi { grid-template-columns: 1fr; } }

.tile {
  position: relative; overflow: hidden; padding: 15px 16px 13px;
  display: flex; flex-direction: column; min-height: 132px;
}
.tile .foot { margin-top: auto; }
.tile .label { color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.1px; font-weight: 600; }
.tile .value { font-size: 30px; font-weight: 640; margin: 7px 0 2px;
  font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.tile .value small { font-size: 15px; color: var(--dim); font-weight: 500; }
.tile .foot { font-size: 12px; color: var(--muted); display: flex;
  align-items: center; gap: 8px; flex-wrap: wrap; min-height: 20px; }
.tile > * { position: relative; z-index: 1; }
/* The trend sits behind the tile as a full-width backdrop, so it can never
   collide with the chips in the footer. */
.tile .spark {
  position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 46px;
  opacity: .3; pointer-events: none; z-index: 0;
}
.tile::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.07), transparent);
}
.tile.ok    { border-left: 2px solid var(--ok); }
.tile.warn  { border-left: 2px solid var(--warn); }
.tile.crit  { border-left: 2px solid var(--crit); }
.tile.info  { border-left: 2px solid var(--info); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap;
  background: var(--panel-2); color: var(--muted);
}
.chip.ok   { background: var(--ok-dim);   color: var(--ok); }
.chip.warn { background: var(--warn-dim); color: var(--warn); }
.chip.crit { background: var(--crit-dim); color: var(--crit); }
.chip.info { background: var(--info-dim); color: var(--info); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  flex: none; box-shadow: 0 0 7px currentColor; }
.dot.pulse { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--accent); background: #1f2a3c; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #0a0f1c;
  font-weight: 600; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .nav button:focus-visible, thead th.sortable:focus-visible,
input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn:disabled { opacity: .5; cursor: default; }

/* Every field type, not an enumerated few — an unlisted type (email, search,
   textarea) otherwise falls back to the browser's white default. */
input:not([type=checkbox]):not([type=radio]):not([type=range]),
select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 11px; outline: none; min-width: 0; color: var(--text);
  font-family: inherit; font-size: inherit;
}
input::placeholder, textarea::placeholder { color: var(--dim); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select { appearance: none; padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 6px 12px; cursor: pointer;
  color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }

.toolbar {
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  position: sticky; top: 57px; z-index: 15;
}
/* Specificity must beat the global input rule's min-width:0, or the filter box
   collapses to a sliver once a toolbar gains a few more controls. */
.toolbar .grow,
.toolbar input.grow { flex: 1 1 220px; min-width: 200px; }

/* ----------------------------------------------------------------- tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 14px; color: var(--muted); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: .9px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
tbody td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.click:hover td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
tbody tr.click { cursor: pointer; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
.th-in { display: inline-flex; align-items: center; gap: 5px; }
.num .th-in { flex-direction: row-reverse; }
.sort-ind { display: inline-flex; align-items: center; opacity: .4; }
thead th.sorted .sort-ind { opacity: 1; }
.pager .btn.sm { padding: 4px 7px; }

.pager {
  display: flex; align-items: center; gap: 9px; padding: 11px 14px;
  border-top: 1px solid var(--line); flex-wrap: wrap; font-size: 12.5px;
}
.pager .spacer { flex: 1; }
.pager-size { display: inline-flex; align-items: center; gap: 6px; }
.pager-size select { padding: 3px 7px; }

.mono { font-family: var(--mono); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Row-selection column: narrow, and the checkbox itself must stay clickable
   without triggering the row's click-to-open. */
.sel { width: 1%; padding-right: 0 !important; }
.sel input[type="checkbox"] { cursor: pointer; margin: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.nowrap { white-space: nowrap; }
.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }

/* meter bar */
.meter { height: 5px; background: var(--panel-2); border-radius: 3px;
  overflow: hidden; min-width: 56px; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.meter i.warn { background: var(--warn); }
.meter i.crit { background: var(--crit); }

/* ----------------------------------------------------------------- alerts */
/* Group banner inside a shared table: keeps one column grid across all groups. */
tbody tr.group-row td {
  background: var(--panel-2); padding: 9px 14px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 12px; letter-spacing: .3px;
}
tbody tr.group-row:hover td { background: var(--panel-2); }

.alert-row { display: flex; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft); align-items: flex-start; }
.alert-row:last-child { border-bottom: 0; }
.alert-bar { width: 3px; border-radius: 2px; align-self: stretch; flex: none; }
.alert-bar.critical { background: var(--crit); }
.alert-bar.major { background: var(--warn); }
.alert-bar.minor { background: var(--info); }
.alert-bar.info { background: var(--dim); }
.alert-row .t { font-weight: 570; }
.alert-row .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.alert-row .meta { color: var(--dim); font-size: 11.5px; margin-top: 4px; }
.alert-row .acts { margin-left: auto; display: flex; gap: 6px; flex: none; }

/* ------------------------------------------------------------- data flow */
.flow { display: flex; align-items: center; gap: 0; flex-wrap: nowrap; }
.flow .node {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; min-width: 108px;
}
.flow .node .n { font-weight: 600; }
.flow .node .s { color: var(--muted); font-size: 11px; }
.flow .link { flex: 1; height: 2px; background: var(--line); position: relative;
  min-width: 26px; }
.flow .link.ok { background: linear-gradient(90deg, var(--ok), rgba(46,230,168,.25)); }
.flow .link.bad { background: repeating-linear-gradient(90deg,
  var(--crit) 0 5px, transparent 5px 10px); }
.flow .link::after {
  content: ''; position: absolute; right: -1px; top: -3px;
  border-left: 6px solid var(--line); border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}
.flow .link.ok::after { border-left-color: var(--ok); }
.flow .link.bad::after { border-left-color: var(--crit); }

/* ------------------------------------------------------------------ misc */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line);
  margin-bottom: 16px; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 9px 15px; color: var(--muted); cursor: pointer; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 8px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent);
  font-weight: 600; }

.empty { padding: 44px 20px; text-align: center; color: var(--dim); }
.empty .big { margin-bottom: 10px; opacity: .45; display: flex;
  justify-content: center; color: var(--muted); }
.skel { background: linear-gradient(90deg, var(--panel-2) 25%, #202a3b 50%,
  var(--panel-2) 75%); background-size: 200% 100%;
  animation: sh 1.3s infinite; border-radius: 5px; height: 12px; }
@keyframes sh { to { background-position: -200% 0 } }

.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 94vw);
  background: var(--bg-alt); border-left: 1px solid var(--line); z-index: 60;
  overflow-y: auto; transform: translateX(100%); transition: transform .22s ease;
  box-shadow: -18px 0 40px rgba(0,0,0,.45);
}
.drawer.open { transform: translateX(0); }
.drawer-h { position: sticky; top: 0; background: var(--bg-alt); padding: 16px 20px;
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.drawer-b { padding: 18px 20px 40px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.on { opacity: 1; pointer-events: auto; }

.kv { display: grid; grid-template-columns: 132px 1fr; gap: 9px 14px; font-size: 13px;
  align-items: baseline; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px;
  border-radius: 8px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s, bottom .2s; pointer-events: none;
}
.toast.on { opacity: 1; bottom: 30px; }

/* ------------------------------------------------------------------ login */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px;
  background: radial-gradient(1100px 620px at 50% -10%, #16203180, transparent),
              var(--bg); }
.login {
  width: 100%; max-width: 366px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 30px;
}
.login h1 { margin: 0 0 4px; font-size: 19px; }
.login p { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login input { width: 100%; margin-bottom: 12px; padding: 10px 13px; }
.login button { width: 100%; justify-content: center; padding: 10px; }
.login .err { color: var(--crit); font-size: 12.5px; min-height: 18px; margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row;
    align-items: center; overflow-x: auto; }
  .brand, .side-foot { display: none; }
  .nav { display: flex; gap: 4px; padding: 8px; }
  .nav button { white-space: nowrap; }
  .nav-sep { display: none; }
  .toolbar { position: static; }
  .topbar { flex-wrap: wrap; }
  .topbar input#globalSearch { width: 100% !important; order: 10; }
}
