/* ============================================================
   Bilgipark NMS — control-room theme
   Palette: deep ink navy surfaces, cyan telemetry accent,
   semantic status colours. Mono face carries live data.
   ============================================================ */

/* The `hidden` attribute must always win over component display rules.
   .modal-backdrop uses display:flex, which otherwise keeps the overlay
   visible (and blocking clicks) even when JS sets it hidden. */
[hidden] { display: none !important; }

:root {
  --ink:        #0e1420;
  --surface:    #161f2e;
  --surface-2:  #1e2939;
  --border:     #2a3648;
  --border-soft:#232f41;
  --text:       #e6edf5;
  --muted:      #8896a8;
  --muted-2:    #5f6d80;

  --accent:     #38bdf8;
  --accent-dim: #1b6d8f;

  --up:      #34d399;
  --warning: #fbbf24;
  --down:    #f87171;
  --unknown: #64748b;
  --paused:  #94a3b8;
  --critical:#f43f5e;

  --sans: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 10px;
  --shadow: 0 12px 40px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(56,189,248,.06), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(52,211,153,.04), transparent 55%);
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
code { font-family: var(--mono); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #06222e; border-color: var(--accent); }
.btn-primary:hover { background: #5accfa; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--down); border-color: #4a2530; background: #24161b; }
.btn-danger:hover { border-color: var(--down); }
.btn-block { width: 100%; margin-top: 8px; }
.btn-xs { padding: 4px 9px; font-size: 12px; }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; position: relative; overflow: hidden;
}
.login-shell { width: 100%; max-width: 380px; padding: 24px; }
.login-signal {
  display: flex; gap: 6px; justify-content: center; align-items: flex-end;
  height: 34px; margin-bottom: 22px;
}
.login-signal span {
  width: 6px; background: var(--accent); border-radius: 3px;
  animation: sig 1.4s ease-in-out infinite;
}
.login-signal span:nth-child(1){ height: 40%; animation-delay: 0s; }
.login-signal span:nth-child(2){ height: 70%; animation-delay: .15s; }
.login-signal span:nth-child(3){ height: 100%; animation-delay: .3s; }
.login-signal span:nth-child(4){ height: 65%; animation-delay: .45s; }
.login-signal span:nth-child(5){ height: 35%; animation-delay: .6s; }
@keyframes sig { 0%,100%{ opacity:.3; transform: scaleY(.6);} 50%{ opacity:1; transform: scaleY(1);} }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-sub { color: var(--muted); margin: 4px 0 24px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; }
.login-card label { font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
.login-card input {
  background: var(--ink); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-family: var(--mono); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-hint { text-align: center; color: var(--muted-2); font-size: 12px; margin-top: 18px; }
.form-error { color: var(--down); font-size: 13px; margin: 10px 0 0; min-height: 18px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand-name { font-weight: 700; letter-spacing: .3px; font-size: 17px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 22px;
  background: rgba(16,22,34,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-status {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border: 1px solid var(--border-soft);
  border-radius: 999px; font-size: 12px;
}
.pulse-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--unknown);
  box-shadow: 0 0 0 0 rgba(52,211,153,.5);
}
.pulse-dot.ok { background: var(--up); animation: pulse 2s infinite; }
.pulse-dot.warn { background: var(--warning); }
.pulse-dot.bad { background: var(--down); animation: pulse-bad 1.2s infinite; }
@keyframes pulse { 0%{ box-shadow: 0 0 0 0 rgba(52,211,153,.5);} 70%{ box-shadow: 0 0 0 8px rgba(52,211,153,0);} }
@keyframes pulse-bad { 0%{ box-shadow: 0 0 0 0 rgba(248,113,113,.6);} 70%{ box-shadow: 0 0 0 8px rgba(248,113,113,0);} }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.role-tag {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .5px; padding: 2px 7px; border-radius: 5px;
  background: var(--accent-dim); color: #cbeefb;
}

/* ---------- Stat strip ---------- */
.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px; background: var(--border-soft);
  border-bottom: 1px solid var(--border);
}
.stat {
  background: var(--surface); padding: 16px 20px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-family: var(--mono); font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat.up .stat-value { color: var(--up); }
.stat.warn .stat-value { color: var(--warning); }
.stat.down .stat-value { color: var(--down); }
.stat.alarm .stat-value { color: var(--critical); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 12px 22px 0; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; border: none; color: var(--muted);
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 8px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-badge {
  background: var(--critical); color: #fff; font-family: var(--mono);
  font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}

/* ---------- Content / panels ---------- */
.content { padding: 22px; max-width: none; margin: 0 auto; }
.panel { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none;} }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.panel-actions { display: flex; gap: 8px; align-items: center; }

.table-wrap {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--surface);
}
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; padding: 12px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.grid td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: rgba(56,189,248,.04); }
td.mono, .grid .mono { font-family: var(--mono); }

/* status pill */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; text-transform: capitalize;
}
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.pill.up::before { background: var(--up); box-shadow: 0 0 8px var(--up); }
.pill.warning::before { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.pill.down::before { background: var(--down); box-shadow: 0 0 8px var(--down); }
.pill.paused::before { background: var(--paused); }
.pill.unknown::before { background: var(--unknown); }

.sev { font-family: var(--mono); font-size: 11px; text-transform: uppercase; font-weight: 700; padding: 3px 8px; border-radius: 5px; }
.sev.info { background: #16323e; color: #7dd3fc; }
.sev.warning { background: #3a3115; color: var(--warning); }
.sev.critical { background: #3a1620; color: var(--critical); }
.state-tag { font-size: 12px; color: var(--muted); text-transform: capitalize; }

.type-tag {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  background: var(--surface-2); padding: 2px 8px; border-radius: 5px;
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Logs ---------- */
.log-stream {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-family: var(--mono); font-size: 12.5px;
  max-height: 70vh; overflow-y: auto;
}
.log-line { display: flex; gap: 12px; padding: 7px 16px; border-bottom: 1px solid var(--border-soft); }
.log-line:hover { background: rgba(255,255,255,.02); }
.log-ts { color: var(--muted-2); white-space: nowrap; }
.log-cat { color: var(--accent); min-width: 68px; }
.log-line.error .log-msg { color: var(--down); }
.log-line.warning .log-msg { color: var(--warning); }
.log-line.audit .log-cat { color: #a78bfa; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,10,18,.7);
  display: flex; align-items: center; justify-content: center; z-index: 40;
  backdrop-filter: blur(2px);
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 480px;
  padding: 24px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 18px; font-size: 16px; }
.field { display: flex; flex-direction: column; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .input-sm {
  background: var(--ink); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 7px; font-family: var(--mono); font-size: 13px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-sm { padding: 7px 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-err { color: var(--down); font-size: 13px; min-height: 18px; margin-top: 6px; }
.hint { font-size: 11px; color: var(--muted-2); margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 40px; font-style: italic; }
.thresholds-mini { margin-top: 4px; }
.thresholds-mini .chip {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  background: var(--surface-2); padding: 2px 7px; border-radius: 5px; margin: 2px 4px 2px 0;
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-right { width: 100%; }
  table.grid { font-size: 12px; }
  .field-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}

/* ============================================================
   MIB library + SNMP configuration
   ============================================================ */
.mib-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 18px;
  align-items: start;
}
.mib-list { margin: 0; }
.mib-detail {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 120px;
}
.mib-detail-head { margin-bottom: 12px; }
.mib-detail-head .input-sm { width: 100%; }
.mib-detail .hint { white-space: normal; max-width: 420px; }

.snmp-block {
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px 14px 4px;
  margin: 4px 0 4px;
  background: rgba(56, 189, 248, .05);
}
.snmp-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin-bottom: 8px;
}

@media (max-width: 860px) {
  .mib-layout { grid-template-columns: 1fr; }
}

/* ============================================================
   Device detail — parameter cards & charts
   ============================================================ */
.asset-row { cursor: pointer; }
.asset-row:hover { background: rgba(56,189,248,.05); }
.param-count {
  display: inline-block; margin-left: 8px; padding: 1px 7px;
  font-size: 11px; border-radius: 10px; background: var(--surface-2);
  color: var(--accent); border: 1px solid var(--border);
}
.device-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.device-head h2 { margin: 0; }
.device-meta { margin: -4px 0 16px; font-size: 12px; }

.param-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.param-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 14px; border-top: 3px solid var(--unknown);
}
.param-card.status-up      { border-top-color: var(--up); }
.param-card.status-warning { border-top-color: var(--warning); }
.param-card.status-down    { border-top-color: var(--down); }
.param-card.status-unknown { border-top-color: var(--unknown); }
.param-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.param-name { font-weight: 600; font-size: 14px; }
.param-oid { font-size: 11px; color: var(--muted-2); word-break: break-all; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; margin-top: 3px; background: var(--unknown); }
.dot.up { background: var(--up); } .dot.warning { background: var(--warning); }
.dot.down { background: var(--down); } .dot.unknown { background: var(--unknown); }

.param-chart { min-height: 74px; display: flex; flex-direction: column; justify-content: center; align-items: center; margin: 10px 0 4px; }
.param-value { text-align: center; font-family: var(--mono); font-size: 15px; color: var(--text); }
.param-rules { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; justify-content: center; }
.param-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; }

.chart-text { font-family: var(--mono); font-size: 30px; font-weight: 600; color: var(--accent); }
.chart-unit { font-size: 14px; color: var(--muted); margin-left: 4px; }
.chart-bar { width: 100%; height: 16px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.chart-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); border-radius: 8px; }
.chart-scale { display: flex; justify-content: space-between; width: 100%; font-size: 10px; color: var(--muted-2); margin-top: 3px; }

.gauge { width: 130px; height: 74px; }
.gauge-bg { fill: none; stroke: var(--surface-2); stroke-width: 10; stroke-linecap: round; }
.gauge-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; }

.pie { width: 92px; height: 92px; }
.pie-ring { fill: none; stroke-width: 12; stroke: var(--unknown); }
.pie-ring.pie-up { stroke: var(--up); } .pie-ring.pie-warning { stroke: var(--warning); }
.pie-ring.pie-down { stroke: var(--down); } .pie-ring.pie-unknown { stroke: var(--unknown); }
.pie-hole { fill: var(--surface); }

.spark { width: 100%; height: 60px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-line { width: 100%; }

.param-thresholds { border-top: 1px solid var(--border-soft); margin-top: 8px; padding-top: 10px; }
.param-rules .chip a { color: var(--down); cursor: pointer; margin-left: 4px; text-decoration: none; }

/* Text/info parameters — plain line-by-line, no card box */
.param-info-block { margin-top: 18px; }
.param-info-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: 8px;
}
.param-info {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); overflow: hidden;
}
.info-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-bottom: 1px solid var(--border-soft);
}
.info-row:last-child { border-bottom: none; }
.info-name { flex: 0 0 40%; color: var(--muted); font-size: 13px; }
.info-val { flex: 1; color: var(--text); word-break: break-all; }
.info-actions { display: flex; gap: 10px; }
.info-actions a { color: var(--accent); cursor: pointer; font-size: 12px; }
.info-actions a[data-pdel] { color: var(--down); }

/* Formula/computed builders + multi-slice pie legend */
.builder-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.builder-row input, .builder-row select { flex: 1; min-width: 0; }
.builder-row .row-x { color: var(--down); cursor: pointer; flex: 0 0 auto; padding: 0 4px; text-decoration: none; }
#src-computed > label, .param-thresholds > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.pie-legend { margin-top: 8px; width: 100%; }
.legend-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }

