/* altcoin admin — self-contained dark dashboard theme (no framework defaults) */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #050807;
  --bg-panel: #0a0f0c;
  --bg-elevated: #0e1511;
  --bg-hover: #12201a;
  --border: #1a2b22;
  --border-light: #244033;
  --text: #d8f0e0;
  --text-muted: #7a9a88;
  --brand: #2f8f5b;
  --brand-dim: rgba(47, 143, 91, 0.16);
  --brand-glow: rgba(47, 143, 91, 0.26);
  --ok: #2f8f5b;
  --ok-dim: rgba(47, 143, 91, 0.18);
  --bad: #ff4060;
  --bad-dim: rgba(255, 64, 96, 0.12);
  --warn: #c8ff00;
  --warn-dim: rgba(200, 255, 0, 0.10);
  --info: #37e2d5;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

/* Matrix-style subtle scanline texture over the whole app */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(47, 143, 91, 0.012) 2px,
    rgba(47, 143, 91, 0.012) 4px
  );
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--info); text-decoration: none; }
p { margin: 0.4rem 0; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: 0.82rem; }
.note { font-size: 0.82rem; color: var(--text-muted); }

/* ---------- buttons & inputs ---------- */

button, .btn {
  font-family: var(--font);
  font-size: 0.94rem;
  padding: 0.5rem 1.1rem;
  border-radius: 7px;
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: var(--bg-hover); border-color: var(--border-light); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

button.primary { background: var(--brand); border-color: var(--brand); color: #f1fff7; font-weight: 700; }
button.primary:hover { background: #3ca068; border-color: #3ca068; box-shadow: 0 0 12px var(--brand-glow); }
button.secondary { background: transparent; border-color: var(--border-light); }
button.secondary:hover { background: var(--bg-hover); }
button.contrast { background: var(--bad-dim); border-color: var(--bad); color: var(--bad); }
button.contrast:hover { background: rgba(255, 64, 96, 0.25); }
button.outline { background: transparent; }
button.small { font-size: 0.78rem; padding: 0.2rem 0.6rem; }

input, select, textarea {
  font-family: var(--font);
  font-size: 0.94rem;
  padding: 0.5rem 0.75rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(47, 143, 91, 0.2);
}
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--brand); }

label { display: block; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.65rem; }
label > input, label > select { display: block; width: 100%; margin-top: 0.3rem; color: var(--text); }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(700px 340px at 20% 10%, rgba(47, 143, 91, 0.14), transparent 60%),
    radial-gradient(600px 300px at 85% 85%, rgba(55, 226, 213, 0.06), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 2.4rem 2.4rem 2rem;
  box-shadow: var(--shadow), 0 0 30px rgba(47, 143, 91, 0.10);
}

.login-card h2 {
  color: var(--brand);
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  text-shadow: 0 0 14px var(--brand-glow);
}
.login-card .muted { margin-bottom: 1.4rem; }
.login-card button[type="submit"] { width: 100%; margin-top: 0.5rem; }

.error-text { color: var(--bad); font-size: 0.85rem; min-height: 1.2em; }

/* ---------- app shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.side-nav {
  width: 252px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #070a09;
  border-right: 1px solid var(--border);
  padding: 1.1rem 0.8rem 0.8rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.side-nav .brand {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--brand);
  text-shadow: 0 0 12px var(--brand-glow);
  padding: 0.15rem 0.7rem 1rem;
  letter-spacing: 0.5px;
}
.side-nav .brand span {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-shadow: none;
}

.side-nav .nav-item,
.side-nav .nav-group-title {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.75rem;
  margin-bottom: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 7px;
  font-size: 1.06rem;
  font-weight: 500;
}
.side-nav .nav-item:hover,
.side-nav .nav-group-title:hover { background: var(--bg-hover); color: var(--text); }

.side-nav .nav-item.active {
  background: var(--brand-dim);
  color: var(--brand);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--brand);
}

.nav-group-title .chev {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.15s;
}
.nav-group.collapsed .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-sub { display: none; }

.nav-sub {
  margin: 0 0 2px 0.75rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border-light);
}
.nav-sub .nav-item { font-size: 0.92rem; padding: 0.48rem 0.65rem; }

.nav-group-title.group-active { color: var(--brand); }

.side-nav .badge {
  margin-left: auto;
  background: var(--bad);
  color: #fff;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.08rem 0.5rem;
  line-height: 1.35;
}

.side-nav .nav-footer {
  margin-top: auto;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}
.side-nav .nav-footer button {
  width: 100%;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.side-nav .nav-footer button:hover { color: var(--bad); background: var(--bad-dim); }

.main-area {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem 3.5rem;
  max-width: 1680px;
}

.top-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.3rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.top-bar h2 { font-size: 1.72rem; text-shadow: 0 0 18px rgba(47, 143, 91, 0.16); }
.top-bar .muted { font-size: 0.88rem; }

/* ---------- cards & stats ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 0.95rem;
  margin-bottom: 1.3rem;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: var(--shadow), 0 0 16px rgba(47, 143, 91, 0.10);
}

.stat-card .stat-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stat-card.clickable .stat-label::after {
  content: "→";
  color: var(--text-muted);
  font-size: 0.9rem;
}
.stat-card.clickable:hover .stat-label::after { color: var(--brand); }

.stat-card .stat-value { font-size: 1.42rem; font-weight: 700; letter-spacing: 0.2px; }

.stat-ok { color: var(--ok); }
.stat-bad { color: var(--bad); }
.stat-warn { color: var(--warn); }

/* ---------- panels (articles) ---------- */

article {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  margin: 0 0 1.1rem;
  overflow: hidden;
}

article > header {
  padding: 0.8rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: rgba(47, 143, 91, 0.08);
  font-size: 1rem;
}
article > header .toolbar { margin-bottom: 0; }
article > div:not(.toolbar), article > table, article > p {
  margin: 1rem 1.15rem;
}
article > p.muted { padding: 0.2rem 0; }
article > canvas { margin: 0.7rem 1.15rem 1.15rem; }

/* ---------- pills ---------- */

.pill {
  display: inline-block;
  padding: 0.24rem 0.82rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.pill-ok { background: var(--ok-dim); color: var(--ok); }
.pill-bad { background: var(--bad-dim); color: var(--bad); }
.pill-warn { background: var(--warn-dim); color: var(--warn); }
.pill-muted { background: var(--bg-hover); color: var(--text-muted); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; }
table.compact { font-size: 0.92rem; }
table.compact th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.compact td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(26, 43, 34, 0.6);
  white-space: nowrap;
}
table.compact tbody tr { transition: background 0.1s; }
table.compact tbody tr:hover { background: var(--bg-hover); }
table.compact tbody tr:last-child td { border-bottom: none; }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ---------- halt banner ---------- */

.halt-banner {
  background: var(--bad-dim);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  animation: pulse-border 2.4s ease-in-out infinite;
}
#halt-reason { white-space: pre-line; overflow-wrap: anywhere; }
.runtime-error { color: var(--bad); }
.runtime-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem 1.2rem; }
.runtime-grid > div { min-width: 0; }
.runtime-grid dt { font-size: 0.82rem; color: var(--text-muted); }
.runtime-grid dd { margin: 0.2rem 0 0; font-size: 0.9rem; overflow-wrap: anywhere; }
#services-table, #dash-services { overflow-x: auto; }
#positions-table, #trades-table, #events-table, #obs-by-chain, #obs-by-router, #obs-failures, #kpi-table, #quota-cards {
  overflow-x: auto;
}
#services-table .note { white-space: normal; min-width: 12rem; overflow-wrap: anywhere; }
@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(246, 70, 93, 0.25); }
  50% { box-shadow: 0 0 14px 0 rgba(246, 70, 93, 0.35); }
}

