/* CalmWave — светло-голубая тема в духе Material You (M3) */
:root {
  --primary: #00629d;
  --on-primary: #ffffff;
  --primary-container: #cfe5ff;
  --on-primary-container: #001d33;
  --secondary-container: #d7e3f1;
  --on-secondary-container: #101d2a;
  --surface: #f6faff;
  --surface-1: #eef4fb;
  --surface-2: #e8f0f8;
  --surface-3: #e1ebf5;
  --on-surface: #181c20;
  --on-surface-variant: #41484f;
  --outline: #71787f;
  --outline-variant: #c1c7ce;
  --error: #ba1a1a;
  --error-container: #ffdad6;
  --ok: #1f9d55;
  --lag: #e0a000;
  --dead: #d3362e;
  --unknown: #a3acb5;
  --radius-xl: 28px;
  --radius-l: 20px;
  --radius-m: 14px;
  --font: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--on-surface);
  font: 400 15px/1.45 var(--font);
  min-height: 100vh;
}
h1, h2, h3 { font-weight: 500; margin: 0; }
.muted { color: var(--on-surface-variant); }
svg.i { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* ---------- App bar + tabs ---------- */
.appbar { position: sticky; top: 0; z-index: 10; background: var(--surface); }
.appbar-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 22px; font-weight: 500; color: var(--on-primary-container); }
.logo-bubble { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 24px; background: var(--primary-container); color: var(--primary); }
.logo-bubble.small { width: 40px; height: 40px; border-radius: 14px; }
.tabs { display: flex; max-width: 1200px; margin: 0 auto; padding: 0 8px; border-bottom: 1px solid var(--outline-variant); overflow-x: auto; scrollbar-width: none; }
.tab {
  position: relative; flex: 1 1 0; min-width: 96px; max-width: 260px; padding: 0 8px; height: 48px; border: 0; background: none;
  color: var(--on-surface-variant); font: 500 14px var(--font); cursor: pointer; border-radius: 16px 16px 0 0;
  transition: background .15s;
}
.tab:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.tab.active { color: var(--primary); }
.tab.active::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary); }

.view { max-width: 1200px; margin: 0 auto; padding: 16px 16px 140px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 20px;
  border-radius: 20px; border: 0; font: 500 14px var(--font); cursor: pointer; white-space: nowrap;
  transition: box-shadow .15s, background .15s, filter .15s;
}
.btn svg.i { width: 18px; height: 18px; margin-left: -4px; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.btn.outlined { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1px var(--outline); }
.btn.text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn.danger { background: var(--error-container); color: var(--error); }
.btn:hover:not(:disabled) { filter: brightness(.96); box-shadow: 0 1px 3px rgba(0, 40, 80, .2); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--on-surface-variant); cursor: pointer; transition: background .15s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.icon-btn.on { color: #e5a400; }
.icon-btn.sm { width: 36px; height: 36px; }
.fab {
  display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 18px;
  background: var(--primary); color: var(--on-primary); cursor: pointer; box-shadow: 0 2px 6px rgba(0, 60, 110, .3);
}
.fab:hover { filter: brightness(1.08); }

/* ---------- Toolbar / chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--on-surface-variant); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: thin; }
.chip {
  flex: none; height: 32px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--outline); background: transparent;
  color: var(--on-surface-variant); font: 500 13px var(--font); cursor: pointer;
}
.chip.active { background: var(--secondary-container); color: var(--on-secondary-container); border-color: transparent; }
.progress { flex: 1 1 160px; max-width: 260px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--primary); border-radius: 3px; transition: width .2s; }

/* ---------- Status dot ---------- */
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--unknown); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.lag { background: var(--lag); box-shadow: 0 0 0 3px color-mix(in srgb, var(--lag) 28%, transparent); }
.dot.dead { background: var(--dead); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dead) 25%, transparent); }
.dot.busy { background: var(--primary); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- Station cards ---------- */
.genre-block { margin-bottom: 24px; }
.genre-title { display: flex; align-items: baseline; gap: 10px; margin: 8px 4px 10px; font-size: 18px; font-weight: 500; color: var(--on-primary-container); }
.genre-title small { font-size: 13px; color: var(--on-surface-variant); font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 12px; border-radius: var(--radius-l);
  background: var(--surface-1); cursor: pointer; transition: background .15s, box-shadow .15s; min-width: 0;
}
.card:hover { background: var(--surface-2); box-shadow: 0 1px 4px rgba(0, 60, 110, .15); }
.card.playing { background: var(--primary-container); }
.cover {
  position: relative; display: grid; place-items: center; width: 52px; height: 52px; flex: none; border-radius: 16px; overflow: hidden;
  background: var(--secondary-container); color: var(--primary); font-weight: 500; font-size: 20px;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.card-body { flex: 1; min-width: 0; }
.card-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--on-surface-variant); white-space: nowrap; overflow: hidden; }
.card-meta .ms { font-variant-numeric: tabular-nums; }
.card-meta .sub { overflow: hidden; text-overflow: ellipsis; }