/* Drag-to-reorder */
.draggable { cursor: grab; }
.param-card.draggable:active { cursor: grabbing; }
.dragging { opacity: .45; outline: 2px dashed var(--accent); }
.info-row.draggable { cursor: grab; }
.reorder-hint { font-size: 11px; color: var(--muted-2); margin: -6px 0 12px; }

/* Resizable cards: allow row spans and let content fill the card */
.param-grid { grid-auto-rows: minmax(150px, auto); align-items: stretch; }
.param-card { display: flex; flex-direction: column; }
.param-card .param-chart { flex: 1 1 auto; }

/* ============================================================
   Admin settings page
   ============================================================ */
.subtabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  border-bottom: 1px solid var(--border); margin-bottom: 18px;
}
.subtab {
  background: none; border: none; color: var(--muted);
  padding: 8px 14px; font: inherit; font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.adm-panel .panel-head { margin-bottom: 12px; }
.adm-panel h3 { margin: 0 0 6px; font-size: 15px; }

.settings-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 18px; max-width: 620px;
}
.settings-card .field { margin-bottom: 12px; }
.settings-card .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.settings-card input, .settings-card select {
  width: 100%; padding: 8px 10px; background: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font: inherit;
}
.switch-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; font-size: 14px; cursor: pointer; }
.switch-row input { width: auto; }
.settings-msg { color: var(--up); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Keep the assets table within the viewport under fixed layout: let action
   buttons wrap and clip/wrap cell content so columns never overflow into a
   horizontal scrollbar at normal window sizes. */
table.grid td, table.grid th { overflow: hidden; }
table.grid td.mono { word-break: break-word; }
.row-actions { flex-wrap: nowrap; white-space: nowrap; }
td .row-actions { justify-content: flex-start; }

/* Agent CPU/RAM history charts (fixed height, gridlines, axis labels) */
.chart-hist { height: 160px; padding: 0; overflow: hidden; }
.chart-hist .hist { width: 100%; height: 160px; display: block; }
.hist .grid-line { stroke: var(--border-soft); stroke-width: 1; }
.hist .axis-lbl { fill: var(--muted-2); font-size: 11px; font-family: var(--mono); }
.hist .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
