:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 14px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-glow: rgba(37, 99, 235, 0.09);
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-text: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-2: #06b6d4;
  --up: #15803d;
  --down: #dc2626;
  --up-soft: rgba(21, 128, 61, 0.1);
  --down-soft: rgba(220, 38, 38, 0.1);
  --sma50: #d97706;
  --sma200: #7c3aed;
  --warn-soft: #fff7ed;
  --warn-border: #fed7aa;
  --warn-text: #9a3412;
  --scrollbar: #cbd5e1;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px -18px rgba(15, 23, 42, 0.24);
  --shadow-strong: 0 30px 80px -24px rgba(15, 23, 42, 0.45);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d17;
  --bg-glow: rgba(37, 99, 235, 0.13);
  --panel: #0f172a;
  --panel-2: #0b1220;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1e293b;
  --border-strong: #334155;
  --accent: #3b82f6;
  --accent-text: #93c5fd;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-2: #22d3ee;
  --up: #4ade80;
  --down: #f87171;
  --up-soft: rgba(74, 222, 128, 0.12);
  --down-soft: rgba(248, 113, 113, 0.12);
  --sma50: #fbbf24;
  --sma200: #a78bfa;
  --warn-soft: #2a1a0c;
  --warn-border: #7c2d12;
  --warn-text: #fdba74;
  --scrollbar: #334155;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 14px 34px -20px rgba(0, 0, 0, 0.9);
  --shadow-strong: 0 30px 90px -20px rgba(0, 0, 0, 0.85);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1100px 650px at 8% -12%, var(--bg-glow), transparent 62%),
    radial-gradient(800px 500px at 100% 0%, rgba(6, 182, 212, 0.045), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  flex: 0 0 auto;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  margin-right: auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px -8px var(--accent);
  flex: 0 0 auto;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.2;
  font-weight: 680;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.brand p {
  margin: 1px 0 0;
  font-size: 10.5px;
  line-height: 1.25;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.brand p.ok::before,
.brand p.error::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: 1px;
  background: var(--up);
}

.brand p.error::before {
  background: var(--down);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.range-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}

.range-tabs::-webkit-scrollbar {
  display: none;
}

.range-tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 11.5px;
  font-weight: 620;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.range-tabs button:hover {
  color: var(--text);
}

.range-tabs button.active {
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.09);
}

[data-theme="dark"] .range-tabs button.active {
  background: #1e293b;
  box-shadow: none;
}

.grid-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.grid-picker-label {
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  color: var(--muted);
  margin-right: 2px;
}

.grid-picker select {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 12.5px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  padding: 2px 1px;
  cursor: pointer;
  text-align: center;
  border-radius: 5px;
}

.grid-picker select:hover {
  background: var(--panel-2);
}

.grid-picker select:focus-visible {
  outline-offset: 0;
}

.grid-times {
  color: var(--muted);
  font-size: 11px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 620;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
}

.icon-btn.square {
  width: 36px;
  padding: 0;
}

.icon-btn .count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-btn .count.warn {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
}

/* ----------------------------------------------------------------- banner */

.banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  font-size: 12px;
  line-height: 1.4;
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text);
}

.banner[hidden] {
  display: none;
}

.banner svg {
  flex: 0 0 auto;
}

.banner span {
  flex: 1;
  min-width: 0;
}

.banner-close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.banner-close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
}

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

.grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.grid {
  display: grid;
  gap: 10px;
  min-height: 100%;
  align-content: stretch;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  container-type: inline-size;
  container-name: tile;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tile-head {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 11px 2px;
  min-width: 0;
}

.tile-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.status-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
}

.status-dot.fresh {
  background: var(--up);
  opacity: 1;
}

.status-dot.delayed {
  background: #f59e0b;
  opacity: 1;
}

.status-dot.error {
  background: var(--down);
  opacity: 1;
}

