/* =========================================================
   BeatForge — styl interfejsu
   Spokojny, czysty, „apple": dużo powietrza, miękkie cienie,
   jeden akcent (indygo), pełny motyw jasny/ciemny przez zmienne.
   ========================================================= */

:root {
  --accent: #6c5ce7;
  --accent-soft: rgba(108, 92, 231, 0.16);
  --accent-glow: rgba(108, 92, 231, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --t: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- MOTYW CIEMNY (domyślny) ---- */
[data-theme="dark"] {
  --bg: #0d0d12;
  --bg-grad: radial-gradient(1200px 700px at 78% -8%, rgba(108,92,231,0.14), transparent 60%), #0d0d12;
  --surface: #16161e;
  --surface-2: #1d1d27;
  --surface-3: #25252f;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f2f7;
  --text-dim: #a0a0ac;
  --text-faint: #6b6b78;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --cell: rgba(255, 255, 255, 0.05);
  --cell-hover: rgba(255, 255, 255, 0.1);
}

/* ---- MOTYW JASNY ---- */
[data-theme="light"] {
  --bg: #f4f4f7;
  --bg-grad: radial-gradient(1200px 700px at 78% -8%, rgba(108,92,231,0.12), transparent 60%), #f4f4f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --surface-3: #f0f0f4;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #16161c;
  --text-dim: #5a5a66;
  --text-faint: #9a9aa6;
  --shadow: 0 18px 50px rgba(20, 20, 40, 0.12);
  --cell: rgba(20, 20, 40, 0.05);
  --cell-hover: rgba(20, 20, 40, 0.1);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-grad);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--t), color var(--t);
}

button, input, select { font-family: inherit; color: inherit; }
.hidden { display: none !important; }
svg { fill: currentColor; }

/* =========================================================
   PRZYCISKI
   ========================================================= */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--t), background var(--t), border-color var(--t), box-shadow var(--t);
}
.btn:hover { transform: translateY(-1px); background: var(--surface-3); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:hover { background: #5d4ce0; box-shadow: 0 8px 26px var(--accent-glow); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--cell); }
.btn-danger { color: #ff6b6b; }
.btn-danger:hover { background: rgba(255, 107, 107, 0.1); }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  transition: var(--t);
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); transform: translateY(-1px); }

.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 12px; padding: 0;
  transition: color var(--t);
}
.link-btn:hover { color: var(--accent); }

/* =========================================================
   MARKA
   ========================================================= */
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(140deg, #8b7cf6, #6c5ce7 55%, #4834c4);
  box-shadow: 0 4px 16px var(--accent-glow);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px 11px;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,0.95) 0 2px, transparent 2px 4px);
}
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.brand-sm .brand-mark { width: 24px; height: 24px; border-radius: 7px; }
.brand-sm .brand-name { font-size: 15px; }

/* =========================================================
   EKRAN LOGOWANIA
   ========================================================= */
