/* ============================================================
   Ciga · ELT — Dark trading-style dashboard
   Tokens
   ============================================================ */
:root {
  --bg-0: #07090f;
  --bg-1: #0a0d14;
  --bg-2: #0f1320;
  --surface: rgba(20, 25, 38, 0.55);
  --surface-2: rgba(15, 19, 32, 0.7);
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 181, 71, 0.18);
  --text: #e6e9f0;
  --text-muted: rgba(230, 233, 240, 0.55);
  --text-dim: rgba(230, 233, 240, 0.35);
  --accent: #ffb547;
  --accent-2: #ffc878;
  --pos: #22d3a3;
  --neg: #ff5a78;
  --info: #60a5fa;
  --purple: #a78bfa;
  --green: #4ade80;

  --font-thai: 'IBM Plex Sans Thai', 'Sarabun', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-thai);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 181, 71, 0.05), transparent 50%),
    radial-gradient(900px 500px at -10% 110%, rgba(124, 92, 255, 0.04), transparent 50%),
    radial-gradient(1000px 700px at 50% 50%, rgba(34, 211, 163, 0.02), transparent 60%),
    var(--bg-0);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: 0.005em;
  overflow-x: hidden;
}

/* subtle grid background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at center, black 0%, transparent 80%);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.06); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 181, 71, 0.25); }

/* ============================================================
   App shell
   ============================================================ */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.main {
  flex: 1;
  padding: 20px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 181, 71, 0.18), rgba(124, 92, 255, 0.1));
  border: 1px solid rgba(255, 181, 71, 0.25);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 24px rgba(255, 181, 71, 0.18) inset, 0 4px 16px rgba(0, 0, 0, 0.4);
}
.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}
.brand-sub { font-size: 10px; color: var(--text-muted); letter-spacing: 0.06em; }
.topbar-sep {
  width: 1px; height: 24px; background: var(--border);
  margin: 0 4px;
}
.period-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 4px 10px;
  background: rgba(15, 19, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
}

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(15, 19, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  position: relative;
  transition: all 150ms ease;
}
.icon-btn:hover {
  background: rgba(255, 181, 71, 0.08);
  border-color: rgba(255, 181, 71, 0.3);
  color: var(--accent);
}
.icon-btn-dot {
  position: absolute; top: 8px; right: 8px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--neg);
  box-shadow: 0 0 8px var(--neg);
}
.icon-btn-mini {
  width: 24px; height: 24px;
  background: transparent; border: 1px solid transparent;
  border-radius: 6px; color: var(--text-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 150ms ease;
}
.icon-btn-mini:hover { background: rgba(255, 90, 120, 0.1); color: var(--neg); border-color: rgba(255, 90, 120, 0.2); }

.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207;
  border: none;
  border-radius: 8px;
  font-family: var(--font-thai);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 181, 71, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 150ms ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255, 181, 71, 0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-thai); font-size: 12.5px;
  cursor: pointer;
  transition: all 150ms ease;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }
.btn-ghost.btn-danger { color: var(--neg); border-color: rgba(255, 90, 120, 0.3); }
.btn-ghost.btn-danger:hover { background: rgba(255, 90, 120, 0.1); }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #0a0d14;
  font-family: var(--font-mono);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================================
   Pill
   ============================================================ */
.pill {
  --pill-color: var(--accent);
  padding: 5px 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--font-thai);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 150ms ease;
}
.pill:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.pill-active {
  color: var(--pill-color);
  background: rgba(255, 181, 71, 0.1);
  border-color: rgba(255, 181, 71, 0.25);
  box-shadow: 0 0 12px rgba(255, 181, 71, 0.1) inset;
}
.pill-mono { font-family: var(--font-mono); }

/* ============================================================
   Currency toggle
   ============================================================ */
.ccy-toggle {
  display: inline-flex;
  padding: 3px;
  background: rgba(15, 19, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  gap: 2px;
}
.ccy-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-thai);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 150ms ease;
  line-height: 1;
}
.ccy-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.ccy-btn .ccy-sym {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-dim);
}
.ccy-btn.active {
  background: rgba(255, 181, 71, 0.1);
  border-color: rgba(255, 181, 71, 0.25);
  color: var(--accent);
}
.ccy-btn.active .ccy-sym { color: var(--accent); text-shadow: 0 0 12px rgba(255, 181, 71, 0.5); }