.tile-name {
  min-width: 0;
  font-size: 12.5px;
  font-weight: 660;
  line-height: 1.25;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-remove {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, background 120ms ease, color 120ms ease;
}

.tile:hover .tile-remove,
.tile-remove:focus-visible {
  opacity: 1;
}

.tile-remove:hover {
  background: var(--down-soft);
  color: var(--down);
}

.tile-quote {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  line-height: 1.15;
}

.tile-price {
  font-size: clamp(16px, 1.35vw, 21px);
  font-weight: 730;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tile-change {
  font-size: 11px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tile-change.up {
  color: var(--up);
}

.tile-change.down {
  color: var(--down);
}

.tile-change.flat,
.tile-change.muted {
  color: var(--muted);
}

.tile-isin {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 550;
  letter-spacing: 0.025em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-performance {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 3px;
  padding-top: 4px;
}

.perf {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.1;
}

.perf-label {
  font-size: 8px;
  font-weight: 680;
  letter-spacing: 0.035em;
  color: var(--muted);
  text-transform: uppercase;
}

.perf-value {
  min-width: 0;
  font-size: 10px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.perf-value.up {
  color: var(--up);
}

.perf-value.down {
  color: var(--down);
}

.perf-value.flat,
.perf-value.muted {
  color: var(--muted);
}

.tile-ma {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-top: 2px;
  font-size: 8.5px;
  font-weight: 620;
  color: var(--muted);
}

.ma-key {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.ma-key::before {
  content: "";
  width: 9px;
  height: 2px;
  border-radius: 2px;
  background: var(--ma-color);
}

.ma-key.sma50 {
  --ma-color: var(--sma50);
}

.ma-key.sma200 {
  --ma-color: var(--sma200);
}

@container tile (max-width: 300px) {
  .tile-performance {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@container tile (max-width: 250px) {
  .tile-isin {
    display: none;
  }

  .perf-label {
    font-size: 8px;
  }

  .perf-value {
    font-size: 10px;
  }

  .tile-ma {
    gap: 7px;
    font-size: 8px;
  }
}

.tile-chart {
  position: relative;
  flex: 1;
  min-height: 0;
}

.chart-canvas {
  position: absolute;
  inset: 0;
}

.tile-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  background: var(--panel);
}

.tile-overlay[hidden] {
  display: none;
}

.tile-overlay .retry {
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 10.5px;
  font-weight: 620;
  cursor: pointer;
}

.tile-overlay .retry:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

.spinner {
  width: 19px;
  height: 19px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 620;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.empty-tile:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
}

.empty-tile .plus {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 19px;
  font-weight: 400;
  line-height: 1;
  opacity: 0.8;
}

/* ----------------------------------------------------------------- dialog */

.dialog {
  width: min(600px, calc(100vw - 24px));
  max-height: min(86vh, 820px);
  max-height: min(86dvh, 820px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-strong);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
}

.dialog::backdrop {
  background: rgba(3, 8, 18, 0.56);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.dialog-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 10px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.dialog-head p {
  margin: 4px 0 0;
  max-width: 430px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.dialog-head .close {
  margin-left: auto;
  font-size: 17px;
  font-weight: 400;
}

.add-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 18px 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field.isin-field {
  flex: 0 0 168px;
}

.field.label-field {
  flex: 1 1 auto;
}

.field label {
  font-size: 10px;
  font-weight: 680;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--muted);
}

.field label span {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  opacity: 0.8;
}

.field input {
  height: 38px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 680;
  cursor: pointer;
  transition: filter 120ms ease, opacity 120ms ease;
}

.primary:hover {
  filter: brightness(1.07);
}

.primary:disabled {
  opacity: 0.55;
  cursor: wait;
  filter: none;
}

.form-error {
  flex: 0 0 auto;
  margin: 4px 18px 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--down-soft);
  color: var(--down);
  font-size: 11.5px;
  line-height: 1.4;
}

.form-error[hidden] {
  display: none;
}

.dialog-subhead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px 5px;
  font-size: 10px;
  font-weight: 680;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--muted);
}

.dialog-subhead span:last-child {
  font-variant-numeric: tabular-nums;
}

.asset-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 12px 4px;
  list-style: none;
  overflow-y: auto;
}

.asset-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
}

.asset-row:last-child {
  border-bottom: 0;
}

.asset-order {
  flex: 0 0 20px;
  text-align: center;
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.asset-info {
  flex: 1 1 auto;
  min-width: 0;
}

.asset-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 620;
}

.asset-name > span:first-child {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-isin {
  font-size: 10px;
  letter-spacing: 0.025em;
  color: var(--muted);
}

.asset-badge {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.045em;
}

.asset-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 1px;
}

.mini-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.mini-btn:hover:not(:disabled) {
  border-color: var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.mini-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.mini-btn.danger:hover:not(:disabled) {
  border-color: transparent;
  background: var(--down-soft);
  color: var(--down);
}

.asset-list-empty {
  padding: 22px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.dialog-hint {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 18px 16px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ----------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.4;
  animation: toast-in 160ms ease-out;
}

.toast.error {
  border-left-color: var(--down);
}

.toast.success {
  border-left-color: var(--up);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* -------------------------------------------------------------- scrollbar */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background: var(--scrollbar);
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ----------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }

  .brand {
    min-width: 0;
    margin-right: 0;
  }

  .brand p {
    max-width: 150px;
  }

  .toolbar {
    width: 100%;
    gap: 6px;
  }

  .range-tabs {
    order: 1;
    flex: 1 1 100%;
  }

  .range-tabs button {
    flex: 0 0 auto;
    padding: 6px 7px;
    text-align: center;
  }

  .grid-picker {
    order: 2;
    height: 34px;
  }

  .icon-btn {
    height: 34px;
  }

  .icon-btn.square {
    width: 34px;
  }

  .grid-wrap {
    padding: 8px;
  }

  .grid {
    gap: 8px;
  }

  .add-form {
    flex-wrap: wrap;
    padding: 8px 14px 4px;
  }

  .field.isin-field {
    flex: 1 1 140px;
  }

  .field.label-field {
    flex: 1 1 150px;
  }

  .add-form .primary {
    flex: 1 1 100%;
  }

  .dialog-head,
  .dialog-subhead,
  .dialog-hint {
    padding-left: 14px;
    padding-right: 14px;
  }

  .form-error {
    margin-left: 14px;
    margin-right: 14px;
  }
}

@media (hover: none) {
  .tile-remove {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
