/* TTrader dashboard - dark theme, Lao-first typography.
   Hand-written rather than a CSS framework: no build step, no network needed at
   page load, and full control over the Lao font stack (Leelawadee UI ships with
   Windows and covers the script; MT5 itself confirmed that earlier).

   Palette follows the supplied design: a slate background, one card tone above
   it, a single blue accent on the section titles, and green/red reserved for
   money so a gain never competes with ordinary chrome. */

:root {
  --bg:        #0f172a;   /* page */
  --panel:     #1e293b;   /* card, one step above the page */
  --panel-2:   #24314a;   /* chips and inner blocks, one step above the card */
  --border:    #334155;   /* row dividers */
  --text:      #cbd5e1;   /* body copy */
  --strong:    #f8fafc;   /* headings and highlighted values */
  --muted:     #94a3b8;   /* labels */
  --accent:    #3b82f6;   /* the one non-semantic colour */
  --win:       #22c55e;
  --loss:      #ef4444;
  --warn:      #f59e0b;
  --buy:       #22c55e;
  --sell:      #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  /* "Noto Sans Lao" is listed first so it is picked up automatically wherever
     it is installed; Leelawadee UI is the one that actually ships with Windows
     and is therefore the real workhorse here. Both cover the script - a font
     that does not is worse than no font at all, because Lao marks stack and a
     missing glyph leaves a blank box. */
  font-family: "Noto Sans Lao", "Leelawadee UI", "Phetsarath OT",
               "Saysettha OT", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;           /* Lao stacks marks above and below the line */
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand-line { display: flex; align-items: baseline; gap: 8px; }

/* Developer credit, visible at the top of every page rather than only in the
   footer - a footer needs scrolling past every panel to reach. */
.byline {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 1px;
}
.byline strong { color: #c9d6e4; font-weight: 600; }
.byline a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
  padding: 4px 0;            /* keeps the phone number a >=24px tap target */
  display: inline-block;
}

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}
.dot.on  { background: var(--win); }
.dot.off { background: var(--loss); }

.topmeta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 13px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono  { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* --------------------------------------------------------------- layout */
main { padding: 18px 20px 40px; display: grid; gap: 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.25);
  /* Safety net: a table that is wider than the card scrolls inside it instead
     of pushing the whole page sideways. Without this, a viewport that sits
     between the card breakpoint and the table's natural width (observed at
     768px) gets an unscrollable overflowing page. */
  overflow-x: auto;
}

/* A blue bar on the left edge of the title. It is the only ornament on the
   page, and it separates panels at a glance without a second card border. */
