:root {
  --bg-1: #f3f6ef;
  --bg-2: #efe8dc;
  --ink: #1f2b27;
  --muted: #55615d;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(31, 43, 39, 0.13);
  --accent: #136f63;
  --accent-2: #e97b3c;
  --ok: #2d8f49;
  --radius: 18px;
  --shadow: 0 18px 46px rgba(22, 37, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #ffffffcc 0 18%, transparent 48%),
    radial-gradient(circle at 85% 20%, #d6e9de 0 20%, transparent 50%),
    linear-gradient(120deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

.layout {
  width: min(1320px, 96vw);
  margin: 1.25rem auto;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(270px, 1fr) minmax(420px, 1.8fr) minmax(250px, 0.9fr);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  padding: 1rem;
}

.panel-header h1,
.panel-header h2,
.panel-header h3 {
  margin: 0;
}

.eyebrow {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.subtitle {
  margin: 0.65rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.92rem;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.status {
  font-family: "IBM Plex Mono", monospace;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  text-transform: lowercase;
  font-size: 0.75rem;
}

.stack {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
}

.grid {
  display: grid;
  gap: 0.75rem;
}

.grid.two {
  grid-template-columns: 1fr 1fr;
}

label,
fieldset {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.label-title-row {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.3rem;
  line-height: 1.2;
}

.th-with-info {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.info-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  padding: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  line-height: 1;
  cursor: pointer;
}

.info-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, 82vw);
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 0.76rem;
  line-height: 1.35;
  box-shadow: 0 10px 24px rgba(20, 35, 30, 0.14);
  z-index: 40;
  display: none;
  text-transform: none;
}

.info-popover::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: #fff;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.info-wrap:hover .info-popover,
.info-wrap:focus-within .info-popover {
  display: block;
}

legend {
  padding: 0 0.25rem;
}

input,
select,
textarea,
button {
  font-family: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in oklab, var(--accent), white 35%);
  outline-offset: 1px;
  border-color: color-mix(in oklab, var(--accent), white 45%);
}

.pill-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.pill input {
  width: auto;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: linear-gradient(120deg, var(--accent), #0f4f62);
  color: #fff;
}

.secondary {
  background: linear-gradient(120deg, #f5f3ec, #f5e7d8);
  border-color: var(--line);
}

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.danger {
  background: linear-gradient(120deg, #f7d9cf, #f5b4a8);
  border-color: color-mix(in oklab, #8a2814, white 52%);
  color: #5d1b0f;
}

.model-card {
  border: 1px dashed color-mix(in oklab, var(--accent), white 50%);
  background: color-mix(in oklab, #fff, var(--accent) 3%);
  border-radius: 12px;
  padding: 0.75rem;
  margin: 0.8rem 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.model-card details {
  margin-top: 0.25rem;
}

.model-card summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.79rem;
}

.model-card pre {
  margin: 0.35rem 0 0;
  padding: 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.73rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 31, 28, 0.32);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.loader-overlay.hidden {
  display: none;
}

.loader-card {
  width: min(460px, 92vw);
  border: 1px solid color-mix(in oklab, var(--accent), white 42%);
  border-radius: 16px;
  background: linear-gradient(160deg, #f8fffc, #eaf5ef);
  box-shadow: 0 18px 48px rgba(20, 35, 30, 0.2);
  padding: 1rem 1.1rem;
  display: grid;
  justify-items: center;
  gap: 0.45rem;
  text-align: center;
}

.loader-ring {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid color-mix(in oklab, var(--accent), white 64%);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}

.loader-title {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
}

.loader-phase {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--line);
}

th {
  background: color-mix(in oklab, #fff, var(--accent-2) 7%);
  position: sticky;
  top: 0;
  z-index: 1;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 1rem;
}

.actions {
  margin-top: 0.9rem;
}

.playlist-player-card,
.library-player-card {
  margin-top: 0.9rem;
}

.playlist-player-card audio,
.library-player-card audio {
  width: 100%;
}

.queue-list {
  margin: 0.3rem 0 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.35rem;
  max-height: 220px;
  overflow: auto;
}

.queue-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.45rem 0.55rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  text-align: left;
}

.queue-item.active {
  border-color: color-mix(in oklab, var(--accent), white 35%);
  background: color-mix(in oklab, #fff, var(--accent) 5%);
}

.small-btn {
  padding: 0.35rem 0.5rem;
  border-radius: 9px;
  font-size: 0.75rem;
}

.table-input,
.table-select {
  width: 100%;
  min-width: 110px;
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.78rem;
}

.manual-select-cell {
  min-width: 68px;
}

.manual-select-cell input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.listen-cell {
  min-width: 92px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #ffffffbe;
  display: grid;
  gap: 0.45rem;
}

.card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
}

.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inline input {
  width: auto;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.feedback-banner {
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid color-mix(in oklab, var(--accent), white 45%);
  background: color-mix(in oklab, #fff, var(--accent) 7%);
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.feedback-details {
  margin-top: 0.35rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  background: #fff;
}

.feedback-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.79rem;
}

.feedback-details pre {
  margin: 0.45rem 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.73rem;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-list {
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.history-list button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  padding: 0.55rem 0.6rem;
  display: grid;
  gap: 0.25rem;
}

.history-list .meta {
  font-size: 0.76rem;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.library-panel {
  grid-column: 1 / -1;
}

.library-controls {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: 1.8fr minmax(140px, 0.8fr);
  gap: 0.75rem;
}

.manual-builder-card {
  margin-top: 0.8rem;
}

.manual-builder-card .muted {
  align-self: end;
}

.library-wrap {
  max-height: 380px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    width: min(800px, 94vw);
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 360px;
  }

  .library-controls {
    grid-template-columns: 1fr;
  }
}
