/* =============================================================================
   styles.css — TradercloudOps SPA
   Brand: data-dense fintech terminal. Mobile-first. Dark by default,
   honors prefers-color-scheme: light. WCAG focus rings. ≥44×44 touch targets.
   ============================================================================= */

/* ---------------------------------------------------------------------------
   Brand tokens — ONE source of truth for colors / spacing / typography.
   --------------------------------------------------------------------------- */
:root {
  /* Brand */
  --brand-mint:        #00D4A8;
  --brand-mint-glow:   rgba(0, 212, 168, 0.25);
  --brand-gold:        #F0B90B;
  --brand-coral:       #FF4D6D;
  --brand-violet:      #7C5CFF;

  /* Dark surfaces (default) */
  --bg-app:        #0B1018;
  --bg-surface:    #131826;
  --bg-elevated:   #1A2030;
  --bg-input:      #0E1420;
  --bg-glass:      rgba(19, 24, 38, 0.72);
  --border:        #2A3142;
  --border-strong: #3D4659;
  --text:          #E8EEF7;
  --text-muted:    #8B95AB;
  --text-dim:      #5C657A;
  --grid-line:     rgba(0, 212, 168, 0.04);

  /* Status */
  --ok:    #10D970;
  --warn:  #FFB020;
  --err:   #FF4D6D;
  --info:  #4DA8FF;

  /* Geometry */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Type */
  --font-display: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-body:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-app:        #F4F6FA;
    --bg-surface:    #FFFFFF;
    --bg-elevated:   #FAFBFD;
    --bg-input:      #FFFFFF;
    --bg-glass:      rgba(255, 255, 255, 0.86);
    --border:        #D9E0EA;
    --border-strong: #BFC7D4;
    --text:          #0E1420;
    --text-muted:    #475569;
    --text-dim:      #64748B;
    --grid-line:     rgba(0, 153, 122, 0.04);
  }
}

/* ---------------------------------------------------------------------------
   Reset + base
   --------------------------------------------------------------------------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  font-size: 16px; line-height: 1.55;
  color: var(--text);
  background: var(--bg-app);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

main { padding: 16px 12px 64px; max-width: 1200px; margin: 0 auto; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.015em; margin: 0; }
h1 { font-size: 1.05rem; }
h2 { font-size: 1.4rem; margin: 0 0 14px; }
p  { margin: 0 0 12px; }

.muted { color: var(--text-muted); font-size: 0.9rem; }
.error { color: var(--err); font-weight: 500; }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-elevated);
  color: var(--text);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  word-break: break-all;
}

/* ---------------------------------------------------------------------------
   Brand
   --------------------------------------------------------------------------- */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-family: var(--font-display); font-weight: 600;
}
.brand-mark { width: 28px; height: 28px; display: block; flex: 0 0 auto; }
.brand-mark-lg { width: 44px; height: 44px; }
.brand-name { font-size: 1.05rem; letter-spacing: -.01em; }
.brand-name-accent { color: var(--brand-mint); }

.brand-login {
  margin: 12px auto 6px;
  font-size: 1.4rem;
}
.brand-login .brand-name { font-size: 1.4rem; }
.brand-tagline {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem; letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: center;
  margin: 0 0 24px;
}

/* ---------------------------------------------------------------------------
   Topbar + tabs
   --------------------------------------------------------------------------- */
header#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--bg-glass);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
header#topbar .brand { flex: 1; }

.status-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem; font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.status-pill.ok      { background: rgba(16, 217, 112, 0.12); color: var(--ok);   border-color: rgba(16, 217, 112, 0.3); }
.status-pill.warn    { background: rgba(255, 176, 32, 0.12); color: var(--warn); border-color: rgba(255, 176, 32, 0.3); }
.status-pill.err     { background: rgba(255, 77, 109, 0.12); color: var(--err);  border-color: rgba(255, 77, 109, 0.3); }
.status-pill.loading { background: var(--bg-elevated); color: var(--text-muted); }