.auth-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  animation: rise var(--t);
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.auth-card .brand { justify-content: center; margin-bottom: 28px; }
.auth-title { font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-dim); font-size: 14px; margin: 6px 0 26px; line-height: 1.5; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 7px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: var(--t);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--surface);
}
.auth-error { color: #ff6b6b; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* =========================================================
   UKŁAD APLIKACJI
   ========================================================= */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.project-name {
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 14px; font-weight: 600; color: var(--text); max-width: 200px;
  transition: var(--t);
}
.project-name:hover { background: var(--cell); }
.project-name:focus { outline: none; background: var(--surface-2); border-color: var(--border); }

/* Transport */
.transport { display: flex; align-items: center; gap: 18px; margin: 0 auto; }
.t-btn {
  display: grid; place-items: center;
  border: none; cursor: pointer; border-radius: 50%;
  transition: var(--t);
}
.t-play {
  width: 46px; height: 46px;
  background: var(--accent); color: #fff;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.t-play:hover { transform: scale(1.05); }
.t-play.playing { background: #ff6b6b; box-shadow: 0 6px 20px rgba(255,107,107,0.4); }
.t-btn svg path, .t-btn svg rect { fill: currentColor; }

.tempo { display: flex; align-items: center; gap: 6px; }
.tempo input {
  width: 58px; padding: 8px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
}
.tempo input:focus { outline: none; border-color: var(--accent); }
.tempo-unit { font-size: 11px; color: var(--text-faint); font-weight: 600; }

.swing { display: flex; align-items: center; gap: 9px; }
.swing-label { font-size: 12px; color: var(--text-faint); font-weight: 600; }

.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; margin-left: 4px; }
.user-chip #user-name { font-size: 13px; font-weight: 600; }

/* =========================================================
   SUWAKI (range) — jednolity, czysty wygląd
   ========================================================= */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px;
  background: var(--surface-3);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 1px solid var(--border-strong);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform var(--t);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 1px solid var(--border-strong);
}
.swing input[type="range"] { width: 90px; }

/* =========================================================
   PRZESTRZEŃ ROBOCZA
   ========================================================= */
.workspace {
  flex: 1; display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 16px; padding: 16px; overflow: hidden;
}
.sidebar, .inspector { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.panel-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin-bottom: 6px; }
.panel-hint { font-size: 12px; color: var(--text-faint); line-height: 1.5; margin-bottom: 14px; }

.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset {
  text-align: left; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  transition: var(--t);
}
.preset:hover { border-color: var(--accent); transform: translateX(2px); }
.preset-name { font-weight: 600; font-size: 14px; }
.preset-desc { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  transition: var(--t);
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* =========================================================
   SEKWENCER
   ========================================================= */
.sequencer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px; overflow: auto; position: relative;
}
.seq-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; position: sticky; top: 0; }
.seq-head-label { width: 132px; flex: none; font-size: 12px; font-weight: 600; color: var(--text-faint); }
.seq-bars { display: grid; grid-template-columns: repeat(16, 1fr); gap: 6px; flex: 1; }
.seq-bars span { text-align: center; font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.seq-bars span.beat-start { color: var(--text-dim); font-weight: 700; }

.tracks { display: flex; flex-direction: column; gap: 10px; }
.track { display: flex; align-items: center; gap: 12px; }
.track-label {
  width: 132px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); transition: var(--t);
}
.track-label:hover { border-color: var(--border-strong); }
.track-label.selected { border-color: var(--accent); background: var(--accent-soft); }
.track-label .t-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.steps { display: grid; grid-template-columns: repeat(16, 1fr); gap: 6px; flex: 1; }
.step {
  aspect-ratio: 1; min-height: 30px;
  background: var(--cell); border: 1px solid transparent;
  border-radius: 8px; cursor: pointer;
  transition: background 120ms, transform 120ms, box-shadow 120ms;
}
.step:hover { background: var(--cell-hover); }
.step.on { background: var(--track-color, var(--accent)); box-shadow: 0 2px 10px var(--track-glow, var(--accent-glow)); }
.step.beat-start { border-left: 1px solid var(--border-strong); }
.step.playhead { box-shadow: inset 0 0 0 2px var(--accent); }
.step.on.playhead { transform: scale(1.08); }

.seq-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-faint); font-size: 14px; pointer-events: none;
}

/* =========================================================
   INSPEKTOR
   ========================================================= */
.inspector-empty { color: var(--text-faint); font-size: 13px; line-height: 1.6; padding: 20px 4px; }
.inspector-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.slider-row, .select-row { display: block; margin-bottom: 16px; }
.slider-row span, .select-row span { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.slider-row input[type="range"] { width: 100%; }
.select-row select {
  width: 100%; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; cursor: pointer;
}
.select-row select:focus { outline: none; border-color: var(--accent); }
.insp-melodic { padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; }

/* =========================================================
   PASEK AKCJI (dół)
   ========================================================= */
.actionbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
.spacer { flex: 1; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; bottom: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; min-width: 200px;
}
.dropdown-menu button {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; background: none; border: none;
  border-radius: var(--radius-sm); font-size: 14px; cursor: pointer;
  transition: background var(--t);
}
.dropdown-menu button:hover { background: var(--cell); }

/* =========================================================
   MODALE
   ========================================================= */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade var(--t);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%; max-width: 460px; max-height: 84vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  animation: rise var(--t);
}
.modal-wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); }

.admin-section { margin-bottom: 26px; }
.admin-section:last-child { margin-bottom: 0; }
.admin-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.admin-section h3 { font-size: 15px; font-weight: 700; }

.invite-list, .admin-user-list, #library-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.invite-row, .user-row, .lib-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.invite-row .grow, .user-row .grow, .lib-row .grow { flex: 1; min-width: 0; }
.invite-link { font-size: 12px; color: var(--text-dim); word-break: break-all; font-family: ui-monospace, monospace; }
.invite-meta, .user-meta { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.tag-admin { background: var(--accent-soft); color: var(--accent); }
.tag-used { background: rgba(46,213,115,0.14); color: #2ed573; }
.tag-open { background: var(--cell); color: var(--text-dim); }
.row-name { font-size: 14px; font-weight: 600; }
.lib-row { cursor: pointer; transition: var(--t); }
.lib-row:hover { border-color: var(--accent); }

.empty-note { color: var(--text-faint); font-size: 13px; padding: 16px 0; text-align: center; }

/* =========================================================
   TOAST
   ========================================================= */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; transition: var(--t); z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================
   FOKUS / DOSTĘPNOŚĆ / RUCH
   ========================================================= */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* =========================================================
   RESPONSYWNOŚĆ
   ========================================================= */
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; overflow-y: auto; }
  .sidebar, .inspector { overflow: visible; }
  .transport { margin: 0; }
}
@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .transport { order: 3; width: 100%; justify-content: center; }
  .seq-head-label, .track-label { width: 92px; }
  .step { min-height: 24px; }
}
