:root {
  color-scheme: dark;
  --bg: #131415;
  --side: #191a1d;
  --panel: #1b1c1f;
  --raised: #26282d;
  --border: #33353b;
  --text: #f1f2f4;
  --muted: #a9adb7;
  --primary: #315baf;
  --primary-hover: #3b68c0;
  --accent: #bad1ff;
  --chart: #6a9bea;
  --radius: .55rem;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  display: grid;
  grid-template-columns: 14.25rem minmax(0, 1fr);
  color: var(--text);
  background: var(--bg);
}
body > aside {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100svh;
  overflow: auto;
  padding: 1.25rem 1rem;
  background: var(--side);
  border-right: 1px solid var(--border);
}
main {
  width: min(100%, 92rem);
  min-width: 0;
  margin-inline: auto;
  padding: clamp(1.25rem, 3vw, 3.25rem);
}
header {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2rem);
  padding: .3rem 0 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
#logo {
  width: clamp(3.4rem, 4.5vw, 4.25rem);
  height: auto;
  flex: none;
  border-radius: .7rem;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.45rem, 2.6vw, 2.25rem); letter-spacing: -.03em; }
h2 { font-size: 1.1rem; letter-spacing: -.02em; }
h3 { margin-block: .75rem .4rem; font-size: 1rem; }
p { margin-block: .65rem; }
#subtitle, .muted, .storage { color: var(--muted); }
#subtitle { margin: .45rem 0 0; }

