/* ===== RESET / BASE ===== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #e5e7eb;
  color: #0f172a;
}

.page {
  max-width: 1120px;
  margin: 24px auto 40px;
  padding: 0 12px;
}

/* Utility */

.hidden {
  display: none !important;
}

/* ===== TOP BAR ===== */

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  background: #0f172a;
  color: #f9fafb;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.5);
}

.app-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.app-subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: #cbd5f5;
}

.top-bar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.credits-text {
  font-size: 0.9rem;
  color: #e5e7eb;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-email {
  font-size: 0.9rem;
  max-width: 180px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.debug-btn {
  padding-inline: 8px;
}

/* ===== BUTTONS ===== */

.btn {
  border-radius: 999px;
  border: none;
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    transform 0.05s ease;
  white-space: nowrap;
}

.btn:disabled {
  cursor: default;
  opacity: 0.6;
  box-shadow: none;
  transform: none;
}

.btn-primary {
  background: #2563eb;
  color: #f9fafb;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.5);
  border: 1px solid #1d4ed8;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.btn-outline {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid rgba(148, 163, 184, 0.7);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.15);
}

.btn-ghost {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.2);
}

.btn-large {
  padding: 8px 18px;
  font-size: 1rem;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

.upload-card .btn-outline,
.mixer-card .btn-outline {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #93c5fd;
  opacity: 1;
}

.upload-card .btn-outline:hover:not(:disabled),
.mixer-card .btn-outline:hover:not(:disabled) {
  background: #dbeafe;
  border-color: #60a5fa;
}

.upload-tabs {
  margin-top: 6px;
}

.upload-panes {
  margin-top: 8px;
}

.upload-pane {
  display: none;
}

.upload-pane.active {
  display: block;
}


/* ===== LAYOUT ===== */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr);
  gap: 16px;
  align-items: stretch;
}

.panel {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.1);
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.panel-history {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.history-inline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-inline-header h2 {
  margin: 0;
  font-size: 1rem;
}

.history-inline-body {
  margin-top: 6px;
}

.panel-section + .panel-section {
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
  margin-top: 2px;
}

/* ===== UPLOAD ===== */

.upload-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.upload-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.current-track-title {
  margin: 0;
  font-size: 0.95rem;
  color: #4b5563;
  word-break: break-word;
}

.file-drop {
  border-radius: 12px;
  border: 1px dashed #9ca3af;
  padding: 16px 14px;
  font-size: 0.9rem;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-align: center;
  background: #f9fafb;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.file-drop--hover {
  border-color: #2563eb;
  background: #eff6ff;
}

.file-input {
  display: none;
}

.file-drop-label {
  pointer-events: none;
}

.upload-youtube {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: #4b5563;
}

.upload-youtube-input {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.upload-youtube-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.upload-youtube-hint {
  font-size: 0.75rem;
  color: #6b7280;
}

.upload-btn {
  align-self: flex-start;
}

.status-text {
  min-height: 1.1em;
  font-size: 0.85rem;
  color: #374151;
}

.status-text--empty {
  opacity: 0.7;
}

/* ===== INFO CARD ===== */

.info-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.info-card p {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.info-card ul {
  margin: 0 0 0 1.1em;
  padding: 0;
  font-size: 0.9rem;
  color: #4b5563;
}

/* ===== PLAYER ===== */

.player-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-times {
  font-size: 0.9rem;
  color: #374151;
  min-width: 96px;
  text-align: right;
}

.time-separator {
  margin: 0 3px;
}

.timeline-wrapper {
  margin-top: 4px;
}

.timeline-bar {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.timeline-bar,
.waveform-wrapper {
  touch-action: pan-y;
}

.stem-volume-bars {
  touch-action: pan-y;
}

.timeline-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: linear-gradient(to right, #2563eb, #38bdf8);
}

/* ===== MIXER ===== */

.mixer-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 0;
}

.mixer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mixer-header h2 {
  margin: 0;
  font-size: 1rem;
}

.mixer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Master waveform */

.waveform-wrapper {
  position: relative;
  width: 100%;
  height: 80px;
  border-radius: 10px;
  overflow: hidden;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
}

#waveformProgress {
  width: 0;
}

.waveform-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.waveform-progress {
  height: 100%;
  width: 0;
  background: linear-gradient(
    to right,
    rgba(37, 99, 235, 0.2),
    rgba(56, 189, 248, 0.1)
  );
}

/* ===== STEMS ROWS ===== */

.stems-list {
  margin-top: 8px;
  max-height: none;
  overflow-y: auto;
}

.stem-row {
  padding: 6px 8px;
  border-radius: 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
}

.stem-wave-mini {
  width: 100%;
  height: 100%;
  display: block;
}

.stem-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

.stem-placeholder-line {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: #e5e7eb;
}

.stem-placeholder-controls {
  justify-self: end;
  width: 80px;
  height: 16px;
  border-radius: 999px;
  background: #e5e7eb;
  flex-shrink: 0;
}

.stem-wave-mini-placeholder {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #e5e7eb;
}

.stem-row--placeholder {
  opacity: 0.6;
  pointer-events: none;
}

.stem-row--placeholder .stem-toggle-btn {
  box-shadow: none;
}

/* Stem buttons */

.stem-toggle-btn {
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  padding: 3px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.stem-toggle-btn:hover {
  background: #e5e7eb;
}

.stem-toggle-btn.is-active {
  color: #f9fafb;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.stem-toggle-btn--mute.is-active {
  background: #b91c1c;
  border-color: #991b1b;
}

.stem-toggle-btn--solo.is-active {
  background: #f59e0b;
  border-color: #d97706;
}

/* Stem volume */

.stem-volume-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: auto;
}

.stem-volume-icon {
  width: 16px;
  height: 16px;
  background-image: url("volume.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
  opacity: 0.9;
}

.stem-volume-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  cursor: pointer;
  padding: 2px 0;
}

.stem-volume-bar {
  width: 3px;
  border-radius: 999px;
  background: #e5e7eb;
  height: 5px;
}

.stem-volume-bar:nth-child(1) {
  height: 5px;
}
.stem-volume-bar:nth-child(2) {
  height: 7px;
}
.stem-volume-bar:nth-child(3) {
  height: 9px;
}
.stem-volume-bar:nth-child(4) {
  height: 11px;
}
.stem-volume-bar:nth-child(5) {
  height: 13px;
}

.stem-volume-bar.is-active {
  background: #2563eb;
}

/* ===== STEMS TABLE ===== */

.stems-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
}

.stems-table td {
  padding: 6px 8px;
  background: #f9fafb;
  vertical-align: middle;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  border-left: none;
  border-right: none;
}

.stems-table td:first-child {
  border-left: 1px solid #e5e7eb;
  border-radius: 10px 0 0 10px;
}

.stems-table td:last-child {
  border-right: 1px solid #e5e7eb;
  border-radius: 0 10px 10px 0;
}

.stem-name-cell {
  white-space: nowrap;
  width: 1%;
}

.stem-wave-cell {
  width: auto;
}

.stem-controls-cell {
  white-space: nowrap;
  width: 1%;
}

.stem-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #111827;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stem-wave-mini-wrapper {
  position: relative;
  width: 100%;
  height: 32px;
  margin: 0 4px;
  overflow: hidden;
  background: transparent;
  align-self: center;
}

