:root {
  --bg: #07111e;
  --panel: #0c1a2b;
  --panel-2: #102238;
  --border: rgba(122, 161, 205, 0.18);
  --text: #e8f2ff;
  --muted: #8ca6c6;
  --up: #16d78a;
  --down: #ff5c7c;
  --neutral: #9db4cf;
  --accent: #54a6ff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Inter, Arial, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(62, 127, 255, 0.18), transparent 26%),
    radial-gradient(circle at top left, rgba(44, 197, 159, 0.14), transparent 24%),
    linear-gradient(180deg, #091320 0%, #050c15 100%);
  color: var(--text);
}
body { overflow: hidden; }
button { font: inherit; }

.app-shell {
  width: 100vw;
  height: 100vh;
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.topbar {
  min-height: 84px;
  background: linear-gradient(180deg, rgba(13, 29, 49, 0.96), rgba(9, 20, 35, 0.96));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}
.topbar__left, .topbar__right { display: flex; align-items: center; gap: 14px; }
.logo-badge {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.logo-badge img { width: 100%; height: 100%; object-fit: cover; }

.news-strip {
  min-width: 0; height: 52px; border-radius: 14px; border: 1px solid var(--border);
  background: rgba(12, 28, 47, 0.88); display: grid; grid-template-columns: auto 1fr;
  align-items: center; gap: 12px; padding: 0 14px; text-decoration: none; color: inherit; overflow: hidden;
}
.news-strip:hover { border-color: rgba(84, 166, 255, 0.4); }
.news-strip__label {
  white-space: nowrap; font-size: 12px; font-weight: 700; color: #9cc4ff; text-transform: uppercase; letter-spacing: 0.08em;
}
.news-strip__viewport { min-width: 0; overflow: hidden; position: relative; }
.news-strip__track { display: inline-block; white-space: nowrap; will-change: transform; padding-left: 100%; animation: ticker 40s linear infinite; color: #eef6ff; font-size: 13px; }

.status-box, .clock-box {
  min-height: 42px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: rgba(12, 28, 47, 0.82);
  display: flex; align-items: center; gap: 10px; font-size: 12px;
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--up); box-shadow: 0 0 12px rgba(22, 215, 138, 0.9); animation: pulse-live 1.4s infinite; }

.main-layout { min-height: 0; display: grid; grid-template-rows: auto 1fr; gap: 10px; }
.board-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: rgba(12, 28, 47, 0.7); border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px;
}
.board-toolbar__left, .board-toolbar__right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.board-toolbar__left span { color: var(--muted); font-size: 12px; }
.legend {
  padding: 6px 10px; border-radius: 999px; font-size: 11px; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.02);
}
.legend.up { color: var(--up); }
.legend.down { color: var(--down); }
.legend.neutral { color: var(--neutral); }

.period-switcher {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px;
  border-radius: 999px; background: rgba(8, 18, 31, 0.9); border: 1px solid var(--border);
}
.period-btn {
  min-width: 48px; height: 34px; border-radius: 999px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; transition: .2s ease;
}
.period-btn.is-active {
  background: rgba(84, 166, 255, 0.18); border-color: rgba(84, 166, 255, 0.3); color: #eef6ff;
}

.metals-grid {
  min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px; align-content: start; padding-right: 4px;
}
.metals-grid::-webkit-scrollbar { width: 10px; }
.metals-grid::-webkit-scrollbar-thumb { background: rgba(122, 161, 205, 0.28); border-radius: 999px; }

.metal-card {
  position: relative; background: linear-gradient(180deg, rgba(14, 28, 46, 0.98), rgba(9, 19, 32, 0.98));
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 10px 12px 10px; overflow: hidden; display: grid; grid-template-rows: auto auto 120px auto auto;
  gap: 8px; min-height: 258px; cursor: grab;
}
.metal-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent 22%); pointer-events: none; }
.metal-card.dragging { opacity: 0.45; transform: scale(0.98); }
.metal-card.drag-over { outline: 2px dashed rgba(84, 166, 255, 0.58); outline-offset: -6px; }
.metal-card.updating-up { animation: flash-up 0.7s ease; }
.metal-card.updating-down { animation: flash-down 0.7s ease; }

.metal-card__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metal-card__symbol {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; color: #d7ebff;
  background: rgba(84, 166, 255, 0.08); flex: 0 0 auto;
}
.metal-card__title { min-width: 0; flex: 1; }
.metal-card__title h3 { margin: 0; font-size: 15px; }
.metal-card__title p { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.atomic-badge {
  flex: 0 0 auto; padding: 6px 8px; border-radius: 999px; font-size: 11px; color: #b9d4f8;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08);
}

.metal-card__price-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.price-side { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.price-value { font-size: 28px; line-height: 1; font-weight: 700; letter-spacing: -0.03em; }
.price-currency { color: var(--muted); font-size: 12px; }
.trend-badge {
  min-width: 74px; padding: 8px 10px; text-align: center; border-radius: 999px; font-size: 12px; font-weight: 700;
  border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.03);
}
.trend-badge.up { color: var(--up); }
.trend-badge.down { color: var(--down); }
.trend-badge.flat { color: var(--neutral); }

.chart-wrap {
  position: relative; border-radius: 14px; overflow: hidden; background:
  linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.05);
}
.chart-wrap canvas { display: block; width: 100%; height: 120px; }

.metal-card__footer { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric-box {
  min-height: 54px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.06); background: rgba(255,255,255,0.03);
  padding: 8px 10px; display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.metric-box__label { font-size: 11px; color: var(--muted); }
.metric-box__value { font-size: 13px; font-weight: 700; }

.metal-card__source {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--muted);
}
.metal-card__source a { color: #8fc0ff; text-decoration: none; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metal-card__source a:hover { text-decoration: underline; }
.fetch-state { padding: 2px 8px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.08); }
.fetch-state.ok { color: var(--up); }
.fetch-state.wait { color: var(--neutral); }
.fetch-state.err { color: var(--down); }

@keyframes pulse-live {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
}
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@keyframes flash-up {
  0% { box-shadow: inset 0 0 0 1px rgba(22,215,138,0), 0 18px 48px rgba(0,0,0,0.32); }
  20% { box-shadow: inset 0 0 0 1px rgba(22,215,138,0.65), 0 18px 48px rgba(0,0,0,0.32), 0 0 25px rgba(22,215,138,0.2); }
  100% { box-shadow: inset 0 0 0 1px rgba(22,215,138,0), 0 18px 48px rgba(0,0,0,0.32); }
}
@keyframes flash-down {
  0% { box-shadow: inset 0 0 0 1px rgba(255,92,124,0), 0 18px 48px rgba(0,0,0,0.32); }
  20% { box-shadow: inset 0 0 0 1px rgba(255,92,124,0.65), 0 18px 48px rgba(0,0,0,0.32), 0 0 25px rgba(255,92,124,0.18); }
  100% { box-shadow: inset 0 0 0 1px rgba(255,92,124,0), 0 18px 48px rgba(0,0,0,0.32); }
}

@media (max-width: 1200px) {
  .topbar { grid-template-columns: 1fr; }
  .topbar__left, .topbar__right { justify-content: space-between; }
}
@media (max-width: 720px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; }
  .price-value { font-size: 23px; }
}