/* ---------- Manage list ---------- */
.list { background: var(--surface-1); border-radius: var(--radius-l); overflow: hidden; }
.row { display: grid; grid-template-columns: 24px 44px minmax(0, 1.2fr) minmax(0, 1.6fr) 130px auto; gap: 12px; align-items: center; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--outline-variant); }
.row:last-child { border-bottom: 0; }
.row.head { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; color: var(--on-surface-variant); background: var(--surface-2); padding-top: 12px; padding-bottom: 12px; }
.row .cover { width: 40px; height: 40px; border-radius: 12px; font-size: 16px; }
.row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .url { font-size: 13px; color: var(--on-surface-variant); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .genre { font-size: 13px; }
.row .ms-line { font-size: 13px; color: var(--on-surface-variant); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .actions { display: flex; }
.empty { text-align: center; padding: 56px 16px; color: var(--on-surface-variant); }
.empty h3 { color: var(--on-surface); margin-bottom: 8px; }
.empty .btn { margin-top: 16px; }

/* ---------- Player ---------- */
.player {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; width: min(720px, calc(100% - 24px));
  display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px; border-radius: var(--radius-xl);
  background: var(--surface-3); box-shadow: 0 4px 18px rgba(0, 50, 100, .25);
}
.player .cover { width: 56px; height: 56px; }
.player-info { flex: 1; min-width: 0; }
.player-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-status { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.volume { display: flex; align-items: center; gap: 6px; color: var(--on-surface-variant); }
.volume input { width: 100px; accent-color: var(--primary); }

/* ---------- Dialog / fields ---------- */
dialog {
  border: 0; border-radius: var(--radius-xl); padding: 24px; width: min(560px, calc(100% - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface-1); color: var(--on-surface); box-shadow: 0 8px 32px rgba(0, 40, 80, .3);
}
dialog::backdrop { background: rgba(10, 30, 50, .4); }
dialog h2 { font-size: 24px; margin-bottom: 16px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.field { position: relative; display: block; margin-bottom: 14px; }
.field input, .field select {
  width: 100%; height: 56px; padding: 22px 16px 6px; border-radius: 12px 12px 4px 4px; border: 0;
  border-bottom: 2px solid var(--outline); background: var(--surface-3); color: var(--on-surface); font: 400 16px var(--font);
}
.field input:focus, .field select:focus { outline: 0; border-bottom-color: var(--primary); }
.field span { position: absolute; left: 16px; top: 8px; font-size: 12px; color: var(--on-surface-variant); pointer-events: none; transition: all .15s; }
.field input:placeholder-shown:not(:focus) + span { top: 17px; font-size: 16px; }
.field input:focus + span { color: var(--primary); }
.error { color: var(--error); margin: 0 0 12px; font-size: 14px; }
.catalog-results { max-height: 46vh; overflow-y: auto; margin: 0 -8px; }
.catalog-item { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 14px; }
.catalog-item:hover { background: var(--surface-2); }
.catalog-item .card-body { min-width: 0; }
.search-row { display: flex; gap: 8px; }
.search-row .field { flex: 1; margin-bottom: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%); z-index: 40; max-width: min(520px, calc(100% - 24px));
  padding: 12px 20px; border-radius: 14px; background: #2d3135; color: #eef1f5; box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); text-align: center; padding: 32px 24px; border-radius: var(--radius-xl); background: var(--surface-1); }
.login-card h1 { font-size: 28px; margin: 16px 0 4px; }
.login-card p.muted { margin: 0 0 24px; }
.login-card .logo-bubble { margin: 0 auto; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; height: 48px; border-radius: 24px; font-size: 15px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .row { grid-template-columns: 20px 40px minmax(0, 1fr) auto; }
  .row .url, .row .genre, .row.head > :nth-child(n+4):not(:last-child) { display: none; }
  .row .name-wrap { grid-column: 3; }
  .volume input { width: 70px; }
  .brand { font-size: 20px; }
}
@media (max-width: 480px) {
  .volume { display: none; }
  .grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
