/* =========================================================================
   TrenoControl Admin SPA — E1 layout + Phase 2 risk view styles
   ========================================================================= */

:root {
  --bg-0:        #08090c;
  --bg-1:        #0d1117;
  --bg-2:        #11151c;
  --bg-3:        #161b24;
  --bg-hover:    #1c2230;
  --bg-active:   #1f2a3d;

  --line:        #1a1f29;
  --line-soft:   #14191f;
  --line-strong: #242a36;

  --fg:          #d6dae3;
  --fg-dim:      #8b94a6;
  --fg-dimmer:   #5b6371;
  --fg-faint:    #3d434f;
  --fg-bright:   #f0f3f8;

  --accent:      #2ea3ff;
  --accent-soft: #1a4e7a;
  --accent-faint:rgba(46,163,255,0.08);

  --green:       #26a69a;
  --green-soft:  #1d4f4a;
  --red:         #ef5350;
  --red-soft:    #5a2828;
  --gold:        #ffd54f;
  --gold-soft:   #5a4a1d;
  --warn:        #ff9800;

  --h-header:     46px;
  --h-bottom:    220px;
  --h-status:     22px;
  --w-left:      280px;
  --w-right:     260px;

  --f-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--f-sans);
  font-size: 13px;
  color: var(--fg);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button { font: inherit; color: inherit; }
input  { font: inherit; color: inherit; }

.hidden { display: none !important; }

*::-webkit-scrollbar          { width: 10px; height: 10px; }
*::-webkit-scrollbar-track    { background: var(--bg-1); }
*::-webkit-scrollbar-thumb    { background: #20262f; border: 2px solid var(--bg-1); border-radius: 6px; }
*::-webkit-scrollbar-thumb:hover { background: #2a313c; }

/* ============ LOGIN ============ */

.login-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(46,163,255,0.06), transparent 60%),
    radial-gradient(800px 400px at 80% 110%, rgba(46,163,255,0.04), transparent 60%),
    var(--bg-0);
}

.login-card {
  width: 360px; padding: 32px 30px 28px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 4px; box-shadow: 0 32px 64px -16px rgba(0,0,0,0.6);
}

.login-mark { font-family: var(--f-mono); font-size: 22px; color: var(--accent); letter-spacing: -2px; margin-bottom: 6px; }
.login-name { font-size: 18px; font-weight: 600; letter-spacing: -0.2px; color: var(--fg-bright); }
.login-sub  { color: var(--fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; margin: 4px 0 24px; }
.login-form label { display: block; margin-bottom: 14px; }
.login-form span  { display: block; font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.login-form input {
  width: 100%; padding: 9px 11px;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 3px; outline: none; transition: border-color 100ms;
}
.login-form input:focus { border-color: var(--accent); }
.login-form button {
  width: 100%; padding: 10px 14px; margin-top: 6px;
  background: var(--accent); color: #001220; font-weight: 600;
  border: 0; border-radius: 3px; cursor: pointer; transition: filter 120ms;
}
.login-form button:hover { filter: brightness(1.1); }
.login-form button:active { filter: brightness(0.9); }
.login-error { margin-top: 10px; color: var(--red); font-size: 12px; min-height: 16px; }

/* ============ SHELL ============ */

.shell {
  display: grid;
  grid-template-areas:
    "header header header"
    "left   main   right"
    "bottom bottom bottom"
    "status status status";
  grid-template-rows: var(--h-header) 1fr var(--h-bottom) var(--h-status);
  grid-template-columns: var(--w-left) 1fr var(--w-right);
  height: 100vh;
  background: var(--bg-0);
}

/* HEADER */
.topbar {
  grid-area: header;
  display: grid; grid-template-columns: var(--w-left) 1fr var(--w-right);
  align-items: stretch;
  background: linear-gradient(180deg, #0e1218 0%, #0b0e13 100%);
  border-bottom: 1px solid var(--line-strong);
  position: relative;
}
.topbar::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(46,163,255,0.18), transparent);
  pointer-events: none;
}

.topbar-brand { display: flex; align-items: center; padding: 0 18px; gap: 10px; border-right: 1px solid var(--line); }
.brand-mark { font-family: var(--f-mono); font-size: 17px; color: var(--accent); letter-spacing: -2px; line-height: 1; }
.brand-name { font-weight: 600; font-size: 14px; color: var(--fg-bright); letter-spacing: -0.2px; }
.brand-sub  { font-family: var(--f-mono); font-size: 10px; color: var(--fg-dim); background: var(--bg-1); padding: 2px 6px; border-radius: 2px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 4px; }

.topbar-center { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 0 16px; }

.killswitch {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong); border-radius: 3px;
  color: var(--fg); font-size: 12px;
  cursor: not-allowed; opacity: 0.85;
  transition: background 120ms, border-color 120ms;
}

