/* ============================================================
 * NEOADM retro v1-grey design system
 * Production stylesheet — lifted from prototype, extended for
 * KPI tiles, donut charts, and back-compat for unmigrated pages.
 * ============================================================ */

:root {
  --bg:           #DDDDDD;
  --bg-window:    #EEEEEE;
  --bg-titlebar:  #000000;
  --text-titlebar:#FFFFFF;
  --text:         #000000;
  --text-muted:   #666666;
  --border:       #000000;
  --bevel-light:  #FFFFFF;
  --bevel-dark:   #808080;
  --accent:       #00B8FF;   /* кислотный циан */
  --selection-bg: #000000;
  --selection-fg: #FFFFFF;
  --ok:           #00C853;   /* кислотный лайм-зелёный */
  --warn:         #FF8A00;   /* кислотный оранж */
  --err:          #FF1744;   /* кислотный красный/маджента */
  --info:         #00B8FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.4;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0,0,0,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.025) 1px, transparent 1px);
  background-size: 3px 3px;
  z-index: 0;
}

a { color: var(--accent); text-decoration: underline; }
a:hover { background: var(--selection-bg); color: var(--selection-fg); text-decoration: none; }
::selection { background: var(--selection-bg); color: var(--selection-fg); }

h1, h2, h3, h4 { margin: 0 0 8px 0; font-weight: 700; font-family: inherit; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
h4 { font-size: 13px; }
p { margin: 0 0 6px 0; }

/* -------- Menu bar -------- */
.menubar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center;
  background: var(--bg-window);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--bevel-dark);
  padding: 0 6px;
  height: 24px;
  font-size: 13px;
}
.menubar .item {
  padding: 2px 10px; cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
}
.menubar .item.brand { font-weight: 700; }
.menubar .item:hover, .menubar .item.active {
  background: var(--selection-bg); color: var(--selection-fg);
}
.menubar .spacer { flex: 1; }
.menubar .user { color: var(--text-muted); padding-right: 4px; }