.card h2 {
  margin: 0 0 12px;
  padding-left: 10px;
  border-left: 4px solid var(--accent);
  color: var(--strong);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.grid { display: grid; gap: 16px; }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.four  { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stats { margin-bottom: 16px; }

.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat strong {
  color: var(--strong);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; }

/* Label left, value right, one divider per row - what a reader expects from a
   key/value panel, and it needs no extra markup to get there. */
table.kv tr { border-bottom: 1px solid var(--border); }
table.kv tr:last-child { border-bottom: none; }

table.kv th {
  text-align: left;
  color: var(--muted);
  font-weight: 400;
  padding: 9px 12px 9px 0;
  white-space: nowrap;
  vertical-align: middle;
}

table.kv td {
  text-align: right;
  padding: 9px 0;
  vertical-align: middle;
  font-weight: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

/* Every value is highlighted, EXCEPT the ones that carry a meaning colour:
   a loss must stay red rather than being repainted white. (0,1,2) beats (0,1,0),
   so the :not() is load-bearing, not decoration. */
table.kv td:not(.win):not(.loss) { color: var(--strong); }

table.data th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.6);
  vertical-align: top;
}

table.data tbody tr:hover { background: rgba(59, 130, 246, 0.08); }
table.data.compact td, table.data.compact th { padding: 4px 8px; font-size: 13px; }

tr.flag { background: rgba(245, 158, 11, 0.08); }

/* Direction and money carry the colour AND the weight, so the sign still reads
   at a glance on a phone in daylight. */
.buy, .win  { color: var(--buy); font-weight: 600; }
.sell, .loss { color: var(--sell); font-weight: 600; }

/* Names from the design brief, kept as aliases so a template can say what it
   means instead of reusing the side colours for money. */
.text-highlight { color: var(--strong); font-weight: 600; }
.text-profit { color: var(--win); font-weight: 700; }
.text-loss   { color: var(--loss); font-weight: 700; }

/* --------------------------------------------------------------- pieces */
.decision {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.tag {
  background: var(--accent);
  color: #04121f;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 12px;
}

.reason {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.blocked {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: rgba(245, 158, 11, 0.10);
  border-left: 3px solid var(--warn);
  border-radius: 0 8px 8px 0;
}

.rhythm { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px; }
.rhythm .label { font-weight: 600; }

/* Total floating P/L, shown in the Open Positions heading. */
.pnl-total {
  margin-left: auto;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* The capital tier the risk sizing is currently using. */
.tier {
  margin: 0 0 14px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.banner {
  margin: 14px 20px 0;
  padding: 10px 14px;
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
}

.banner.warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.45);
}

.empty { color: var(--muted); margin: 6px 0; }

.note {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.note p { margin: 6px 0 10px; }
.note summary { cursor: pointer; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid currentColor;
}
.badge.warn { color: var(--warn); }

.impact { white-space: nowrap; font-size: 13px; }
.impact-high  { color: var(--loss); }
.impact-medium{ color: var(--warn); }

.headlines { margin: 12px 0 0; padding-left: 20px; color: var(--muted); }
.headlines li { margin-bottom: 6px; }

/* --------------------------------------------------------------- footer */
footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px 28px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

/* Developer credit - the one piece of chrome that is not about the data. */
.credit {
  line-height: 1.8;
  font-size: 13.5px;
}
.credit strong { color: var(--text); }
.credit a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
  padding: 3px 0;           /* keeps it tappable on a phone */
  display: inline-block;
}
.credit a:hover { color: #93c5fd; }

/* ---------------------------------------------------------------- mobile */
/* The panels are data-heavy: a positions row has 9 columns and a history row
   has 10. On a phone that is unreadable as a table, and horizontal scrolling
   inside a card is worse than not showing it at all - you lose which column
   belongs to which value. So below 760px each row becomes its own card and the
   column name moves next to the value via data-label (see the templates).
   Nothing is hidden: every field is still present, just stacked. */

@media (max-width: 760px) {
  html, body { font-size: 15px; -webkit-text-size-adjust: 100%; }

  .topbar {
    padding: 8px max(12px, env(safe-area-inset-left)) 8px max(12px, env(safe-area-inset-right));
    flex-wrap: wrap;
    gap: 4px 10px;
    position: static;          /* sticky chrome costs scarce vertical space */
  }
  .brand { font-size: 16px; }
  .byline { font-size: 12px; line-height: 1.4; }
  .topmeta { gap: 6px; font-size: 13px; }
  .pill { padding: 2px 10px; font-size: 12px; }

  main {
    padding: 12px max(12px, env(safe-area-inset-left))
             max(28px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    gap: 12px;
  }

  .card { padding: 12px; border-radius: 12px; }
  .card h2 { font-size: 16px; margin-bottom: 10px; }

  .banner { margin: 10px 12px 0; padding: 10px 12px; font-size: 14px; }

  /* one column, except the compact stat strip which fits two */
  .grid.two, .grid.four { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 8px 10px; }
  .stat strong { font-size: 17px; }

  .decision { gap: 6px 12px; font-size: 14px; margin-top: 12px; }
  .reason, .blocked { font-size: 14px; padding: 10px; }
  .rhythm { font-size: 14px; }

  /* the two-column news table stays a table - it is already narrow */
  table.data:not(.stack) td,
  table.data:not(.stack) th { padding: 6px 4px; }

  footer {
    padding: 12px max(12px, env(safe-area-inset-left))
             max(20px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    flex-direction: column;
    gap: 4px;
    font-size: 12.5px;
  }

  .note { padding: 10px; }
  details summary { padding: 6px 0; min-height: 24px; }
  .headlines { padding-left: 18px; }
}

/* Very small phones: the stat strip goes single column too. */
@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr; }
  #clock { font-size: 12px; }
}

/* ---------- wide tables become stacked cards ---------- */
/* A positions row has 9 columns and a history row has 10; together with the
   nowrap headers that needs about 780px before it fits. So the cut-off is 900,
   not 760: a small tablet in portrait (768px) has no room for the table and
   would otherwise overflow the page. The column name moves next to the value
   via data-label, so nothing is hidden. */
@media (max-width: 900px) {
  table.data.stack,
  table.data.stack tbody,
  table.data.stack tr,
  table.data.stack td { display: block; width: 100%; }

  table.data.stack thead { display: none; }   /* labels come from data-label */

  table.data.stack tr {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }
  table.data.stack tr:last-child { margin-bottom: 0; }
  table.data.stack tbody tr:hover { background: var(--panel-2); }
  table.data.stack tr.flag { background: rgba(245, 158, 11, 0.10); }

  table.data.stack td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 3px 0;
    border: 0;
    font-size: 14px;
    white-space: normal;
    text-align: right;
  }
  table.data.stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12.5px;
    text-align: left;
    flex: 1 1 auto;
  }

  /* the first cell is the card's title line */
  table.data.stack td:first-child {
    font-size: 16px;
    font-weight: 700;
    padding-bottom: 6px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  table.data.stack td:first-child::before { content: none; }
}