.stems-table tr.stem-row--placeholder td {
  opacity: 0.6;
}

/* ===== BANNER ===== */

.banner {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e0f2fe;
  color: #0f172a;
  border: 1px solid #7dd3fc;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.banner .btn-ghost {
  color: #0f172a;
  border-color: #7dd3fc;
}

.banner .btn-ghost:hover:not(:disabled) {
  background: rgba(125, 211, 252, 0.2);
}

.banner-bottom {
  margin-top: 10px;
}

/* ===== MODALS ===== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-dialog {
  position: relative;
  z-index: 41;
  background: #ffffff;
  border-radius: 12px;
  padding: 16px 18px 18px;
  max-width: 420px;
  width: calc(100% - 24px);
  max-height: 90vh;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-title {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.modal-close {
  position: absolute;
  right: 10px;
  top: 8px;
  border: none;
  background: transparent;
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  color: #4b5563;
}

/* Auth modal */

.auth-tabs {
  display: inline-flex;
  border-radius: 999px;
  background: #f3f4f6;
  padding: 2px;
  align-self: flex-start;
}

.auth-tab {
  border-radius: 999px;
  border: none;
  font-size: 0.85rem;
  padding: 4px 12px;
  cursor: pointer;
  background: transparent;
  color: #6b7280;
}

.auth-tab.active {
  background: #2563eb;
  color: #f9fafb;
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.auth-form.active {
  display: flex;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.field span {
  color: #4b5563;
}

.field input {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.field input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.auth-error {
  min-height: 1em;
  font-size: 0.8rem;
  color: #b91c1c;
}

/* History table */

.history-table-wrapper {
  margin-top: 6px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  flex: none;
  min-height: auto;
  max-height: none;
  overflow-y: visible;
  overflow-x: auto; 
  -webkit-overflow-scrolling: touch;
}

.history-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: max-content;
  min-width: 100%; 
}

.history-table thead {
  position: sticky;
  top: 0;
  background: #f3f4f6;
  z-index: 1;
}

.history-table th,
.history-table td {
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.history-table th:nth-child(1),
.history-table td:nth-child(1) {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-table tbody tr {
  cursor: pointer;
}

.history-table tbody tr:nth-child(odd) {
  background: #f9fafb;
}

.history-table tbody tr:nth-child(even) {
  background: #ffffff;
}

.history-table tbody tr:hover {
  background: #e5f2ff;
}

.history-row--current {
  outline: 1px solid #2563eb;
  outline-offset: -1px;
}

.history-row--active {
  box-shadow: inset 2px 0 0 #f59e0b;
}

.history-row--queued .history-status,
.history-row--processing .history-status {
  color: #f59e0b;
}

.history-row--done .history-status {
  color: #16a34a;
}

.history-row--error .history-status {
  color: #b91c1c;
}

.history-row--disabled {
  cursor: default;
  opacity: 0.6;
}

.history-row--disabled:hover {
  background: inherit;
}

.history-empty {
  text-align: center;
  padding: 10px 8px;
  font-size: 0.85rem;
  color: #6b7280;
}

/* Body scroll lock when modal is open */

body.modal-open {
  overflow: hidden;
}

#masterWaveform {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel-left {
    order: 1;
  }

  .panel-right {
    order: 2;
  }

  .panel-history {
    order: 3;
  }
}

@media (max-width: 600px) {
  .page {
    margin-top: 12px;
    padding: 0 8px;
  }

  .top-bar {
    padding: 12px 12px;
  }

  .panel {
    padding: 14px 14px 16px;
  }

  .timeline-bar {
    height: 12px;
  }

  .waveform-wrapper {
    height: 70px;
  }

  .stems-list {
    max-height: none;
  }

  .modal-dialog {
    width: calc(100% - 16px);
    max-width: none;
    height: auto;
    max-height: 92vh;
    margin: 0;
    border-radius: 12px;
  }
}