/* ============================================================
   Shareholders / profit split
   ============================================================ */
.sh-wrap { display: flex; flex-direction: column; gap: 14px; }
.sh-summary {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sh-stat { display: flex; flex-direction: column; gap: 4px; }
.sh-stat-val {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sh-stat-mgmt .sh-stat-val { font-size: 18px; }
.sh-stat-pool .sh-stat-val { font-size: 20px; }
.sh-arrow {
  color: var(--text-dim);
  font-size: 22px;
  font-family: var(--font-mono);
}

.sh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sh-table th {
  text-align: left;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.sh-table td {
  padding: 12px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}
.sh-table td.mono { font-family: var(--font-mono); }
.sh-table td.right { text-align: right; }
.sh-table td.muted { color: var(--text-muted); }
.sh-table tbody tr:hover { background: rgba(255, 181, 71, 0.03); }
.sh-row td:first-child {
  display: flex; align-items: center; gap: 10px;
}
.sh-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #0a0d14;
  font-family: var(--font-mono);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.sh-name { color: var(--text); font-size: 13px; }
.sh-row-mgmt {
  background: linear-gradient(90deg, rgba(255, 90, 120, 0.05), transparent 60%);
}
.sh-row-mgmt td:first-child::before {
  content: '';
  position: absolute;
}
.sh-row-total {
  background: rgba(255, 181, 71, 0.04);
  border-top: 1px solid var(--accent) !important;
}
.sh-row-total td {
  padding: 14px 12px !important;
  border-bottom: none !important;
  font-weight: 600;
}
.sh-warn { color: var(--neg); }
.sh-warn-msg {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 90, 120, 0.08);
  border: 1px solid rgba(255, 90, 120, 0.25);
  border-radius: 8px;
  color: var(--neg);
  font-size: 12px;
}

/* ============================================================
   Shareholder edit modal
   ============================================================ */
.sh-edit-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sh-edit-total {
  font-family: var(--font-mono);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.sh-edit-total.ok {
  color: var(--pos);
  background: rgba(34, 211, 163, 0.08);
  border-color: rgba(34, 211, 163, 0.25);
}
.sh-edit-total.bad {
  color: var(--neg);
  background: rgba(255, 90, 120, 0.08);
  border-color: rgba(255, 90, 120, 0.25);
}
.sh-edit-list { display: flex; flex-direction: column; gap: 6px; }
.sh-edit-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.sh-edit-pct {
  display: flex; align-items: center; gap: 4px;
}

/* ============================================================
   Settings modal
   ============================================================ */
.settings-section {
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.settings-section-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.04em;
  font-weight: 600;
}
.presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.presets-label { font-size: 11px; color: var(--text-muted); margin-right: 4px; }
.preset-btn {
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms ease;
}
.preset-btn:hover { color: var(--text); border-color: rgba(255, 181, 71, 0.3); }
.preset-btn.active {
  color: var(--accent);
  background: rgba(255, 181, 71, 0.08);
  border-color: rgba(255, 181, 71, 0.3);
}
.rate-preview {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 6px 16px;
  padding: 10px 12px;
  background: rgba(255, 181, 71, 0.04);
  border: 1px dashed rgba(255, 181, 71, 0.25);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.rate-preview > div:nth-child(2),
.rate-preview > div:nth-child(3),
.rate-preview > div:nth-child(4) {
  grid-column: span 1;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 6px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}
input[type="range"]::-moz-range-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  background: var(--accent);
  border-radius: 50%;
  margin-top: -5px;
  box-shadow: 0 0 0 4px rgba(255, 181, 71, 0.15), 0 0 12px rgba(255, 181, 71, 0.5);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  box-shadow: 0 0 0 4px rgba(255, 181, 71, 0.15);
  cursor: pointer;
}

@media (max-width: 800px) {
  .sh-summary { grid-template-columns: 1fr; }
  .sh-arrow { transform: rotate(90deg); justify-self: start; }
}

/* ============================================================
   DB export/import
   ============================================================ */
.db-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 181, 71, 0.04);
  border: 1px dashed rgba(255, 181, 71, 0.2);
  border-radius: 8px;
}
.db-stats > div {
  display: flex; flex-direction: column; gap: 2px;
  font-family: var(--font-mono);
}
.db-stats > div > span:first-child {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-thai);
}
.db-stats > div > span:last-child {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}
.export-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.export-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-thai);
  transition: all 150ms ease;
}
.export-btn:hover {
  background: rgba(255, 181, 71, 0.04);
  border-color: rgba(255, 181, 71, 0.3);
  transform: translateY(-1px);
}
.export-btn-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.export-btn-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.export-btn-text strong { font-size: 13px; color: var(--text); }
.export-btn-text span {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.db-help {
  font-size: 11px;
  color: var(--text-muted);
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 1.7;
}
.db-help strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.db-help ol { margin: 0; padding-left: 18px; }
.db-help code {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: rgba(255, 181, 71, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent);
}

.danger-zone {
  border-color: rgba(255, 90, 120, 0.25) !important;
  background: rgba(255, 90, 120, 0.04) !important;
}
.btn-danger-full {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 90, 120, 0.08);
  border: 1px solid rgba(255, 90, 120, 0.35);
  border-radius: 8px;
  color: var(--neg);
  font-family: var(--font-thai);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
}
.btn-danger-full:hover {
  background: rgba(255, 90, 120, 0.15);
  border-color: var(--neg);
  box-shadow: 0 4px 20px rgba(255, 90, 120, 0.15);
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: 84px;
  background: rgba(10, 13, 20, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}
.sidebar-items { display: flex; flex-direction: column; gap: 4px; padding: 0 12px; }
.side-item {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 12px 8px;
  border-radius: 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  position: relative;
  cursor: pointer;
  transition: all 150ms ease;
}
.side-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.side-item.active {
  color: var(--accent);
  background: linear-gradient(135deg, rgba(255, 181, 71, 0.08), transparent);
}
.side-icon { display: flex; align-items: center; justify-content: center; }
.side-indicator {
  position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 24px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
  margin: 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.status-led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 8px var(--pos);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ============================================================
   Ticker
   ============================================================ */
.ticker {
  height: 28px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}
.ticker::before, .ticker::after {
  content: '';
  position: absolute; top: 0; bottom: 0;
  width: 60px;
  z-index: 1;
  pointer-events: none;
}
.ticker::before { left: 0; background: linear-gradient(90deg, var(--bg-0), transparent); }
.ticker::after { right: 0; background: linear-gradient(-90deg, var(--bg-0), transparent); }
.ticker-track {
  display: inline-flex;
  white-space: nowrap;
  animation: tick 80s linear infinite;
  padding-left: 0;
}
@keyframes tick {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
.ticker-item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 28px;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.ticker-label { color: var(--text-muted); letter-spacing: 0.05em; }
.ticker-value { color: var(--text); font-weight: 600; }
.ticker-delta { font-weight: 600; }

/* ============================================================
   Glass card
   ============================================================ */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  position: relative;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.03) inset,
    0 24px 48px rgba(0, 0, 0, 0.25);
  transition: border-color 200ms ease, transform 200ms ease;
}
.glass-card::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 50%);
  pointer-events: none;
}
.glass-card:hover {
  border-color: rgba(255, 181, 71, 0.18);
}
.glass-glow {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 0 0 1px rgba(255, 181, 71, 0.1),
    0 24px 60px rgba(255, 181, 71, 0.08),
    0 24px 48px rgba(0, 0, 0, 0.3);
}

