/* us terminal — one stylesheet, two palettes.
 *
 * Every colour is a token. A hardcoded hex is a bug: it survives the theme
 * switch and shows up as one element still wearing the other theme.
 *
 * Dark is the default because this is a terminal and it is looked at for a
 * long time; light is available and is a real palette rather than an
 * inversion. */

:root {
  --bg:        #0b0e14;
  --bg-raised: #121722;
  --bg-hover:  #1a2130;
  --border:    #232b3b;
  --border-lt: #1a2130;

  --fg:        #e6e9ef;
  --fg-dim:    #9aa4b8;
  --fg-faint:  #5f6a80;

  --accent:    #4d9fff;
  --accent-dim:#1d4d8a;

  /* Up and down are the two colours this whole product is about. Green/red
   * is the convention every reader arrives with; the greens and reds are
   * pulled toward the blue accent so they sit in the same family. */
  --up:        #26c07f;
  --up-bg:     rgba(38, 192, 127, 0.12);
  --down:      #ff5f6d;
  --down-bg:   rgba(255, 95, 109, 0.12);
  --flat:      var(--fg-faint);

  --warn:      #f0b429;

  --radius:    8px;
  --radius-sm: 5px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg:        #f7f8fa;
  --bg-raised: #ffffff;
  --bg-hover:  #eef1f6;
  --border:    #d9dee8;
  --border-lt: #e8ecf2;

  --fg:        #131722;
  --fg-dim:    #5a6373;
  --fg-faint:  #8c95a6;

  --accent:    #0b63ce;
  --accent-dim:#bcd6f5;

  --up:        #0a8f5b;
  --up-bg:     rgba(10, 143, 91, 0.10);
  --down:      #d32f3f;
  --down-bg:   rgba(211, 47, 63, 0.10);

  --warn:      #a86b00;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- shell ---------------------------------------------------------- */

header.top {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  height: 52px;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
  font-size: 15px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 6px;
  vertical-align: 2px;
}

nav.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
nav.tabs a {
  color: var(--fg-dim);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  white-space: nowrap;
}
nav.tabs a:hover { background: var(--bg-hover); color: var(--fg); text-decoration: none; }
nav.tabs a.on { color: var(--fg); background: var(--bg-hover); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 5px 9px;
  font-size: 13px;
  font-family: var(--sans);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

main { max-width: 1500px; margin: 0 auto; padding: 20px 16px 64px; }

h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 14px; margin: 0 0 10px; color: var(--fg-dim); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.06em; }
.sub { color: var(--fg-dim); font-size: 13px; margin: 0 0 20px; }

/* ---- search --------------------------------------------------------- */

.search-wrap { position: relative; width: 260px; flex-shrink: 0; }
.search-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--sans);
}
.search-wrap input:focus { outline: none; border-color: var(--accent); }
.results {
  position: absolute;
  top: 110%;
  left: 0; right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 340px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.results.open { display: block; }
.results a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  color: var(--fg);
  border-bottom: 1px solid var(--border-lt);
}
.results a:last-child { border-bottom: 0; }
.results a:hover, .results a.sel { background: var(--bg-hover); text-decoration: none; }
.results .sym { font-family: var(--mono); font-weight: 600; }
.results .nm {
  color: var(--fg-dim); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- cards / grid --------------------------------------------------- */

.grid { display: grid; gap: 14px; }
.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.stat .label { color: var(--fg-dim); font-size: 11px; text-transform: uppercase;
               letter-spacing: 0.06em; margin-bottom: 3px; }
.stat .value { font-family: var(--mono); font-size: 19px; font-weight: 600; }
.stat .note  { color: var(--fg-faint); font-size: 11px; margin-top: 2px; }

/* ---- tables --------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border);
              border-radius: var(--radius); background: var(--bg-raised); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0;
                                 background: var(--bg-raised); }
tbody tr:hover td { background: var(--bg-hover); }
tbody tr:hover td:first-child { background: var(--bg-hover); }
thead th {
  color: var(--fg-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky; top: 0; z-index: 2;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--fg); }
thead th .arrow { color: var(--accent); margin-left: 3px; }
tbody td { border-bottom: 1px solid var(--border-lt); }
tbody tr:last-child td { border-bottom: 0; }

td.sym { font-family: var(--mono); font-weight: 600; }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.name { color: var(--fg-dim); max-width: 260px; overflow: hidden;
          text-overflow: ellipsis; text-align: left; }

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.pill.up   { background: var(--up-bg); }
.pill.down { background: var(--down-bg); }
.pill.flat { background: var(--bg-hover); }

/* ---- filters -------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
           margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--fg-dim); text-transform: uppercase;
               letter-spacing: 0.05em; }
.field input, .field select {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 13px;
  font-family: var(--mono);
  min-width: 92px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--fg-dim); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--fg); filter: none; }

/* ---- states --------------------------------------------------------- */

.muted { color: var(--fg-dim); }
.empty { padding: 36px; text-align: center; color: var(--fg-dim); }
.error { padding: 14px; border: 1px solid var(--down); background: var(--down-bg);
         border-radius: var(--radius); color: var(--fg); }
.skel { display: inline-block; height: 1em; width: 4em; border-radius: 3px;
        background: linear-gradient(90deg, var(--bg-hover), var(--border), var(--bg-hover));
        background-size: 200% 100%; animation: sh 1.2s linear infinite; }
@keyframes sh { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

.note {
  border-left: 2px solid var(--warn);
  padding: 8px 12px;
  background: var(--bg-raised);
  color: var(--fg-dim);
  font-size: 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 14px;
}

footer {
  border-top: 1px solid var(--border);
  color: var(--fg-faint);
  font-size: 12px;
  padding: 16px;
  text-align: center;
  margin-top: 40px;
}

/* ---- chart ---------------------------------------------------------- */

.chart-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
              margin-bottom: 10px; }
.range-btns { display: flex; gap: 3px; margin-left: auto; }
.range-btns button {
  background: transparent; border: 1px solid var(--border); color: var(--fg-dim);
  border-radius: var(--radius-sm); padding: 3px 9px; font-size: 12px; cursor: pointer;
  font-family: var(--mono);
}
.range-btns button:hover { background: var(--bg-hover); color: var(--fg); }
.range-btns button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
svg.chart { width: 100%; height: 300px; display: block; }
svg.chart .grid-line { stroke: var(--border-lt); stroke-width: 1; }
svg.chart .axis-label { fill: var(--fg-faint); font-size: 10px; font-family: var(--mono); }
svg.chart .price-line { fill: none; stroke: var(--accent); stroke-width: 1.5;
                        stroke-linejoin: round; stroke-linecap: round; }
svg.chart .price-area { fill: var(--accent); opacity: 0.07; }
svg.chart .ma-line { fill: none; stroke: var(--fg-faint); stroke-width: 1;
                     stroke-dasharray: 3 3; }
svg.chart .hover-line { stroke: var(--fg-faint); stroke-width: 1; }
svg.chart .hover-dot { fill: var(--accent); }

.legend { display: flex; gap: 14px; font-size: 11px; color: var(--fg-dim);
          font-family: var(--mono); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 2px; vertical-align: middle;
            margin-right: 4px; }
.legend .l-price i { background: var(--accent); }
.legend .l-ma i { background: var(--fg-faint); }

/* ---- stock header --------------------------------------------------- */

.stock-head { display: flex; align-items: flex-start; gap: 18px; flex-wrap: wrap;
              margin-bottom: 18px; }
.stock-head .ticker { font-family: var(--mono); font-size: 26px; font-weight: 700;
                      letter-spacing: -0.02em; }
.stock-head .coname { color: var(--fg-dim); font-size: 14px; }
.stock-head .venue { font-family: var(--mono); font-size: 11px; color: var(--fg-faint);
                     border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; }
.px { text-align: right; margin-left: auto; }
.px .last { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.px .chg { font-family: var(--mono); font-size: 14px; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1px;
      background: var(--border-lt); border: 1px solid var(--border);
      border-radius: var(--radius); overflow: hidden; }
.kv > div { background: var(--bg-raised); padding: 9px 12px; }
.kv .k { color: var(--fg-dim); font-size: 11px; text-transform: uppercase;
         letter-spacing: 0.05em; }
.kv .v { font-family: var(--mono); font-size: 15px; font-weight: 600; margin-top: 2px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center;
         margin-top: 16px; color: var(--fg-dim); font-size: 13px; }

@media (max-width: 900px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .cols-3 { grid-template-columns: 1fr; }
  .search-wrap { width: 150px; }
  header.top { gap: 10px; }
  .brand .tag { display: none; }
}
@media (max-width: 620px) {
  .cols-4 { grid-template-columns: 1fr; }
  main { padding: 14px 10px 48px; }
  .px { margin-left: 0; text-align: left; }
}