nav#tabnav {
  position: sticky; top: 57px; z-index: 9;
  display: flex; gap: 4px; overflow-x: auto;
  padding: 8px 12px;
  background: var(--bg-glass);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
nav#tabnav .tab {
  background: transparent; border: none;
  font-family: var(--font-display); font-weight: 500; font-size: 0.92rem;
  color: var(--text-muted);
  padding: 10px 14px; border-radius: 8px;
  cursor: pointer; min-height: 44px;
  white-space: nowrap;
  position: relative;
  transition: color .15s ease, background .15s ease;
}
nav#tabnav .tab:hover { color: var(--text); background: var(--bg-elevated); }
nav#tabnav .tab[aria-current="page"] {
  color: var(--brand-mint);
  background: rgba(0, 212, 168, 0.08);
}
nav#tabnav .tab[aria-current="page"]::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 4px;
  height: 2px; background: var(--brand-mint); border-radius: 2px;
  box-shadow: 0 0 8px var(--brand-mint-glow);
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.95rem;
  padding: 12px 18px; min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--bg-elevated); color: var(--text);
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease, box-shadow .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brand-mint); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(135deg, var(--brand-mint) 0%, #00B695 100%);
  color: #06160F;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(0, 212, 168, 0.18);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(0, 212, 168, 0.32); }

.btn.danger  { background: linear-gradient(135deg, var(--err) 0%, #D9304F 100%); color: white; box-shadow: 0 4px 14px rgba(255, 77, 109, 0.18); }
.btn.success { background: linear-gradient(135deg, var(--ok) 0%, #0AAB59 100%); color: #04140A; box-shadow: 0 4px 14px rgba(16, 217, 112, 0.18); }
.btn.ghost   { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-elevated); border-color: var(--border-strong); }

/* Inline link button */
.link-btn {
  background: transparent; border: none; padding: 6px 0;
  color: var(--brand-mint); font: inherit; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer; align-self: flex-start;
}
.link-btn:hover { color: #5EEAD4; }
.link-btn:focus-visible { outline: 2px solid var(--brand-mint); outline-offset: 2px; border-radius: 2px; }

/* ---------------------------------------------------------------------------
   Panels + cards
   --------------------------------------------------------------------------- */
.panel { padding: 16px 4px; }

.login-panel {
  max-width: 460px; margin: 32px auto;
  padding: 32px 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--border) inset;
  position: relative;
}
.login-panel::before {
  content: ""; position: absolute; inset: -1px; border-radius: var(--radius-xl);
  padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, rgba(0, 212, 168, 0.4), transparent 40%, transparent 60%, rgba(240, 185, 11, 0.25));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}

.cards { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 16px; }
@media (min-width: 600px) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .cards { grid-template-columns: 1fr 1fr 1fr 1fr; } }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius-lg);
  transition: border-color .15s ease, transform .15s ease;
}
.card:hover { border-color: var(--border-strong); }
.card .label { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.card .value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; word-break: break-word; margin-top: 4px; }
.card.skeleton { background: linear-gradient(90deg, var(--bg-surface) 0%, var(--bg-elevated) 50%, var(--bg-surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; height: 88px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }

/* ---------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------- */
form { display: flex; flex-direction: column; gap: 10px; max-width: 480px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
label {
  color: var(--text-muted);
  font-family: var(--font-display); font-weight: 500; font-size: 0.85rem;
}
input[type="email"], input[type="password"], input[type="text"], input[type="tel"], select, textarea {
  width: 100%;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px; font: inherit; min-height: 44px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-mint); outline: none;
  box-shadow: 0 0 0 3px var(--brand-mint-glow);
}
textarea { min-height: 80px; font-family: var(--font-mono); }

/* Password input + eye toggle */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--bg-elevated); }
.pw-toggle:focus-visible { outline: 2px solid var(--brand-mint); outline-offset: 2px; }
.pw-toggle[aria-pressed="true"] { color: var(--brand-mint); }

/* ---------------------------------------------------------------------------
   QR code
   --------------------------------------------------------------------------- */
