:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --ink: #10233f;
  --muted: #5a6b80;
  --line: #d3dae2;
  --accent: #0b7a75;
  --accent-soft: #d5ece9;
  --near: #b86e00;
  --near-soft: #fbe9cc;
  --up: #16794a;
  --down: #b3261e;
  --down-soft: #f8dcd9;
  --focus: #2f6fd6;
  --shadow: 0 1px 0 rgba(16, 35, 63, 0.06);
  --radius: 10px;
  font-family: "Schibsted Grotesk", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1621;
    --surface: #152131;
    --surface-2: #1b293c;
    --ink: #e6edf5;
    --muted: #8fa1b6;
    --line: #26374d;
    --accent: #3cc3b5;
    --accent-soft: #163d40;
    --near: #f0a43a;
    --near-soft: #3d2e14;
    --up: #4cc38a;
    --down: #f2726b;
    --down-soft: #45201f;
    --focus: #79a8ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0 auto; max-width: 1240px; padding: 0 24px 40px; background: var(--bg); }
h1, h2 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 28px 0 18px; flex-wrap: wrap; }
.brand h1 { font-size: 2.1rem; line-height: 1; }
.brand p { margin: 6px 0 0; color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--up); }
.pill.warn::before { background: var(--near); }
.pill.bad::before { background: var(--down); }
.pill.live { background: var(--down-soft); border-color: var(--down); font-weight: 600; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--muted); filter: none; }
.btn.icon { padding: 6px 8px; display: inline-flex; }
.btn.danger { background: var(--surface); color: var(--down); border-color: var(--line); }
.btn.danger:hover { border-color: var(--down); }
.btn.warn-on { background: var(--near-soft); border-color: var(--near); color: var(--ink); font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: default; }
@media (prefers-color-scheme: dark) { .btn:not(.ghost):not(.danger):not(.warn-on) { color: #06201e; } }

.notice { margin: 0 0 14px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--near); background: var(--near-soft); }
.notice.bad { border-color: var(--down); background: var(--down-soft); }

/* totals */
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.4fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.totals > div { padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; }
.totals > div + div { border-left: 1px solid var(--line); }
.totals .k { color: var(--muted); font-size: 0.85rem; }
.totals .v { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.01em; }
.totals .v.small { font-size: 1rem; font-weight: 500; padding-top: 6px; }
.pos { color: var(--up); }
.neg { color: var(--down); }

/* search and add */
.add { position: relative; margin: 18px 0 26px; }
.search { display: flex; flex-direction: row; align-items: center; gap: 10px; font-size: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0; background: transparent; padding: 13px 0; outline: none; color: var(--ink); font-size: 1rem; }
.search kbd { font: inherit; font-size: 0.8rem; border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); list-style: none; margin: 0; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(16, 35, 63, 0.16); max-height: 420px; overflow: auto; }
.results li { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.results li[aria-selected="true"], .results li:hover { background: var(--surface-2); }
.results .nm { font-weight: 500; }
.results .cd { color: var(--muted); font-size: 0.85rem; }
.results .px { text-align: right; grid-row: span 2; align-self: center; font-size: 0.9rem; }
.results .px small { display: block; color: var(--muted); }
.results .empty { color: var(--muted); cursor: default; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.no { background: var(--down-soft); color: var(--down); }

.adder { margin-top: 10px; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 18px 20px; }
.adder h3 { margin: 0; font-size: 1.15rem; }
.adder .facts { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); font-size: 0.9rem; margin: 4px 0 14px; }
.adder .facts b { color: var(--ink); font-weight: 500; }
.add-form .form { margin-top: 4px; }
.form .wide { grid-column: 1 / -1; }
.form .wide select { max-width: 440px; }

/* forms */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 16px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label input, label select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font-size: 0.95rem; min-width: 0; }
label input:focus, label select:focus { border-color: var(--accent); outline: none; }
.unit { display: flex; align-items: center; gap: 6px; }
.unit input { flex: 1; }
.unit em { font-style: normal; color: var(--muted); min-width: 1.2em; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 10px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; max-width: 72ch; }
.error { color: var(--down); margin: 10px 0 0; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.row-start { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }

/* list */
.list-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 10px; }
.list-head h2 { font-size: 1.2rem; }
.list-head .sub { color: var(--muted); font-size: 0.9rem; }
.rules { display: flex; flex-direction: column; gap: 8px; }
.empty-list { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; color: var(--muted); }
.empty-list b { color: var(--ink); }

