:root {
  --bg: #0A0A0A;
  --surface: #121212;
  --surface-2: #1A1A1A;
  --surface-3: #222;
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.15);
  --text: #F4F4F4;
  --text-muted: #9A9A9A;
  --text-mute-2: #6E6E6E;
  --green: #00C47A;
  --green-soft: rgba(0,196,122,0.14);
  --red: #FF5A5A;
  --red-soft: rgba(255,90,90,0.14);
  --amber: #F5B400;
  --accent: #7C5CFF;
  --radius: 14px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* , *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--green); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ============ HEADER ============ */
.hdr {
  position: sticky; top: 0; z-index: 10;
  background: rgba(10,10,10,0.85);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.hdr__inner {
  max-width: 760px; margin: 0 auto;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.hdr__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hdr__logo {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--green);
  color: var(--bg);
  border-radius: 11px;
  font-size: 22px; font-weight: 700;
}
.hdr__text { min-width: 0; }
.hdr__title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.hdr__sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.hdr__refresh {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  transition: all 0.2s var(--ease);
}
.hdr__refresh:hover { background: var(--surface-3); }
.hdr__refresh:active { transform: scale(0.92); }
.hdr__refresh.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ NBK STRIP ============ */
.nbk {
  max-width: 760px; margin: 16px auto 0;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(124,92,255,0.14), rgba(0,196,122,0.06));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.nbk__label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.nbk__date { color: var(--text); font-weight: 500; text-transform: none; letter-spacing: 0; font-size: 12px; }
.nbk__list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 10px;
}
.nbk__item {
  display: flex; flex-direction: column; gap: 2px;
}
.nbk__cur {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--text-mute-2); letter-spacing: 0.08em;
}
.nbk__val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px; font-weight: 600; color: var(--text);
}

/* ============ TABS ============ */
.tabs {
  max-width: 760px; margin: 14px auto 0;
  padding: 0 16px;
  display: flex; gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s var(--ease);
  scroll-snap-align: start;
}
.tab.is-active {
  background: var(--green);
  border-color: var(--green);
  color: var(--bg);
}
.tab:active { transform: scale(0.96); }

/* ============ FILTERS ============ */
.filters { max-width: 760px; margin: 12px auto 0; padding: 0 16px; }
.filters__row { display: flex; gap: 8px; align-items: stretch; }
.filters__search {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: border-color 0.2s var(--ease);
}
.filters__search:focus-within { border-color: var(--green); color: var(--green); }
.filters__search input {
  flex: 1; min-width: 0;
  padding: 11px 0;
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px;
}
.filters__search input::placeholder { color: var(--text-mute-2); }

.filters__sort {
  padding: 11px 32px 11px 12px;
  background: var(--surface) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239A9A9A' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: var(--text);
  cursor: pointer;
  appearance: none; -webkit-appearance: none;
  max-width: 48%;
}

.filters__pills {
  margin-top: 10px;
  display: flex; gap: 6px;
}
.pill {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s var(--ease);
}
.pill.is-active { background: var(--surface-2); border-color: var(--line-strong); color: var(--text); }
.pill:active { transform: scale(0.96); }

/* ============ BEST SUMMARY ============ */
.best { max-width: 760px; margin: 16px auto 0; padding: 0 16px; }
.best__grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.best__card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 6px;
}
.best__card--buy { border-left: 3px solid var(--green); }
.best__card--sell { border-left: 3px solid var(--accent); }
.best__label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-muted);
}
.best__value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px; font-weight: 700;
  color: var(--text); line-height: 1;
}
.best__name { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.best__hint { font-size: 10px; color: var(--text-mute-2); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }

/* ============ LIST ============ */
.list { max-width: 760px; margin: 16px auto 0; padding: 0 16px 32px; display: flex; flex-direction: column; gap: 10px; }

.item {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid; grid-template-columns: 1fr auto;
  gap: 10px 14px; align-items: start;
  transition: border-color 0.2s var(--ease);
}
.item:active { border-color: var(--line-strong); }
.item--best { border-color: var(--green); box-shadow: 0 0 0 1px rgba(0,196,122,0.25); }

.item__head { min-width: 0; }
.item__name {
  font-size: 15px; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item__meta {
  font-size: 12px; color: var(--text-muted);
  margin-top: 3px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.item__type {
  font-size: 10px; padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.item__type--bank { background: rgba(124,92,255,0.18); color: var(--accent); }
.item__type--exchange { background: rgba(0,196,122,0.14); color: var(--green); }

.item__stale { font-size: 11px; color: var(--amber); }
.item__stale--fresh { color: var(--green); }

.item__rates {
  display: grid; grid-template-columns: auto auto;
  gap: 2px 14px;
  font-family: 'JetBrains Mono', monospace;
  text-align: right;
}
.item__rate-label { font-size: 10px; color: var(--text-mute-2); text-transform: uppercase; letter-spacing: 0.08em; align-self: end; }
.item__rate-val { font-size: 17px; font-weight: 600; }
.item__rate-val--buy { color: var(--green); }
.item__rate-val--sell { color: var(--accent); }
.item__rate-val--best { position: relative; }
.item__rate-val--best::after {
  content: '';
  position: absolute; left: -10px; top: 50%;
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor;
  transform: translateY(-50%);
  box-shadow: 0 0 8px currentColor;
}

.item__spread {
  grid-column: 1 / -1;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-muted);
}
.item__spread-val { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text); }
.item__address { font-size: 11px; color: var(--text-mute-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }

/* ============ SKELETON ============ */
.skeleton {
  height: 100px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ STATES ============ */
.empty, .error {
  max-width: 760px; margin: 40px auto; padding: 24px 16px;
  text-align: center; color: var(--text-muted);
  font-size: 14px;
}
.btn {
  margin-top: 12px;
  padding: 10px 18px;
  background: var(--green); color: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
}
.btn:active { transform: scale(0.97); }

/* ============ FOOTER ============ */
.ftr {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-muted);
  text-align: center;
}
.ftr p + p { margin-top: 4px; }
.ftr__mute { color: var(--text-mute-2); }
.ftr__updated { color: var(--text-mute-2); font-family: 'JetBrains Mono', monospace; font-size: 11px; margin-top: 8px; }

/* ============ DESKTOP ============ */
@media (min-width: 720px) {
  body { font-size: 16px; }
  .hdr__title { font-size: 19px; }
  .best__grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
  .best__card--buy, .best__card--sell { grid-column: auto; }
  .item { padding: 18px; }
  .item__rate-val { font-size: 19px; }
}