/* ============================================================
   KPI grid
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}
.kpi {
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
  --kpi-accent: var(--accent);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: '';
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--kpi-accent), transparent);
  opacity: 0.5;
}
.kpi-head {
  display: flex; align-items: center; justify-content: space-between;
}
.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.kpi-delta.pos { color: var(--pos); background: rgba(34, 211, 163, 0.1); }
.kpi-delta.neg { color: var(--neg); background: rgba(255, 90, 120, 0.1); }
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.1;
  display: flex; align-items: baseline;
}
.kpi-value.big { font-size: 28px; }
.kpi-suffix { font-size: 11px; color: var(--text-muted); margin-left: 6px; font-weight: 400; }
.kpi-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.kpi-prev { font-size: 10.5px; color: var(--text-dim); flex: 1; }

/* ============================================================
   Row grid
   ============================================================ */
.row-grid { display: grid; gap: 14px; }
.row-grid.two-cols { grid-template-columns: 2fr 1fr; }
.stock-grid { grid-template-columns: 1fr 1fr 2fr; }

@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .row-grid.two-cols { grid-template-columns: 1fr; }
  .stock-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .stock-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Panel
   ============================================================ */
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 16px;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.panel-sub {
  font-size: 11px;
  color: var(--text-muted);
}
.legend {
  display: flex; gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }

.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: transparent; border: 1px dashed rgba(255, 181, 71, 0.25);
  color: var(--accent); padding: 5px 10px;
  border-radius: 6px; font-family: var(--font-thai); font-size: 11px;
  cursor: pointer;
  transition: all 150ms ease;
}
.link-btn:hover { background: rgba(255, 181, 71, 0.06); }

/* ============================================================
   Donut wrap
   ============================================================ */
.donut-wrap {
  display: flex; align-items: center; gap: 20px;
  padding: 8px 0;
}
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.donut-row { min-width: 0; }
.donut-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.donut-row-name { font-size: 12px; color: var(--text); flex: 1; }
.donut-row-pct { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.donut-row-val { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.donut-row-bar {
  height: 4px; background: rgba(255, 255, 255, 0.05);
  border-radius: 2px; overflow: hidden;
}
.donut-row-bar span { display: block; height: 100%; border-radius: 2px; transition: width 600ms cubic-bezier(.2,.7,.3,1); }

/* ============================================================
   Investment timeline
   ============================================================ */
.invest-timeline {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 18px;
}
.invest-row {
  display: flex; gap: 12px;
  padding: 8px 0;
}
.invest-node {
  width: 16px;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
}
.invest-dot {
  width: 10px; height: 10px; border-radius: 50%;
  margin-top: 4px;
  box-shadow: 0 0 12px currentColor;
}
.invest-line {
  position: absolute; top: 18px; bottom: -12px;
  width: 1px; background: rgba(255, 181, 71, 0.15);
  left: 50%;
}
.invest-body { flex: 1; padding-bottom: 8px; border-bottom: 1px dashed rgba(255, 255, 255, 0.04); }
.invest-head {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-dim);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.invest-title { font-size: 13px; color: var(--text); margin-bottom: 4px; }
.invest-meta {
  display: flex; justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}
.invest-amount {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 600;
}
.invest-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 150ms ease;
}
.invest-row:hover .invest-actions { opacity: 1; }
.icon-btn-mini.neutral {
  color: var(--text-muted);
}
.icon-btn-mini.neutral:hover {
  background: rgba(255, 181, 71, 0.08);
  color: var(--accent);
  border-color: rgba(255, 181, 71, 0.25);
}
.seg-wrap { flex-wrap: wrap; }
.seg-wrap .seg-btn { flex: 0 0 auto; padding: 6px 12px; }

input[type="date"] {
  color-scheme: dark;
  font-family: var(--font-mono) !important;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7) sepia(1) saturate(4) hue-rotate(0deg) brightness(1.1);
  cursor: pointer;
  opacity: 0.7;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

.invest-total {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.muted-label {
  font-size: 10px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 4px;
  display: block;
}
.big-stat {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
}

/* ============================================================
   P&L table
   ============================================================ */
.pl-table { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.pl-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
  position: relative;
}
.pl-row .pl-bar {
  grid-column: 1 / -1;
  height: 3px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.pl-row .pl-bar span { display: block; height: 100%; transition: width 500ms cubic-bezier(.2,.7,.3,1); }
.pl-name { font-size: 12.5px; color: var(--text); }
.pl-val {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}
.pl-val.pos { color: var(--pos); }
.pl-val.neg { color: var(--neg); }
.pl-row.sub .pl-name { color: var(--accent); font-weight: 500; }
.pl-row.sub .pl-val { color: var(--accent); }
.pl-row.total {
  padding-top: 14px; margin-top: 4px;
  border-top: 1px solid var(--accent);
  border-bottom: none;
}
.pl-row.total .pl-name { font-size: 14px; font-weight: 600; }
.pl-row.total .pl-val { font-size: 18px; }

.margin-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Stock cards
   ============================================================ */
.stock-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px;
  --prod-color: var(--accent);
  overflow: hidden;
  position: relative;
}
.stock-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 120px;
  background: radial-gradient(circle at top right, hsla(var(--prod-hue), 90%, 65%, 0.06), transparent 60%);
  pointer-events: none;
}
.stock-head { display: flex; justify-content: space-between; align-items: flex-start; }
.stock-prod { display: flex; gap: 12px; align-items: center; }
.stock-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.stock-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.stock-sku { font-size: 10px; color: var(--text-dim); font-family: var(--font-mono); letter-spacing: 0.04em; }
.badge-warn {
  font-size: 10px; color: var(--neg);
  background: rgba(255, 90, 120, 0.1);
  border: 1px solid rgba(255, 90, 120, 0.3);
  padding: 3px 8px; border-radius: 4px;
  letter-spacing: 0.04em;
  animation: pulse 1.6s infinite;
}
.stock-qty {
  display: flex; align-items: baseline; gap: 6px;
  margin-top: 4px;
}
.stock-qty-num {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.stock-qty-unit { font-size: 12px; color: var(--text-muted); }
.stock-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 3px;
  position: relative;
  overflow: visible;
}
.stock-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 3px;
  transition: width 700ms cubic-bezier(.2,.7,.3,1);
  box-shadow: 0 0 12px currentColor;
}
.stock-bar-mark {
  position: absolute; top: -3px; bottom: -3px;
  width: 1px;
  background: rgba(255, 90, 120, 0.5);
}
.stock-bar-mark::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 3px solid transparent; border-right: 3px solid transparent;
  border-top: 4px solid rgba(255, 90, 120, 0.5);
}
.stock-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.stock-meta > div {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11.5px;
}
.stock-meta > div > span:first-child { color: var(--text-muted); }
.stock-meta > div > span:last-child { font-family: var(--font-mono); }
.stock-flow {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.flow-stat {
  display: flex; gap: 8px; align-items: center;
  font-size: 12px;
}
.flow-stat > svg { color: var(--text-dim); }

.stock-move-panel { display: flex; flex-direction: column; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 4px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  text-align: left;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}
.data-table tbody tr:hover {
  background: rgba(255, 181, 71, 0.03);
}
.tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}
.tag-in { color: var(--info); border-color: rgba(96, 165, 250, 0.3); background: rgba(96, 165, 250, 0.06); }
.tag-out { color: var(--accent); border-color: rgba(255, 181, 71, 0.3); background: rgba(255, 181, 71, 0.06); }