/* ---------- quota bars ---------- */

.quota-bar {
  height: 7px;
  border-radius: 4px;
  background: var(--bg-hover);
  overflow: hidden;
  min-width: 120px;
  margin-top: 0.45rem;
}
.quota-bar > div { height: 100%; background: var(--ok); border-radius: 4px; transition: width 0.35s; }
.quota-bar.warn > div { background: var(--warn); }
.quota-bar.exceeded > div { background: var(--bad); }

/* ---------- log viewer ---------- */

.log-view {
  background: #030604;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.55;
  max-height: 66vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: #a9d8b8;
}

/* ---------- param forms ---------- */

fieldset.param-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem 0.4rem;
  margin: 0 0 0.8rem;
}
fieldset.param-group legend {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--brand);
  padding: 0 0.45rem;
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.2rem 1.2rem;
}
.param-grid label { margin-bottom: 0.5rem; font-size: 0.86rem; }
.param-grid input[type="number"] { font-size: 0.92rem; padding: 0.38rem 0.6rem; }
.param-grid label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.92rem;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.toolbar select, .toolbar input { width: auto; margin-bottom: 0; }
.toolbar strong { font-size: 1rem; }

.control-btn {
  min-width: 74px;
  padding: 0.56rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #f1fff7;
}

.control-start {
  background: #2f8f5b;
  border: 1px solid #2f8f5b;
}