.qr-wrap {
  background: #ffffff;
  padding: 14px;
  border-radius: var(--radius);
  display: inline-block;
  margin: 12px 0;
  max-width: 100%;
  border: 1px solid var(--border);
  box-shadow: 0 0 0 1px var(--brand-mint-glow);
}
.qr-wrap svg { display: block; max-width: 100%; height: auto; }

/* ---------------------------------------------------------------------------
   Tables (logs / alarms)
   --------------------------------------------------------------------------- */
.table {
  width: 100%; border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table thead { background: var(--bg-elevated); }
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th {
  color: var(--text-muted);
  font-family: var(--font-display); font-weight: 600;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em;
}
.table tbody tr:last-child td { border-bottom: none; }
.table td { font-family: var(--font-mono); font-size: 0.82rem; }

/* ---------------------------------------------------------------------------
   Sessions tree + preview
   --------------------------------------------------------------------------- */
.filetree {
  list-style: none; padding: 0; margin: 8px 0;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 0.85rem;
}
.filetree li {
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.filetree li:hover { background: var(--bg-elevated); color: var(--brand-mint); }
.filetree li:last-child { border-bottom: none; }

.preview {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--radius);
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--font-mono); font-size: 0.82rem;
}

/* ---------------------------------------------------------------------------
   Charts
   --------------------------------------------------------------------------- */
.charts {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 800px) { .charts { grid-template-columns: 1fr 1fr; } }
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 240px;
}

/* ---------------------------------------------------------------------------
   Phase Cloud-3.1 redesign — new tab elements
   --------------------------------------------------------------------------- */

/* Subheadings inside a tab panel (Wallet, Analysis, etc) */
.section-h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  margin: 24px 0 10px;
  color: var(--text);
}

/* Mint mini-badge for things like "current regime" */
.badge-mint {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand-mint);
  background: rgba(0, 212, 168, 0.10);
  border: 1px solid rgba(0, 212, 168, 0.30);
  border-radius: 999px;
  vertical-align: middle;
}

/* Wallet table — green / red PnL */
.pnl-pos { color: var(--ok); font-weight: 600; }
.pnl-neg { color: var(--err); font-weight: 600; }

/* Forensics file mtime suffix */
.filetree .size, .filetree .mtime {
  color: var(--text-dim); font-size: 0.78rem; margin-left: 8px; font-weight: 400;
}

/* Commands tab — collapsible categories */
.cmd-cat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.cmd-cat > summary {
  cursor: pointer;
  padding: 14px 16px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  position: relative;
}
.cmd-cat > summary::-webkit-details-marker { display: none; }
.cmd-cat > summary::after {
  content: "▾";
  position: absolute; right: 16px;
  color: var(--text-muted);
  transition: transform .15s ease;
}
.cmd-cat[open] > summary::after { transform: rotate(180deg); }
.cmd-cat > summary:hover { color: var(--brand-mint); }
.cmd-list { padding: 4px 16px 14px; display: flex; flex-direction: column; gap: 4px; }
.cmd-list details {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}
.cmd-list details summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  list-style: none;
  position: relative;
  padding-right: 22px;
}
.cmd-list details summary::-webkit-details-marker { display: none; }
.cmd-list details summary::after {
  content: "+";
  position: absolute; right: 0; top: 0;
  color: var(--text-dim);
  font-size: 1.1rem;
  font-family: var(--font-display);
}
.cmd-list details[open] summary::after { content: "−"; color: var(--brand-mint); }
.cmd-list details p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}
.cmd-list details.cmd-danger summary { color: var(--err); }
.cmd-list details.cmd-danger summary code { border-color: rgba(255, 77, 109, 0.4); }

/* Config tab — YAML block */
.yaml-block {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  max-height: 70vh;
  white-space: pre;
  overflow: auto;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */
footer {
  text-align: center;
  padding: 24px 12px 12px;
  color: var(--text-dim);
  font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------------------
   Reduced motion
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
