:root {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 5.5%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 7%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
  --gain: 142 71% 45%;
  --loss: 0 84% 60%;
  --brand: 47 95% 55%;
  --radius: 0.6rem;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

* { scrollbar-width: thin; scrollbar-color: hsl(var(--secondary)) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--secondary)); border-radius: 999px; border: 2px solid hsl(var(--background)); }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.45); }
::-webkit-scrollbar-corner { background: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
svg { width: 1em; height: 1em; }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: hsl(var(--muted-foreground)); font-size: 13px; }
.hidden { display: none !important; }

.header {
  position: sticky; top: 0; z-index: 50;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background) / 0.8);
  backdrop-filter: blur(12px);
}
.header__inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; flex: 1; }
.header__end { flex: 1; }
.brand__logo {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: hsl(var(--brand));
  color: hsl(240 10% 8%); font-size: 18px;
}
.brand__accent { color: hsl(var(--brand)); }

.tabs {
  display: flex; gap: 4px;
  background: hsl(var(--muted)); padding: 4px; border-radius: var(--radius);
}
.tab {
  border: none; background: transparent; color: hsl(var(--muted-foreground));
  font-size: 13px; font-weight: 500; padding: 7px 16px;
  border-radius: calc(var(--radius) - 0.2rem); transition: color .15s, background .15s;
}
.tab:hover { color: hsl(var(--foreground)); }
.tab--active {
  background: hsl(var(--background)); color: hsl(var(--foreground));
  box-shadow: 0 1px 2px hsl(0 0% 0% / 0.4);
}

.main { flex: 1; padding: 28px 20px 48px; }
.panel { display: none; animation: fade .25s ease; }
.panel--active { display: block; }
.panel > .card { margin-bottom: 18px; }
.panel > .card:last-child { margin-bottom: 0; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.panel__title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.panel__subtitle { color: hsl(var(--muted-foreground)); font-size: 13px; margin-top: 2px; }
.panel__head-meta { display: flex; align-items: center; gap: 10px; }

.card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); overflow: hidden;
}
.card--pad { padding: 20px; overflow: visible; }
.card__title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 500; line-height: 1;
  padding: 0 16px; height: 38px; border-radius: calc(var(--radius) - 0.15rem);
  border: 1px solid transparent; transition: background .15s, border-color .15s, opacity .15s, color .15s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(0.5px); }
.btn--primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn--primary:hover { background: hsl(var(--primary) / 0.9); }
.btn--outline { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.btn--outline:hover { background: hsl(var(--accent)); }
.btn--ghost { background: transparent; color: hsl(var(--muted-foreground)); }
.btn--ghost:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 12.5px; }
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 34px; }

.chip[data-active="true"] {
  background: hsl(var(--brand) / 0.15); color: hsl(var(--brand)); border: 1px solid hsl(var(--brand) / 0.3);
}
.chip[data-active="true"] svg { fill: hsl(var(--brand)); }

.input {
  width: 100%; height: 38px; padding: 0 12px;
  background: hsl(var(--background)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 0.15rem);
  font-size: 13px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / 0.12); }
.input--lg { height: 48px; font-size: 18px; font-weight: 600; font-family: var(--font-mono); }
.input[readonly] { background: hsl(var(--muted)); cursor: default; }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer; }

.input-wrap { position: relative; }
.input-wrap--search { flex: 1; min-width: 200px; }
.input-wrap__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: hsl(var(--muted-foreground)); pointer-events: none; }
.input-wrap--search .input { padding-left: 36px; }

.select-wrap { position: relative; }
.select-wrap__icon { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: hsl(var(--muted-foreground)); pointer-events: none; }

.combo { position: relative; }
.combo__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: hsl(var(--muted-foreground)); pointer-events: none; z-index: 1; }
.combo__input { padding-left: 36px; }
.combo__menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: hsl(var(--popover)); border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.1rem); box-shadow: 0 12px 32px hsl(0 0% 0% / 0.5);
  max-height: 296px; overflow-y: auto; padding: 4px; display: none;
}
.combo__menu--open { display: block; }
.combo__item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 10px; background: transparent; border: none;
  border-radius: calc(var(--radius) - 0.25rem); color: hsl(var(--foreground));
  text-align: left; font-size: 13px;
}
.combo__item:hover, .combo__item--active { background: hsl(var(--accent)); }
.combo__item-name { font-weight: 500; }
.combo__item-sym { margin-left: auto; color: hsl(var(--muted-foreground)); font-size: 12px; font-family: var(--font-mono); }
.combo__empty { padding: 14px; text-align: center; color: hsl(var(--muted-foreground)); font-size: 13px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar__filters { display: flex; gap: 8px; align-items: center; }
.toolbar .select { height: 38px; }

.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 13px 16px; text-align: left; }
.table th { white-space: nowrap; }
.table thead th {
  font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground)); border-bottom: 1px solid hsl(var(--border));
  position: sticky; top: 0; background: hsl(var(--card));
}
.table tbody tr { border-bottom: 1px solid hsl(var(--border)); transition: background .12s; }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: hsl(var(--accent) / 0.5); }
.table .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.th-fav { width: 40px; }