.control-start:hover {
  background: #3ca068;
  border-color: #3ca068;
}

.control-stop {
  background: #b43a4e;
  border: 1px solid #b43a4e;
}

.control-stop:hover {
  background: #c7485d;
  border-color: #c7485d;
}

.control-restart {
  background: #8b6a2b;
  border: 1px solid #8b6a2b;
}

.control-restart:hover {
  background: #a37f32;
  border-color: #a37f32;
}

.obs-controls {
  align-items: flex-end;
  gap: 0.65rem;
}

.obs-controls .obs-field {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: auto;
}

.obs-controls .obs-field input,
.obs-controls .obs-field select {
  width: auto;
  min-width: 88px;
}

/* ---------- tabs ---------- */

section.tab-page { display: none; animation: fade-in 0.18s ease; }
section.tab-page.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- alerts ---------- */

.alert-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 0.6rem 0.95rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.12s;
}
.alert-item:hover { background: var(--bg-elevated); }
.alert-item.sev-CRITICAL { border-left-color: var(--bad); }
.alert-item.sev-WARN { border-left-color: var(--warn); }
.alert-item.sev-INFO { border-left-color: var(--ok); }
.alert-item .alert-title { font-weight: 600; font-size: 0.96rem; }
.alert-item .alert-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.alert-item .alert-body {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  display: none;
}
.alert-item.open .alert-body { display: block; }
.alert-item.is-read {
  opacity: 0.72;
}
.alert-item.is-unread {
  box-shadow: inset 0 0 0 1px rgba(200, 255, 0, 0.18);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0 1.15rem 1rem;
}

/* ---------- misc ---------- */

details { margin: 0.4rem 0; }
details summary { cursor: pointer; color: var(--text-muted); font-size: 0.9rem; }
details summary:hover { color: var(--text); }
details[open] summary { color: var(--text); margin-bottom: 0.35rem; }
pre { font-family: var(--mono); font-size: 0.85rem; white-space: pre-wrap; }

canvas { max-width: 100%; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .runtime-grid { grid-template-columns: minmax(0, 1fr); }
  .halt-banner { flex-wrap: wrap; }
  .app-shell { flex-direction: column; }
  .side-nav {
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 0.6rem 0.6rem;
  }
  .side-nav .brand { padding: 0.1rem 0.45rem 0.65rem; }
  .side-nav .nav-item, .side-nav .nav-group-title { font-size: 0.9rem; padding: 0.55rem 0.65rem; }
  .side-nav .nav-sub { margin-left: 0.45rem; padding-left: 0.45rem; }
  .main-area { padding: 1rem 0.8rem 3rem; }
  .pager { justify-content: flex-start; }
}
