/* ─────────────────────────────────────────────────────────────────────────
   Trader · design system v2
   Applied globally to every page (Dashboard, Alerts, Trade, Paper, Settings,
   Admin, Login). Page-specific HTML files keep their inline <style> blocks
   for niche components, but inherit the typography, colour palette, and
   reusable primitives below.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Surface */
  --bg:          #faf9f5;
  --surface:     #ffffff;
  --surface-2:   #f5f3ed;

  /* Lines */
  --border:      #e7e5e0;
  --border-soft: #efeee8;

  /* Text */
  --text:        #1a1815;
  --text-muted:  #57534e;
  --text-subtle: #a8a29e;

  /* Accent (kept as the burnt orange you've already been seeing) */
  --brand:       #cc785c;
  --brand-hover: #b56a4f;
  --brand-light: #fdf2ee;

  /* Status */
  --green:       #16794b;
  --green-bg:    #ecfdf5;
  --green-border:#a7f3d0;
  --red:         #b91c1c;
  --red-bg:      #fef2f2;
  --red-border:  #fecaca;
  --amber-bg:    #fef3c7;
  --amber-fg:    #92400e;

  /* Shape */
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;

  /* Shadows */
  --shadow-sm:   0 1px 2px rgba(20,16,11,.04);
  --shadow:      0 4px 16px rgba(20,16,11,.06);
  --shadow-lg:   0 12px 40px rgba(20,16,11,.12);

  /* Motion */
  --t-fast: .12s;
  --t:      .2s;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }

/* ── Top bar / header ───────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 249, 245, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
header h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}
header h1::before {
  content: '';
  display: inline-block;
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--brand) 0%, #d68a73 100%);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
}
header nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  margin-left: 6px;
}
header nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
header nav a:hover { background: rgba(20,16,11,.05); color: var(--text); }
header nav a.active { background: var(--text); color: var(--bg); }

/* ── Product badge (NRML / MIS) ──────────────────────────────────────────────
   Small chip on instrument rows stating the contract product at a glance. */
.product-badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 6px; border-radius: 4px;
  text-transform: uppercase; white-space: nowrap;
  border: 1px solid transparent;
}
.product-badge.nrml { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.product-badge.mis  { background: var(--amber-bg); color: var(--amber-fg); border-color: #fde68a; }

/* ── Market-move + high-impact-news alert banners ────────────────────────────
   Small dismissible cards pinned to the top-right, just below the nav. Built in
   common.js. position:FIXED (viewport-relative) so the stack follows the user
   down the page as they scroll — always visible until dismissed. z-index sits
   BELOW the header (50) so open nav dropdowns render over them. */
#market-alert-stack {
  position: fixed;
  right: 12px;
  z-index: 40;
  width: 236px;
  max-width: calc(100vw - 24px);
  display: none;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
#market-alert-stack .ma-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px 7px 11px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
#market-alert-stack .ma-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
}
#market-alert-stack .ma-dismiss-all,
#market-alert-stack .ma-x {
  border: none; background: transparent; cursor: pointer;
  line-height: 1; color: var(--text-subtle);
  padding: 3px 5px; border-radius: 4px;
  transition: background var(--t-fast), color var(--t-fast);
}
#market-alert-stack .ma-dismiss-all { font-size: 12px; }
#market-alert-stack .ma-x { font-size: 11px; }
#market-alert-stack .ma-dismiss-all:hover,
#market-alert-stack .ma-x:hover { background: rgba(20,16,11,.07); color: var(--text); }
#market-alert-stack .ma-list { display: flex; flex-direction: column; max-height: 62vh; overflow-y: auto; }
#market-alert-stack .ma-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 11px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12px;
}
#market-alert-stack .ma-item:last-child { border-bottom: none; }
#market-alert-stack .ma-item.up   { border-left: 3px solid var(--green); }
#market-alert-stack .ma-item.down { border-left: 3px solid var(--red); }
#market-alert-stack .ma-name {
  flex: 1; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#market-alert-stack .ma-pct {
  display: inline-flex; align-items: center; gap: 3px;
  font-weight: 700; font-variant-numeric: tabular-nums;
}
#market-alert-stack .ma-item.up   .ma-pct { color: var(--green); }
#market-alert-stack .ma-item.down .ma-pct { color: var(--red); }
#market-alert-stack .ma-arrow { font-size: 8px; }
/* News alerts — 📰 + headline (links out), sentiment-tinted left bar. */
#market-alert-stack .ma-item.news.flat { border-left: 3px solid var(--border); }
#market-alert-stack .ma-news-ic { flex: none; font-size: 12px; }
#market-alert-stack .ma-news-title {
  flex: 1; font-size: 11px; font-weight: 500; line-height: 1.35;
  color: var(--text); text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
#market-alert-stack .ma-news-title:hover { text-decoration: underline; }
/* Hairline between workflow groups (money pages | analysis | meta). */
header nav .nav-sep {
  width: 1px; height: 18px; flex: none;
  background: var(--border);
  margin: 0 8px;
}
header nav .nav-dropdown-trigger .caret {
  font-size: 10px; opacity: .55; margin-left: 1px;
  display: inline-block; transition: transform var(--t-fast);
}
header nav .nav-dropdown:hover .caret,
header nav .nav-dropdown.open .caret { transform: translateY(1px); }
header nav .who {
  font-size: 12px;
  color: var(--text-subtle);
  padding: 0 10px;
  margin-left: auto;   /* Push username + logout to the far right */
}
/* If .who is missing/empty on some pages, fall back to pushing logout itself. */
header nav button#logout { margin-left: auto; }
header nav .who + button#logout { margin-left: 0; }

