:root {
  color-scheme: light dark;
  --bg: #f4f7f5;
  --panel: #ffffff;
  --panel-soft: #eef2f0;
  --text: #17201d;
  --muted: #65726d;
  --line: #d9e0dc;
  --accent: #2d7f68;
  --accent-soft: #e6f4ee;
  --accent-text: #ffffff;
  --warm: #9b6a34;
  --warm-soft: #f5ead9;
  --danger: #a84646;
  --shadow: 0 16px 40px rgba(23, 32, 29, 0.12);
}

body.dark {
  --bg: #101820;
  --panel: #182533;
  --panel-soft: #223243;
  --text: #f5f7f4;
  --muted: #9fb0bb;
  --line: #2d3d4f;
  --accent: #42a882;
  --accent-soft: #20392f;
  --accent-text: #07110d;
  --warm: #e5b66e;
  --warm-soft: #392f21;
  --danger: #ff8a8a;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Helvetica Neue", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 18px 14px 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 0 16px;
}

.top-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.lang-switch {
  display: flex;
  gap: 4px;
  min-height: 42px;
  border-radius: 8px;
  padding: 4px;
  background: var(--panel-soft);
}

.lang-switch button {
  appearance: none;
  min-width: 74px;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.lang-switch button.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 1px 5px rgba(45, 127, 104, 0.24);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
}

.summary,
.dialog-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.ghost-button,
.clear-button,
.close-button {
  appearance: none;
  min-width: 44px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.search-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.search-panel input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.clear-button[hidden] {
  display: none;
}

.search-panel input:focus {
  border-color: var(--accent);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab,
.chip,
.primary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.tab {
  padding: 10px 8px;
  font-weight: 700;
  line-height: 1.15;
}

.tab span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.tab.active,
.chip.active,
.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.tab.active span {
  color: var(--accent-text);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.toolbar-title,
.toolbar-note {
  margin: 0;
}

.toolbar-title {
  font-weight: 700;
}

.toolbar-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-actions {
  display: flex;
  gap: 6px;
}

.quick-actions button,
.secondary {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.quick-actions button.active,
.secondary.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.toolbar select {
  height: 40px;
  max-width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--text);
}

.performers-wrap {
  margin-bottom: 14px;
  overflow: hidden;
}

.performers {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.performers::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  padding: 0 12px;
  white-space: nowrap;
  scroll-snap-align: start;
}

.status {
  margin: 18px 0;
  color: var(--muted);
  text-align: center;
}

.audio-list {
  display: grid;
  gap: 12px;
}

.audio-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(23, 32, 29, 0.04);
}

.card-actions {
  display: grid;
  gap: 8px;
}

.audio-card:hover {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--line));
}

.audio-title {
  margin: 0 0 6px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.audio-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.audio-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

.badge.type {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.badge.time {
  background: var(--warm-soft);
  color: var(--warm);
}

.primary {
  min-width: 92px;
  padding: 0 14px;
  font-weight: 700;
}

.wide-primary {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  margin-bottom: 12px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 700;
}

.parts-dialog {
  width: min(calc(100% - 24px), 720px);
  max-height: 84vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.admin-dialog {
  width: min(calc(100vw - 24px), 1160px);
  height: min(calc(100vh - 24px), 780px);
  max-height: calc(100vh - 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.admin-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.44);
}

.admin-head {
  align-items: flex-start;
  min-height: 86px;
  margin: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.admin-workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  padding: 12px;
  background: color-mix(in srgb, var(--panel-soft) 52%, var(--panel));
}

.admin-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.admin-tabs button {
  display: grid;
  gap: 2px;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  line-height: 1.15;
  text-align: left;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 120ms ease;
}

.admin-tabs button:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 1px 8px rgba(23, 32, 29, 0.08);
}

.admin-tabs button:active {
  transform: translateY(1px);
}

.admin-tabs button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 2px;
}

.admin-tabs button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 9px rgba(45, 127, 104, 0.22);
}

.admin-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-tab-hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-tabs button.active .admin-tab-hint {
  color: var(--accent-text);
  opacity: 0.86;
}