.killswitch[data-state="active"] .ks-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px rgba(38,166,154,0.6);
  animation: ks-pulse 2.4s ease-in-out infinite;
}
.killswitch[data-state="paused"] { background: var(--red-soft); border-color: var(--red); color: #ffeaea; }
.killswitch[data-state="paused"] .ks-dot { background: var(--red); box-shadow: 0 0 8px rgba(239,83,80,0.8); animation: ks-pulse-red 1.2s ease-in-out infinite; }

@keyframes ks-pulse { 0%, 100% { box-shadow: 0 0 6px rgba(38,166,154,0.6); } 50% { box-shadow: 0 0 10px rgba(38,166,154,0.9); } }
@keyframes ks-pulse-red { 0%, 100% { box-shadow: 0 0 6px rgba(239,83,80,0.7); } 50% { box-shadow: 0 0 14px rgba(239,83,80,1); } }

.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 14px; border-left: 1px solid var(--line); }
.admin-info  { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-dim); }
.admin-glyph { color: var(--accent); font-size: 10px; }
#admin-name  { color: var(--fg); font-weight: 500; }
.ghost-btn {
  padding: 5px 10px; background: transparent;
  border: 1px solid var(--line-strong); border-radius: 3px;
  color: var(--fg-dim); font-size: 12px; cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.ghost-btn:hover { border-color: var(--accent-soft); color: var(--fg); }

/* DOCKS */
.left-dock  { grid-area: left;  background: var(--bg-1); border-right: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; }
.right-dock { grid-area: right; background: var(--bg-1); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.main-host  { grid-area: main;  background: var(--bg-0); overflow: auto; position: relative; }
#view-host  { min-height: 100%; padding: 16px 20px; }
.bottom-dock { grid-area: bottom; background: var(--bg-1); border-top: 1px solid var(--line-strong); overflow: hidden; display: flex; flex-direction: column; }

/* STATUSBAR */
.statusbar {
  grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: #0a0d12; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--fg-dim); font-family: var(--f-mono);
}
.status-seg  { display: inline-flex; align-items: center; gap: 6px; }
.status-grow { flex: 1; }
.status-dot  { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-faint); }
.status-dot[data-state="up"]      { background: var(--green); box-shadow: 0 0 4px rgba(38,166,154,0.5); }
.status-dot[data-state="down"]    { background: var(--red);   box-shadow: 0 0 4px rgba(239,83,80,0.5); }
.status-dot[data-state="stale"]   { background: var(--gold);  box-shadow: 0 0 4px rgba(255,213,79,0.5); }
.status-dot[data-state="unknown"] { background: var(--fg-faint); }
.status-lbl  { letter-spacing: 0.4px; text-transform: uppercase; }

/* PANEL CHROME */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-title { font-size: 10px; font-weight: 600; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 1.2px; }
.panel-meta  { font-family: var(--f-mono); font-size: 10px; color: var(--fg-dimmer); letter-spacing: 0.3px; }
.panel-body  { flex: 1; overflow: auto; background: var(--bg-1); }

/* MARKET WATCH */
.mw-table { width: 100%; border-collapse: collapse; font-family: var(--f-mono); font-size: 11.5px; }
.mw-table thead th { position: sticky; top: 0; background: var(--bg-2); border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: right; font-weight: 500; font-size: 10px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.5px; z-index: 1; }
.mw-table thead th:first-child { text-align: left; }
.mw-table tbody td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mw-table tbody td:first-child { text-align: left; color: var(--fg); }
.mw-table tbody tr:hover { background: var(--bg-hover); }
.mw-bid { color: var(--red); } .mw-ask { color: var(--green); } .mw-sprd { color: var(--fg-dim); } .mw-stale { color: var(--fg-dimmer); }
.mw-flash-up   { animation: flash-up   500ms ease-out; }
.mw-flash-down { animation: flash-down 500ms ease-out; }
@keyframes flash-up   { 0% { background: rgba(38,166,154,0.35); } 100% { background: transparent; } }
@keyframes flash-down { 0% { background: rgba(239,83,80,0.35); } 100% { background: transparent; } }
.mw-footer-note { padding: 8px 12px; font-size: 10.5px; color: var(--fg-dim); background: var(--bg-2); border-top: 1px solid var(--line); text-align: center; font-family: var(--f-mono); letter-spacing: 0.2px; }

/* NAVIGATOR */
.nav-tree { padding: 4px 0; font-size: 12.5px; }
.nav-section { margin-bottom: 4px; }
.nav-section-head { padding: 9px 14px 6px; font-size: 10px; font-weight: 600; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 1.2px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px 6px 22px; cursor: pointer; color: var(--fg); border-left: 2px solid transparent; transition: background 80ms, border-left-color 80ms; user-select: none; }
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--accent-faint); border-left-color: var(--accent); color: var(--fg-bright); }
.nav-item .nav-label { flex: 1; }
.nav-item .nav-count { font-family: var(--f-mono); font-size: 10.5px; color: var(--fg-dim); background: var(--bg-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 9px; min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.nav-item.active .nav-count { color: var(--accent); border-color: var(--accent-soft); }
.nav-item .nav-count.danger { color: var(--red);  border-color: var(--red-soft);  background: var(--red-soft); }
.nav-item .nav-count.warn   { color: var(--gold); border-color: var(--gold-soft); background: var(--gold-soft); }

/* DEALING */
.dealing-head { display: flex; align-items: stretch; background: var(--bg-2); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.dealing-tabs { display: flex; }
.dealing-tab  { padding: 8px 18px; background: transparent; border: 0; border-right: 1px solid var(--line); border-bottom: 2px solid transparent; color: var(--fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; font-weight: 500; cursor: pointer; transition: background 80ms, color 80ms, border-color 80ms; }
.dealing-tab:hover { background: var(--bg-hover); color: var(--fg); }
.dealing-tab.active { color: var(--fg-bright); background: var(--bg-1); border-bottom-color: var(--accent); }
.dealing-meta { flex: 1; display: flex; align-items: center; justify-content: flex-end; padding: 0 14px; font-family: var(--f-mono); font-size: 10.5px; color: var(--fg-dimmer); }
.dealing-table-wrap { flex: 1; overflow: auto; background: var(--bg-1); }
.dealing-table { width: 100%; border-collapse: collapse; font-family: var(--f-mono); font-size: 11.5px; }
.dealing-table thead th { position: sticky; top: 0; background: var(--bg-2); border-bottom: 1px solid var(--line); padding: 5px 12px; text-align: left; font-weight: 500; font-size: 10px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.dealing-table tbody td { padding: 5px 12px; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; vertical-align: top; }
.dealing-table tbody tr:hover { background: var(--bg-hover); }
.dealing-time   { color: var(--fg-dim); width: 92px; }
.dealing-login  { color: var(--accent); width: 80px; }
.dealing-type   { color: var(--fg); width: 130px; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.5px; }
.dealing-detail { color: var(--fg); }
.dealing-out    { width: 90px; text-align: right; }
.dealing-out.done   { color: var(--green); }
.dealing-out.placed { color: var(--accent); }
.dealing-out.failed { color: var(--red); }
.dealing-empty { padding: 40px 16px; text-align: center; color: var(--fg-dimmer); font-size: 12px; font-style: italic; }

/* VIEW HOST GENERIC */
#view-host h1 { font-size: 18px; font-weight: 600; color: var(--fg-bright); margin: 0 0 4px; letter-spacing: -0.2px; }
#view-host h2 { font-size: 14px; font-weight: 600; color: var(--fg); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.8px; }
#view-host h3 { font-size: 12px; font-weight: 600; color: var(--fg-dim); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 1px; }
#view-host p  { color: var(--fg-dim); margin: 0 0 8px; }
#view-host a  { color: var(--accent); text-decoration: none; }
#view-host a:hover { text-decoration: underline; }

.data, table.data {
  width: 100%; border-collapse: collapse;
  font-family: var(--f-mono); font-size: 12px;
  background: var(--bg-1); border: 1px solid var(--line);
  margin: 8px 0 18px;
}
.data thead th { padding: 7px 10px; background: var(--bg-2); border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; font-weight: 600; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.6px; white-space: nowrap; }
.data tbody td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.data tbody tr:hover { background: var(--bg-hover); cursor: default; }
.data .num-right, .data td.num, .data th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pos { color: var(--green); }
.neg { color: var(--red); }

.book-A { display: inline-block; padding: 1px 6px; background: var(--green-soft); color: #b6efd8; border-radius: 2px; font-size: 10px; font-weight: 600; letter-spacing: 0.5px; }
.book-B { display: inline-block; padding: 1px 6px; background: var(--red-soft);   color: #ffc7c5; border-radius: 2px; font-size: 10px; font-weight: 600; letter-spacing: 0.5px; }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 3px; padding: 14px 16px; margin-bottom: 12px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.detail-grid > div { font-family: var(--f-mono); font-size: 12px; }
.detail-grid > div b, .detail-grid > div strong { display: block; font-family: var(--f-sans); font-size: 10px; font-weight: 600; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 4px; }

form.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
form.inline input, form.inline select { padding: 6px 10px; background: var(--bg-1); border: 1px solid var(--line); border-radius: 3px; font-size: 12px; outline: none; }
form.inline input:focus, form.inline select:focus { border-color: var(--accent); }
form.inline button, .btn { padding: 6px 12px; background: var(--accent); color: #001220; border: 0; border-radius: 3px; font-size: 12px; font-weight: 600; cursor: pointer; transition: filter 120ms; }
.btn.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line-strong); }
.btn.danger    { background: var(--red); color: #fff; }
form.inline button:hover, .btn:hover { filter: brightness(1.1); }

.banner-warn, .banner-danger { padding: 10px 14px; margin-bottom: 12px; border: 1px solid var(--red); background: var(--red-soft); color: #ffd9d8; border-radius: 3px; font-size: 12px; }
.banner-warn { border-color: var(--warn); background: rgba(255,152,0,0.15); color: #ffd699; }

/* =========================================================================
   PHASE 2 — RISK VIEW
   ========================================================================= */

.risk-view { padding-bottom: 30px; }

.risk-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.risk-header h1 { margin: 0; }
.risk-meta {
  font-family: var(--f-mono); font-size: 11px; color: var(--fg-dim);
  letter-spacing: 0.3px;
}

/* TILES */
.risk-tiles {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin-bottom: 16px;
}

.risk-tile {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 3px;
  padding: 14px 16px;
  position: relative;
  transition: border-left-color 120ms;
}

.risk-tile.tile-critical { border-left-color: var(--red);   }
.risk-tile.tile-stopout  { border-left-color: var(--red);   }
.risk-tile.tile-mc       { border-left-color: var(--gold);  }
.risk-tile.tile-safe     { border-left-color: var(--green); }

.tile-label {
  font-size: 10px; font-weight: 600; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: 1.2px;
  margin-bottom: 6px;
}

.tile-count {
  font-family: var(--f-mono); font-size: 28px; font-weight: 600;
  color: var(--fg-bright); line-height: 1;
  margin-bottom: 6px;
}

.tile-critical .tile-count { color: var(--red);   }
.tile-stopout  .tile-count { color: var(--red);   }
.tile-mc       .tile-count { color: var(--gold);  }
.tile-safe     .tile-count { color: var(--green); }

.tile-sub {
  font-family: var(--f-mono); font-size: 11px;
  color: var(--fg-dim);
}

/* Recent margin events */
.risk-recent-card {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--bg-2);
  border: 1px solid var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: 3px;
}
.risk-recent-label {
  font-size: 10px; color: var(--gold);
  text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600;
  white-space: nowrap;
}
.risk-recent-list { display: flex; flex-wrap: wrap; gap: 12px; }
.risk-recent-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--f-mono); font-size: 11px;
}
.recent-time   { color: var(--fg-dim); }
.recent-action { color: var(--fg); text-transform: uppercase; letter-spacing: 0.4px; font-size: 10.5px; }
.recent-login  { color: var(--accent); }

/* Section heads */
.risk-section { margin-bottom: 18px; }
.risk-section h2 { display: flex; align-items: baseline; gap: 8px; }
.risk-section-meta {
  font-family: var(--f-mono); font-size: 11px; font-weight: 500;
  color: var(--fg-dimmer); letter-spacing: 0;
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 1px 8px; border-radius: 9px;
  text-transform: none;
}

/* Risk tables */
.risk-table { font-size: 11.5px; }
.risk-table .sortable {
  cursor: pointer; user-select: none;
  transition: background 80ms, color 80ms;
}
.risk-table .sortable:hover { background: var(--bg-hover); color: var(--fg); }
.risk-table .sort-arrow {
  font-size: 9px; margin-left: 4px;
  color: var(--accent);
}

.risk-table .risk-row { cursor: pointer; }
.risk-table .risk-row:hover { background: var(--bg-hover); }

.lvl-critical { color: var(--red);  font-weight: 600; }
.lvl-warn     { color: var(--gold); font-weight: 600; }

.risk-empty {
  padding: 14px 16px; color: var(--fg-dimmer);
  font-style: italic; font-size: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 3px;
  margin: 8px 0 18px;
}

/* Narrower screens — tiles collapse to 2 columns */
@media (max-width: 1200px) {
  .risk-tiles { grid-template-columns: repeat(2, 1fr); }
}