/* ── Nav dropdown (hover) ─────────────────────────────────────────────────
   Used for Volume → Daily Picks / Bank Trend. Wraps trigger + menu so
   hovering anywhere on the dropdown keeps the menu open.
   z-index must be > main content (chart libs use up to 100). */
header { position: relative; z-index: 50; overflow: visible; }
header nav { overflow: visible; }
header nav .nav-dropdown {
  position: relative; display: inline-block;
}
header nav .nav-dropdown-menu {
  position: absolute; top: 100%; left: 0;
  display: none; flex-direction: column;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(20,16,11,0.08);
  padding: 4px;
  z-index: 1000;       /* Above charts and tab content */
  margin-top: 2px;
}
/* Hover opens on pointer devices; the `.open` class is the JS-driven path for
   touch screens (hover doesn't exist there, which used to make every page in
   this menu unreachable on a phone). We deliberately drop `:focus-within`
   because it kept the menu visible after a click during the page navigation,
   causing the items to briefly appear "crammed" into the nav while the next
   page rendered. */
header nav .nav-dropdown:hover > .nav-dropdown-menu,
header nav .nav-dropdown.open > .nav-dropdown-menu {
  display: flex;
}
header nav .nav-dropdown-menu a {
  display: block;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
}
header nav .nav-dropdown-menu a:hover {
  background: rgba(20,16,11,.05);
  color: var(--text);
}
header nav .nav-dropdown-menu a.active {
  background: var(--text);
  color: var(--bg);
}

/* ── Page layout ────────────────────────────────────────────────────────── */
main {
  max-width: 1280px;
  margin: 32px auto 80px;
  padding: 0 32px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
input[type=text],
input[type=password],
input[type=number],
input[type=email],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  margin-bottom: 14px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(204,120,92,.16);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--text);
  color: var(--bg);
  border: 1px solid transparent;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform .06s;
  letter-spacing: -0.005em;
}
button:hover { background: #2c2622; }
button:active { transform: scale(.985); }
button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-weight: 500;
}
button.secondary:hover { background: var(--surface-2); border-color: var(--border-soft); }
button.danger { background: var(--red); color: #fff; }
button.danger:hover { background: #991b1b; }
button.brand { background: var(--brand); color: #fff; }
button.brand:hover { background: var(--brand-hover); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead { border-bottom: 1px solid var(--border); }
th {
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-subtle);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── P&L colours ────────────────────────────────────────────────────────── */
.pos { color: var(--green); font-weight: 500; }
.neg { color: var(--red);   font-weight: 500; }

/* ── Stat row ───────────────────────────────────────────────────────────── */
.row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.row > * { flex: 1; min-width: 160px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-subtle);
  margin-bottom: 6px;
}
.stat .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Inline alerts (legacy `.error` / `.success` divs) ─────────────────── */
.error {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
}
.success {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: var(--green);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
}

/* ── Login page ─────────────────────────────────────────────────────────── */
.login-wrap {
  max-width: 400px;
  margin: 88px auto;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.login-wrap .logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--brand) 0%, #d68a73 100%);
  border-radius: 9px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.login-wrap h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.login-wrap .sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 26px;
}
.login-wrap button { width: 100%; padding: 11px; font-size: 14px; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge.ok    { background: var(--green-bg); color: var(--green); }
.badge.warn  { background: var(--amber-bg); color: var(--amber-fg); }
.badge.bad   { background: var(--red-bg);   color: var(--red);   }
.badge.buy     { background: var(--green-bg); color: var(--green); }
.badge.sell    { background: var(--red-bg);   color: var(--red);   }
.badge.filled  { background: var(--green-bg); color: var(--green); }
.badge.no_position { background: var(--amber-bg); color: var(--amber-fg); }
.badge.quote_fail  { background: var(--red-bg); color: var(--red); }
.badge.market_closed { background: var(--amber-bg); color: var(--amber-fg); }
.badge.auto    { background: #eff6ff; color: #1d4ed8; }
.badge.manual  { background: var(--surface-2); color: var(--text-muted); }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); font-size: 13px; }
.muted-sm { color: var(--text-subtle); font-size: 12px; }
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
code {
  font-family: ui-monospace, "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 3px 7px;
  border-radius: 5px;
  color: var(--text);
}
p.muted { padding: 12px 0; }

/* ── Toast notifications (global) ──────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 400;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 380px;
  pointer-events: auto;
  animation: toast-in .26s cubic-bezier(.2,.8,.2,1);
}
.toast.success { background: var(--green); color: #fff; }
.toast.error   { background: var(--red);   color: #fff; }
.toast.info    { background: var(--text);  color: var(--bg); }
.toast .ic { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toast.leaving { animation: toast-out .18s ease-in forwards; }
@keyframes toast-in  { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateY(12px); opacity: 0; } }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  header { padding: 0 16px; }
  header nav { gap: 0; overflow-x: auto; scrollbar-width: none; }
  header nav::-webkit-scrollbar { display: none; }
  header nav a { padding: 5px 9px; font-size: 12px; white-space: nowrap; }
  header nav .nav-sep { margin: 0 4px; }
  header nav .who { display: none; }
  main { padding: 0 16px; margin: 18px auto 60px; }
  .card { padding: 16px 16px; }
  .stat .value { font-size: 19px; }
}