.admin-body {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.admin-card,
.admin-form,
.admin-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.admin-card strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.system-log {
  max-width: 100%;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  text-decoration: none;
}

.admin-form {
  display: grid;
  gap: 8px;
}

.admin-form.soft,
.admin-row.soft {
  background: var(--panel-soft);
}

.admin-section-head {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.admin-section-head strong {
  font-size: 18px;
  line-height: 1.2;
}

.admin-section-head span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.admin-notice {
  display: grid;
  gap: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 8px;
  padding: 12px;
  background: var(--accent-soft);
}

.admin-notice strong {
  overflow-wrap: anywhere;
}

.admin-notice p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.admin-form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-form-grid .full {
  grid-column: 1 / -1;
}

.admin-form input,
.admin-form textarea,
.admin-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.admin-form input:focus,
.admin-form textarea:focus,
.admin-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 16%, transparent);
}

.admin-form textarea {
  min-height: 110px;
  resize: vertical;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.admin-row-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.admin-row-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.admin-filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(130px, 160px) minmax(150px, 170px) auto;
  gap: 8px;
}

.admin-detail {
  display: grid;
  gap: 8px;
}

.admin-inline-detail {
  display: grid;
  gap: 8px;
}

.admin-inline-detail:empty {
  display: none;
}

.order-tools {
  display: grid;
  gap: 8px;
}

.order-list {
  display: grid;
  gap: 8px;
}

.order-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  cursor: grab;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 120ms ease,
    opacity 160ms ease;
}

.order-item:active {
  cursor: grabbing;
}

.order-item.dragging {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(45, 127, 104, 0.18);
  opacity: 0.72;
}

.order-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.order-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.order-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.order-actions {
  display: flex;
  gap: 6px;
}

.order-actions button {
  min-width: 38px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.order-actions button:disabled {
  cursor: default;
  opacity: 0.42;
}

.admin-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.admin-detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.admin-detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.admin-detail-item strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.danger-button,
.admin-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 120ms ease;
}

.admin-action {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 60%, var(--line));
  color: var(--danger);
}

.danger-button:hover,
.admin-action:hover,
.secondary:hover,
.ghost-button:hover,
.clear-button:hover,
.close-button:hover {
  box-shadow: 0 1px 8px rgba(23, 32, 29, 0.1);
}

.danger-button:active,
.admin-action:active,
.secondary:active,
.ghost-button:active,
.clear-button:active,
.close-button:active {
  transform: translateY(1px);
}

.parts-dialog::backdrop {
  background: rgba(0, 0, 0, 0.44);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.parts-list {
  display: grid;
  gap: 8px;
}

.parts-search {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  padding: 0 12px;
  background: var(--panel-soft);
  color: var(--text);
  outline: none;
}

.parts-search:focus {
  border-color: var(--accent);
}

.part-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.part-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-meta {
  color: var(--muted);
  font-size: 12px;
}

.skeleton {
  min-height: 84px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--panel), var(--panel-soft), var(--panel));
  background-size: 220% 100%;
  animation: shimmer 1.1s infinite linear;
}

@keyframes shimmer {
  from {
    background-position: 220% 0;
  }
  to {
    background-position: -220% 0;
  }
}

@media (max-width: 860px) {
  .admin-dialog {
    width: min(calc(100vw - 14px), 760px);
    height: min(calc(100vh - 14px), 820px);
    max-height: calc(100vh - 14px);
  }

  .admin-workspace {
    grid-template-columns: 1fr;
    gap: 10px;
    overflow: auto;
  }

  .admin-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
    padding-right: 0;
  }

  .admin-tabs button {
    min-height: 44px;
    text-align: center;
  }

  .admin-tab-hint {
    display: none;
  }

  .admin-body {
    overflow: visible;
    padding-right: 0;
  }

  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-form-grid,
  .admin-form-grid.three,
  .admin-filter-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .admin-dialog {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .admin-head {
    padding: 12px;
  }

  .admin-workspace {
    padding: 10px;
  }

  .admin-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-detail-grid {
    grid-template-columns: 1fr;
  }

  .order-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .order-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .shell {
    padding-inline: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    justify-content: space-between;
  }

  .ghost-button {
    width: auto;
    color: var(--text);
    padding: 0 12px;
    position: static;
  }

  .ghost-button::after {
    content: none;
  }

  .tab {
    min-height: 52px;
    font-size: 13px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar select {
    max-width: none;
    width: 100%;
  }

  .audio-card {
    grid-template-columns: 1fr;
  }

  .primary {
    width: 100%;
  }

  .card-actions {
    grid-template-columns: 1fr 1fr;
  }

  .admin-filter-grid,
  .admin-detail-grid {
    grid-template-columns: 1fr;
  }
}