.empty {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 7, 12, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 200ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal {
  width: 520px; max-width: 100%;
  background: linear-gradient(180deg, rgba(20, 25, 38, 0.95), rgba(15, 19, 32, 0.95));
  border: 1px solid rgba(255, 181, 71, 0.18);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.03);
  display: flex; flex-direction: column;
  max-height: 90vh;
  animation: slideUp 250ms cubic-bezier(.2,.7,.3,1);
  overflow: hidden;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}
.field input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: all 150ms ease;
}
.field input:focus {
  border-color: rgba(255, 181, 71, 0.4);
  background: rgba(255, 181, 71, 0.03);
}
.field-row { display: flex; gap: 12px; }
.seg {
  display: flex; gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.seg-btn {
  --seg-color: var(--accent);
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-thai);
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms ease;
  display: flex; align-items: center; justify-content: center;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: rgba(255, 181, 71, 0.1);
  color: var(--seg-color);
  border-color: color-mix(in oklch, var(--seg-color) 30%, transparent);
  box-shadow: 0 0 12px color-mix(in oklch, var(--seg-color) 15%, transparent) inset;
}
.modal-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  background: rgba(255, 181, 71, 0.04);
  border: 1px dashed rgba(255, 181, 71, 0.3);
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
  font-size: 13px;
}
.detail-row > span:first-child { color: var(--text-muted); }
.detail-row.total { border-top: 1px solid var(--accent); border-bottom: none; margin-top: 8px; padding-top: 16px; }

/* ============================================================
   Footer
   ============================================================ */
.footer {
  display: flex; justify-content: space-between;
  padding: 16px 0;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ============================================================
   Loading splash
   ============================================================ */
.app-splash {
  position: fixed; inset: 0;
  background: var(--bg-0);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  transition: opacity 400ms ease;
}
.app-splash.fade { opacity: 0; pointer-events: none; }
.splash-mark {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-align: center;
}
.splash-mark > div:first-child {
  display: inline-block;
  width: 32px; height: 4px;
  background: linear-gradient(90deg, var(--accent), transparent);
  animation: load 1.2s infinite;
  margin-bottom: 14px;
}
@keyframes load {
  0% { transform: translateX(-30px); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateX(30px); opacity: 0; }
}