.brand { display: flex; align-items: center; gap: .65rem; padding: .15rem .35rem 1rem; }
#symbol { width: 2.75rem; height: auto; border-radius: .45rem; }
.brand strong { margin-right: auto; font-size: 1.05rem; letter-spacing: .17em; }
#sidebar { display: grid; gap: 1.3rem; }
nav { display: grid; gap: .3rem; }
nav a {
  padding: .72rem .85rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  color: var(--muted);
  text-decoration: none;
  font-size: .89rem;
  font-weight: 600;
}
nav a:hover { background: var(--raised); color: var(--text); }
nav a[aria-current="page"] { color: #edf3ff; background: #252d3d; border-left: 2px solid #78a8fa; }
.shop {
  display: grid;
  gap: .65rem;
  padding: .85rem;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: var(--panel);
}
.shop .actions { gap: .35rem; }
.shop .actions button { flex: 1; padding-inline: .45rem; font-size: .76rem; }
#delete { color: #ffb5ba; }
#shop-form { padding-top: .35rem; }
#create { display: grid; gap: .55rem; margin-top: .65rem; }
.storage { margin: 0; padding: 1rem .35rem 0; border-top: 1px solid var(--border); font-size: .82rem; }
#sidebar > button { width: 100%; }
#sidebar > button + button { margin-top: -.9rem; }
#menu { display: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  min-height: 2.65rem;
  border: 1px solid #484a53;
  border-radius: .62rem;
  padding: .52rem .75rem;
  background: #17181b;
}
input, select { max-width: 100%; min-width: 0; }
button {
  border-color: transparent;
  background: var(--primary);
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--primary-hover); }
button:disabled { opacity: .5; cursor: default; }
.secondary { background: #25272c; border-color: #3a3c44; }
.secondary:hover:not(:disabled) { background: #31343a; border-color: #606470; }
:focus-visible { outline: 2px solid #aebaff; outline-offset: 3px; }
.skip { position: fixed; left: -100vw; }
.skip:focus { left: 1rem; top: 1rem; z-index: 9; background: #fff; color: #191a1d; padding: .75rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
label, summary { font-size: .875rem; font-weight: 700; }
summary { cursor: pointer; }

.panel, .metric {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.panel { padding: clamp(.9rem, 2vw, 1.35rem); margin-bottom: 1rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; margin-bottom: .85rem; }
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; }
.field { display: grid; gap: .35rem; min-width: 0; }
.field > label { color: #ced0d6; }
.quick { border-top: 1px solid var(--border); padding-top: .85rem; margin-top: 1rem; }
.quick button { min-height: 2.2rem; border-radius: .38rem; font-size: .79rem; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .8rem;
  margin-bottom: 1rem;
}
.metric {
  padding: clamp(.75rem, 1.5vw, 1.2rem);
  background: var(--panel);
  border-left: 3px solid #6a9bea;
}
.metric:nth-child(even) { border-left-color: #c76d71; }
.metric span { color: #bdc1cb; font-size: .84rem; font-weight: 650; }
.metric strong {
  display: block;
  margin: .38rem 0 .32rem;
  color: var(--text);
  font-size: clamp(1.19rem, 2.6vw, 2rem);
  line-height: 1.15;
  letter-spacing: -.035em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.metric small { color: var(--muted); font-size: .75rem; }
.metric .up { color: #ffabb3; }
.metric .down { color: #91e3b8; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }

.table-wrap, .chart-scroll { overflow: auto; scrollbar-color: #555960 #202124; }
.table-wrap { max-height: 29rem; border: 1px solid var(--border); border-radius: .7rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }
th, td { padding: .7rem .85rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #26282c; color: #d6d8de; font-size: .78rem; }
tbody tr:nth-child(even) { background: #202124; }
tbody tr:hover { background: #292d35; }
tbody tr:last-child td, tfoot tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sort { min-height: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: inherit; cursor: pointer; }
.sort:hover:not(:disabled) { background: none; color: #fff; text-decoration: underline; }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; background: #26282c; }
.matrix th:first-child { z-index: 2; }
.matrix tfoot { background: #26282c; font-weight: 750; }
.link { background: none; border: 0; color: #b6d2ff; padding: 0; min-height: 1.5rem; text-align: left; }
.link:hover:not(:disabled) { background: none; color: #fff; text-decoration: underline; }
.chart-scroll svg { width: 100%; min-width: 37rem; display: block; }
.chart-grid { stroke: #383b43; }
.chart-bar { fill: var(--chart); }
.chart-hit { fill: transparent; }
.chart-hit:focus, .chart-hit:hover { fill: #ffffff22; }
.chart-label { fill: #bfc3cd; font: 12px system-ui; }
.drop {
  display: grid;
  justify-items: center;
  gap: .75rem;
  padding: clamp(1.5rem, 5vw, 3.75rem) 1rem;
  border: 1px dashed #555d6b;
  border-radius: .85rem;
  text-align: center;
  background: #202227;
}
.drop.active { background: #272f3e; border-color: #a2c3ff; }
.drop p { margin: 0; }
progress { width: 100%; accent-color: var(--chart); }
#notice { padding: .75rem 1rem; border: 1px solid #3e755d; border-radius: .7rem; background: #142b23; }
#notice.error { background: #371f2a; border-color: #86505e; }
.error { color: #ffc0c7; }
dialog {
  width: min(65rem, calc(100% - 2rem));
  max-height: 90vh;
  padding: clamp(1rem, 2.5vw, 1.6rem);
  border: 1px solid #4b5574;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1.4rem 5rem #0009;
}
dialog::backdrop { background: #060711b8; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: 1rem; }
dialog form { display: grid; gap: .75rem; }

body:has(.login:not([hidden])) { display: block; }
body:has(.login:not([hidden])) > aside { position: absolute; left: 0; top: 0; height: auto; padding: 1rem 1.4rem; border: 0; background: transparent; }
body:has(.login:not([hidden])) > aside .brand { padding: 0; }
body:has(.login:not([hidden])) #menu { display: none; }
body:has(.login:not([hidden])) main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(100%, 33rem);
  min-height: 100svh;
  padding: 5rem 1rem 2rem;
}
body:has(.login:not([hidden])) header {
  display: grid;
  justify-items: center;
  gap: .6rem;
  padding: 0;
  margin-bottom: 1.2rem;
  border: 0;
  background: transparent;
  text-align: center;
}
body:has(.login:not([hidden])) #logo { width: 5.4rem; }
body:has(.login:not([hidden])) h1 { font-size: clamp(1.85rem, 7vw, 2.75rem); }
.login { display: grid; gap: .6rem; width: min(100%, 28rem); margin: 0 auto; padding: clamp(1.15rem, 5vw, 1.75rem);  }
.login button { margin-top: .55rem; }
.login p:empty { display: none; }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
@media (max-width: 740px) {
  body { display: block; }
  body > aside { position: static; height: auto; padding: .65rem 1rem; border: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; }
  #symbol { width: 2.3rem; }
  #menu { display: inline-flex; align-items: center; background: var(--raised); border-color: var(--border); }
  #sidebar { padding-block: .9rem .25rem; }
  #sidebar:not(.open) { display: none; }
  main { padding: 1rem; }
  header { gap: .8rem; margin-bottom: 1rem; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 360px) {
  .filters { grid-template-columns: minmax(0, 1fr); }
  .metrics { gap: .5rem; }
}
@media print {
  :root { color-scheme: light; --text: #111; --muted: #333; --panel: white; --border: #aaa; }
  body { display: block; background: white; }
  main { padding: 0; max-width: none; }
  body > aside, button, .skip, #notice, .quick, dialog { display: none !important; }
  header, .metric { background: white; }
  .metric span, .metric .up, .metric .down, .field > label { color: #333; }
  input, select { color: #111; background: white; }
  .table-wrap, .chart-scroll { max-height: none; overflow: visible; }
  table { font-size: 9pt; }
  th, td { position: static !important; background: white !important; color: #111; white-space: normal; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .chart-scroll svg { min-width: 0; }
  .chart-label { fill: #222; }
  .metric, tr { break-inside: avoid; }
  thead { display: table-header-group; }
  button.link, button.sort { display: inline !important; color: #111; padding: 0; min-height: 0; }
}

/* Assistente IA */
textarea { width: 100%; resize: vertical; min-height: 4rem; }
.ia { display: grid; gap: 1rem; }
.ia-log { display: grid; align-content: start; gap: .75rem; min-height: 18rem; max-height: 60vh; overflow: auto; padding: .25rem; }
.ia-msg { max-width: min(100%, 52rem); padding: .7rem .95rem; border: 1px solid var(--border); border-radius: .7rem; overflow-wrap: anywhere; }
.ia-msg.me { justify-self: end; background: #252d3d; border-color: #3b4a6b; white-space: pre-wrap; }
.ia-msg.bot { justify-self: start; background: var(--raised); }
.ia-msg.error { background: #371f2a; border-color: #86505e; }
.ia-msg > div > :first-child { margin-top: 0; }
.ia-msg > div > :last-child { margin-bottom: 0; }
.ia-msg ul { margin: .5rem 0; padding-left: 1.25rem; }
.ia-msg .table-wrap { margin-block: .6rem; max-height: 20rem; }
.ia-form { display: grid; gap: .6rem; }
@media print { .ia-form { display: none; } .ia-log { max-height: none; } }