.rule {
  display: grid;
  grid-template-columns: minmax(200px, 1.25fr) minmax(220px, 1.35fr) minmax(250px, 1.25fr) minmax(140px, 0.75fr) 44px;
  grid-template-areas: "main track rule hold sw" "state state state state state" "detail detail detail detail detail";
  gap: 6px 22px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px 10px;
  box-shadow: var(--shadow);
}
.rule.off { background: var(--surface-2); }
.rule.off .track, .rule.off .r-price { opacity: 0.55; }
.rule.hot { border-color: var(--near); }
.rule.bought { border-color: var(--accent); }
.r-main { grid-area: main; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.r-name { all: unset; cursor: pointer; display: flex; flex-direction: column; min-width: 0; border-radius: 6px; }
.r-name:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.r-name .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-name:hover .name { text-decoration: underline; text-underline-offset: 3px; }
.r-name .ids { color: var(--muted); font-size: 0.82rem; }
.r-price { display: flex; gap: 8px; align-items: baseline; }
.r-price .price { font-size: 1.15rem; font-weight: 600; }
.r-price .chg { font-size: 0.85rem; }

/* the drop track: buy price on the left, reference on the right, the price as a dot */
.track { grid-area: track; display: flex; flex-direction: column; gap: 5px; }
.track .bar { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); }
.track .bar::before { content: ""; position: absolute; left: -1px; top: -5px; bottom: -5px; width: 3px; border-radius: 2px; background: var(--accent); }
.track .fill { position: absolute; top: 0; bottom: 0; right: 0; width: 0; border-radius: 0 5px 5px 0; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 35%, transparent)); transition: width 0.6s ease; }
.track .dot { position: absolute; top: 50%; right: 0; width: 14px; height: 14px; margin: -7px -7px 0 0; border-radius: 50%; background: var(--surface); border: 3px solid var(--ink); transition: right 0.6s ease; }
.rule.hot .track .fill { background: linear-gradient(90deg, var(--near), color-mix(in srgb, var(--near) 35%, transparent)); }
.rule.hot .track .dot { border-color: var(--near); }
.track .ends { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.track .ends .end-buy { color: var(--accent); font-weight: 600; }
.track .togo { color: var(--ink); font-weight: 500; }
.rule.hot .togo { color: var(--near); font-weight: 600; }

.r-rule { grid-area: rule; display: flex; flex-direction: column; gap: 3px; }
.sent { line-height: 2; display: flex; flex-wrap: wrap; column-gap: 0.4em; }
.sent .grp { white-space: nowrap; }
.inl { width: 3.4em; padding: 1px 4px; border: 1px solid transparent; border-bottom: 1px dashed var(--muted); border-radius: 5px; background: transparent; font-weight: 600; text-align: center; font-size: 1rem; }
.inl.amount { width: 4.6em; }
select.inl { width: auto; text-align: left; padding: 1px 0 1px 2px; margin-left: 2px; cursor: pointer; }
.inl:hover { border-color: var(--line); }
.inl:focus { border: 1px solid var(--accent); background: var(--surface); outline: none; }
.inl.saved { border-color: var(--up); }
.inl.bad { border-color: var(--down); }
.est { color: var(--muted); font-size: 0.82rem; }
.r-hold { grid-area: hold; display: flex; flex-direction: column; text-align: right; }
.hold-v { font-weight: 600; }
.hold-v.none { font-weight: 400; color: var(--muted); }
.hold-s { color: var(--muted); font-size: 0.82rem; }

.switch { grid-area: sw; position: relative; justify-self: end; width: 40px; height: 24px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 12px; background: var(--line); transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.r-state { grid-area: state; font-size: 0.82rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 7px; margin-top: 4px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.r-state .warn { color: var(--near); }
.r-state .bad { color: var(--down); }
.r-state .good { color: var(--accent); }

/* detail */
.r-detail { grid-area: detail; padding: 12px 0 8px; display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(260px, 1fr); gap: 20px; }
.chart-box { min-width: 0; }
.chart-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.chart-legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }
.chart { height: 300px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.chart-note { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.detail-side h4 { margin: 0 0 8px; font-size: 0.95rem; }
.detail-side .form { grid-template-columns: 1fr 1fr; }
.orders { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 18px; }
.orders th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 6px; }
.orders td { border-bottom: 1px solid var(--line); padding: 5px 6px; }
.orders td.r, .orders th.r { text-align: right; }
.st { font-size: 0.78rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.st.filled { background: var(--accent-soft); color: var(--accent); }
.st.rejected, .st.error, .st.cancelled { background: var(--down-soft); color: var(--down); }
.st.needs_action, .st.submitted { background: var(--near-soft); color: var(--near); }

/* activity */
.activity { margin-top: 30px; }
.events { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-height: 340px; overflow: auto; }
.events li { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: 0.9rem; }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); font-size: 0.85rem; }
.events li.buy { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.events li.warning span { color: var(--near); }
.events li.error span { color: var(--down); }
.events li.none { display: block; color: var(--muted); }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 0.82rem; margin-top: 22px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 22px 24px; width: min(620px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 20, 35, 0.45); }
dialog h2 { font-size: 1.25rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-top: 14px; }

@media (max-width: 1080px) {
  .rule { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; grid-template-areas: "main hold sw" "track track track" "rule rule rule" "state state state" "detail detail detail"; }
  .r-detail { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { padding: 0 16px 32px; }
  .brand h1 { font-size: 1.7rem; }
  .totals { grid-template-columns: 1fr 1fr; }
  .totals > div:nth-child(3) { border-left: 0; }
  .totals > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .totals .v { font-size: 1.3rem; }
  .rule { padding: 12px 14px 8px; gap: 8px 12px; grid-template-columns: minmax(0, 1fr) 44px; grid-template-areas: "main sw" "track track" "rule rule" "hold hold" "state state" "detail detail"; }
  .r-hold { text-align: left; flex-direction: row; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }
  .r-price { white-space: nowrap; }
  .events li { grid-template-columns: 1fr; gap: 0; }
  .grid2, .detail-side .form { grid-template-columns: 1fr; }
  .search kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