/* -------- Window -------- */
.window {
  background: var(--bg-window);
  border: 1px solid var(--border);
  box-shadow:
    inset 1px 1px 0 var(--bevel-light),
    inset -1px -1px 0 var(--bevel-dark),
    2px 2px 0 var(--border);
  margin-bottom: 14px;
}
.window .titlebar {
  display: flex; align-items: center;
  background: var(--bg-titlebar);
  color: var(--text-titlebar);
  height: 18px;
  padding: 0 2px;
  font-size: 12px;
  user-select: none;
}
.titlebar .stripes {
  flex: 1; height: 100%;
  background-image: repeating-linear-gradient(180deg,#fff 0,#fff 1px,#000 1px,#000 2px);
  margin: 2px 4px;
  opacity: .85;
}
.titlebar .title {
  padding: 0 6px; background: #000;
  letter-spacing: 1px;
  white-space: nowrap;
  color: var(--text-titlebar);
}
.titlebar .close, .titlebar .ctrl {
  display: inline-block; width: 14px; height: 14px;
  border: 1px solid #fff; background: #000; color: #fff;
  text-align: center; line-height: 12px; font-size: 11px;
  margin: 0 2px; cursor: pointer;
}
.titlebar .close:hover { background: #fff; color: #000; }
.window .body { padding: 10px 12px; }
.window .body.flush { padding: 0; }

/* -------- Buttons -------- */
.btn {
  display: inline-block;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
  padding: 2px 12px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: #cdcdcd; }
.btn:active, .btn.pressed {
  box-shadow: inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light);
  background: #cdcdcd;
}
.btn.primary { font-weight: 700; outline: 2px solid var(--border); outline-offset: 1px; }
.btn.ascii {
  background: transparent; border: none; box-shadow: none;
  padding: 0; text-decoration: underline; color: var(--accent);
}
.btn.ascii:hover { background: var(--selection-bg); color: var(--selection-fg); text-decoration: none; }
.btn:disabled, .btn[disabled] { color: var(--text-muted); cursor: not-allowed; background: var(--bg); }
.btn-sm { padding: 1px 8px; font-size: 12px; }

/* Back-compat aliases for old templates */
.btn-primary { font-weight: 700; outline: 2px solid var(--border); outline-offset: 1px; }
.btn-secondary {}
.btn-danger {
  color: var(--err);
  border-color: var(--err);
  box-shadow: inset 1px 1px 0 #ffb3c2, inset -1px -1px 0 #660018;
  font-weight: 700;
}
.btn-danger:hover {
  background: var(--err);
  color: #fff;
}

/* -------- Inputs -------- */
.field {
  display: inline-flex; align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light);
  padding: 1px 4px;
  font-family: inherit;
  font-size: 13px;
}
.field input, .field select, .field textarea {
  border: 0; outline: 0; background: transparent;
  font-family: inherit; font-size: inherit; color: var(--text);
  padding: 1px 0; min-width: 60px;
  width: 100%;
}
.field .blink { display: none; color: var(--text); font-weight: 700; }
.field:focus-within .blink { display: inline; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.field.full { display: flex; }

label.fld { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 13px; }
label.fld .lbl { min-width: 100px; color: var(--text); }
label.fld .field { flex: 1; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="datetime-local"], select, textarea {
  font-family: inherit; font-size: 13px;
  background: #fff; color: var(--text);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light);
  padding: 2px 4px;
  outline: 0;
}

/* -------- Tables -------- */
table.mono, table.table {
  width: 100%; border-collapse: collapse;
  font-family: inherit; font-size: 13px;
}
table.mono th, table.mono td,
table.table th, table.table td {
  padding: 2px 6px; text-align: left;
  white-space: nowrap; border: 0;
}
table.mono thead th, table.table thead th {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  font-weight: 700; cursor: pointer; user-select: none;
}
table.mono thead th:hover, table.table thead th:hover { background: #cdcdcd; }
table.mono tbody tr, table.table tbody tr { border-bottom: 1px dotted var(--bevel-dark); }
table.mono tbody tr:hover, table.table tbody tr:hover {
  background: var(--selection-bg); color: var(--selection-fg);
}
table.mono tbody tr:hover a, table.table tbody tr:hover a { color: var(--selection-fg); }
table.mono tbody tr:hover .badge,
table.table tbody tr:hover .badge { filter: invert(1); }
table.mono .num, table.table .num { text-align: right; }

th[data-sort] { cursor: pointer; user-select: none; }
.sort-arrow { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
th.sort-asc .sort-arrow::after { content: '↑'; }
th.sort-desc .sort-arrow::after { content: '↓'; }

/* -------- Badges -------- */
.badge {
  display: inline-block;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 0 5px;
  border: 1px solid currentColor;
  white-space: nowrap;
  line-height: 1.3;
  background: transparent;
}
.badge.ok    { color: var(--ok); }
.badge.warn  { color: var(--warn); }
.badge.err   { color: var(--err); }
.badge.muted { color: var(--text-muted); }
.badge.accent{ color: var(--accent); }

/* Back-compat */
.badge-ok       { color: var(--ok); border: 1px solid currentColor; padding: 0 4px; }
.badge-warning  { color: var(--warn); border: 1px solid currentColor; padding: 0 4px; }
.badge-critical { color: var(--err); border: 1px solid currentColor; padding: 0 4px; }
.badge-unknown  { color: var(--text-muted); border: 1px solid currentColor; padding: 0 4px; }
.badge-accent   { color: var(--accent); border: 1px solid currentColor; padding: 0 4px; }

/* -------- Text helpers -------- */
.dim, .text-muted, .text-secondary { color: var(--text-muted); }
.right { text-align: right; }
.center { text-align: center; }
.bold, .font-medium { font-weight: 700; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-2xl { font-size: 20px; }
.text-3xl { font-size: 26px; }
.text-ok       { color: var(--ok); }
.text-warning  { color: var(--warn); }
.text-critical { color: var(--err); }
.text-accent   { color: var(--accent); }

/* -------- KPI tile (dashboard) -------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--bg-window);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
  padding: 10px 12px;
}
.kpi .kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.kpi .kpi-value {
  font-family: 'VT323', monospace;
  font-size: 36px;
  line-height: 1;
  letter-spacing: 1px;
  margin-top: 6px;
}
.kpi.ok .kpi-value    { color: var(--ok); }
.kpi.warn .kpi-value  { color: var(--warn); }
.kpi.err .kpi-value   { color: var(--err); }
.kpi.muted .kpi-value { color: var(--text-muted); }
.kpi .kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.kpi-link {
  display: block;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: transform .05s ease-out;
}
.kpi-link:hover {
  background: var(--bg);
  box-shadow:
    inset 1px 1px 0 var(--bevel-light),
    inset -1px -1px 0 var(--bevel-dark),
    2px 2px 0 var(--border);
  color: var(--text);
  text-decoration: none;
}
.kpi-link:active { transform: translate(1px, 1px); }

.legend-link:hover {
  background: var(--selection-bg);
  color: var(--selection-fg) !important;
}
.legend-link:hover b { color: var(--selection-fg); }

/* -------- Marquee status badge --------
 * Бесшовная бесконечная прокрутка: внутри `.track` две одинаковые `.copy`,
 * анимируем translateX от 0 до -50%. В момент, когда первая копия уезжает
 * влево, вторая уже встала на её место — обрыв не виден.
 */
.badge-marquee {
  display: inline-block;
  overflow: hidden;
  width: 80px;
  height: 16px;
  vertical-align: middle;
  border: 1px solid currentColor;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  background: transparent;
  position: relative;
}
.badge-marquee .track {
  display: inline-flex;
  white-space: nowrap;
  will-change: transform;
  animation: marquee 10s linear infinite;
}
.badge-marquee .copy {
  display: inline-block;
  white-space: nowrap;
  padding-right: 18px;          /* gap между «склейками» */
  flex-shrink: 0;
}
.badge-marquee.ok    { color: var(--ok);    }
.badge-marquee.warn  { color: var(--warn);  }
.badge-marquee.err   { color: var(--err);   }
.badge-marquee.muted { color: var(--text-muted); }

@keyframes marquee {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .badge-marquee .track { animation: none !important; }
}

/* -------- Stat card (back-compat) -------- */
.stat-card { background: var(--bg-window); border: 1px solid var(--border); padding: 8px; }
.stat-value { font-family: 'VT323', monospace; font-size: 32px; line-height: 1; }
.stat-value.ok       { color: var(--ok); }
.stat-value.warning  { color: var(--warn); }
.stat-value.critical { color: var(--err); }
.stat-value.accent   { color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* -------- Card (back-compat alias for .window) -------- */
.card {
  background: var(--bg-window);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
  margin-bottom: 14px;
}
.card-header {
  padding: 4px 10px;
  background: var(--bg-titlebar);
  color: var(--text-titlebar);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: 10px 12px; }

/* -------- Alert (back-compat) -------- */
.alert { padding: 6px 10px; border: 1px solid var(--border); margin-bottom: 6px; }
.alert-info     { background: #f0f0ff; color: var(--info); }
.alert-warning  { background: #fff4e0; color: var(--warn); }
.alert-critical { background: #ffe0e0; color: var(--err); }

/* -------- Tabs -------- */
.tabs {
  display: flex; border-bottom: 1px solid var(--border);
  margin: 0 0 10px 0; font-size: 13px;
}
.tabs .tab {
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  margin-right: -1px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer; user-select: none;
  text-decoration: none;
}
.tabs .tab:hover { background: #cdcdcd; }
.tabs .tab.active {
  background: var(--bg-window);
  border-bottom: 1px solid var(--bg-window);
  font-weight: 700;
  position: relative; top: 1px;
}

/* -------- ASCII / bar -------- */
.ascii { font-family: inherit; white-space: pre; line-height: 1.1; font-size: 12px; }
.ascii-big {
  font-family: 'VT323', monospace;
  font-size: 36px; line-height: 1; letter-spacing: 1px;
}
.bar { font-family: inherit; font-size: 13px; letter-spacing: -1px; white-space: nowrap; }

/* -------- Layout -------- */
.page {
  max-width: 1400px; margin: 0 auto;
  padding: 12px;
  position: relative; z-index: 1;
  padding-bottom: 40px; /* room for statusbar */
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }

/* -------- Modal -------- */
.overlay, .modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 100; padding-top: 60px;
}
.overlay.open, .modal-overlay:not(.hidden) { display: flex; }
.overlay .window, .modal-overlay .modal,
.overlay .window { width: 640px; max-width: 95%; margin: 0; }
.modal {
  background: var(--bg-window);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark), 2px 2px 0 var(--border);
  padding: 12px;
  width: 640px; max-width: 95%;
}

/* -------- Login -------- */
.login-screen {
  min-height: calc(100vh - 24px);
  display: flex; align-items: center; justify-content: center;
}
.login-screen .window { width: 380px; }
.login-screen .build {
  text-align: center; color: var(--text-muted);
  font-size: 11px; margin-top: 6px;
}

/* -------- Status bar -------- */
.statusbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-window);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 0 var(--bevel-light) inset;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 12px;
  display: flex; gap: 14px; flex-wrap: wrap;
  z-index: 40;
}
.statusbar .sep { color: var(--bevel-dark); }
.statusbar .blink-cursor {
  margin-left: auto; color: var(--text);
  font-weight: 700; animation: blink 1s steps(1) infinite;
}

/* -------- Toast -------- */
.toast-wrap {
  position: fixed; bottom: 30px; right: 14px; z-index: 200;
  display: flex; flex-direction: column; gap: 6px;
}
.toast {
  background: var(--bg-window);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark), 2px 2px 0 var(--border);
  padding: 6px 10px;
  font-family: inherit; font-size: 12px;
  animation: pop .12s ease-out;
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* -------- Pagination -------- */
.pagination {
  display: flex; gap: 4px; align-items: center;
  border-top: 1px solid var(--bevel-dark);
  padding: 6px 8px; margin-top: 8px;
  font-size: 13px;
}
.pagination .gap { flex: 1; }

/* -------- Scrollbars -------- */
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track {
  background: repeating-linear-gradient(45deg, #cccccc 0 2px, #dddddd 2px 4px);
  border: 1px solid var(--border);
}
::-webkit-scrollbar-thumb {
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
}

/* -------- Donut (SVG-based) -------- */
.donut {
  display: inline-block;
  width: 160px; height: 160px;
}
.donut svg { width: 100%; height: 100%; }
.donut-legend {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; padding: 6px;
}
.donut-legend .row {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: nowrap; white-space: nowrap;
}
.donut-legend .sw {
  display: inline-block; width: 10px; height: 10px;
  border: 1px solid var(--border);
}

/* -------- Utility overrides for old templates -------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.space-y-2 > * + * { margin-top: 8px; } .space-y-4 > * + * { margin-top: 16px; } .space-y-6 > * + * { margin-top: 24px; }
.w-full { width: 100%; }
.overflow-x-auto { overflow-x: auto; }
.text-center { text-align: center; }
.font-mono { font-family: 'IBM Plex Mono', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opacity-75 { opacity: .75; }
.opacity-90 { opacity: .9; }
.relative { position: relative; }
.min-w-0 { min-width: 0; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.ml-1 { margin-left: 4px; } .ml-2 { margin-left: 8px; }
.mr-1 { margin-right: 4px; } .mr-2 { margin-right: 8px; }

/* Hide elements that no longer make sense */
.theme-toggle, .sun-icon, .moon-icon, .navbar-logo { display: none !important; }