.coin { display: flex; align-items: center; gap: 11px; }
.coin__icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: hsl(var(--muted)); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: hsl(var(--muted-foreground)); overflow: hidden;
}
.coin__icon img { width: 100%; height: 100%; object-fit: cover; }
.coin__name { font-weight: 600; }
.coin__ticker { color: hsl(var(--muted-foreground)); font-size: 12px; }

.star { background: none; border: none; color: hsl(var(--muted-foreground)); padding: 4px; display: grid; place-items: center; border-radius: 6px; transition: color .15s, background .15s; }
.star svg { width: 17px; height: 17px; }
.star:hover { color: hsl(var(--brand)); background: hsl(var(--accent)); }
.star--active { color: hsl(var(--brand)); }
.star--active svg { fill: hsl(var(--brand)); }

.delta { font-weight: 600; white-space: nowrap; }
.delta--up { color: hsl(var(--gain)); }
.delta--down { color: hsl(var(--loss)); }

.flash-up { animation: flashUp .8s ease; }
.flash-down { animation: flashDown .8s ease; }
@keyframes flashUp { 0% { background: hsl(var(--gain) / 0.18); } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: hsl(var(--loss) / 0.18); } 100% { background: transparent; } }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
  font-family: var(--font-mono);
}
.badge--up { background: hsl(var(--gain) / 0.15); color: hsl(var(--gain)); }
.badge--down { background: hsl(var(--loss) / 0.15); color: hsl(var(--loss)); }

.state {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 40px 20px; color: hsl(var(--muted-foreground)); font-size: 13.5px; text-align: center;
}
.state svg { width: 20px; height: 20px; }
.state--error { color: hsl(var(--loss)); flex-wrap: wrap; }
.state__art { width: 40px !important; height: 40px !important; opacity: 0.4; }
.state:has(.state__art), #portfolioEmpty, #marketEmpty { flex-direction: column; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid hsl(var(--muted-foreground) / 0.3); border-top-color: hsl(var(--foreground));
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat__label { font-size: 12px; color: hsl(var(--muted-foreground)); }
.stat__value { font-size: 24px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -0.02em; }
.stat .badge { align-self: flex-start; margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 14px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--btn { justify-content: flex-end; }
.label { font-size: 12.5px; font-weight: 500; color: hsl(var(--foreground)); }

.converter { max-width: 640px; margin: 0 auto; }
.converter__row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.converter .input, .converter .select { height: 48px; }
.converter .select { font-size: 15px; }
.converter .input--lg { font-size: 18px; }
.converter__swap { display: flex; justify-content: center; padding: 14px 0; }
.converter__rate { text-align: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid hsl(var(--border)); }

.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-left: 3px solid hsl(var(--loss));
  padding: 12px 16px; border-radius: calc(var(--radius) - 0.1rem);
  font-size: 13px; box-shadow: 0 8px 24px hsl(0 0% 0% / 0.4);
  animation: toastIn .25s ease; max-width: 340px;
}
.toast svg { width: 16px; height: 16px; color: hsl(var(--loss)); flex-shrink: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.footer { border-top: 1px solid hsl(var(--border)); padding: 20px 0; margin-top: auto; }
.footer__inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; color: hsl(var(--muted-foreground)); }
.footer a { color: hsl(var(--brand)); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

@media (max-width: 860px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field--btn { grid-column: 1 / -1; }
  .field--btn .btn { width: 100%; }
}

@media (max-width: 680px) {
  .header__inner { flex-wrap: wrap; height: auto; padding: 10px 20px; gap: 10px; }
  .brand { flex: 0 0 auto; }
  .header__end { display: none; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .hide-sm { display: none; }
  .panel__title { font-size: 20px; }
  .converter__row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .table th, .table td { padding: 11px 10px; }
  .toast-stack { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}
