:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0b0b0b;
  --surface-muted: #151515;
  --text: #f1f4f2;
  --muted: #9aa29d;
  --line: #282b29;
  --green: #1bb978;
  --green-dark: #129260;
  --green-soft: #0c2b1d;
  --coral: #ff756c;
  --coral-soft: #351614;
  --amber: #f4bd5a;
  --amber-soft: #382a10;
  --blue: #76baff;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.topbar {
  height: 52px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #000;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand, .login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--green);
  color: #fff;
  border-radius: 7px;
  font-size: 12px;
}
.brand-mark-large { width: 48px; height: 48px; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions form { margin: 0; }
.admin-name { color: var(--muted); font-size: 14px; }

.main { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 20px 0 56px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.page-heading h1 { margin: 0; font-size: 25px; line-height: 1.2; }
.page-heading p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.button, .icon-button, .text-button, .tab, .dialog-close {
  border: 0;
  cursor: pointer;
}
.button {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.button:disabled, .icon-button:disabled, .text-button:disabled { cursor: wait; opacity: .55; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.button-secondary:hover, .button-quiet:hover { background: var(--surface-muted); }
.button-quiet { background: transparent; color: var(--muted); }
.button-block { width: 100%; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { min-height: 72px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.stat > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.stat strong { display: block; font-size: 21px; line-height: 1.2; overflow-wrap: anywhere; }
.account-stat { position: relative; padding-right: 68px; }
.account-state { font-size: 16px !important; }
.account-state.is-valid { color: var(--green); }
.account-state.is-invalid { color: var(--coral); }
.text-button { background: transparent; color: var(--blue); padding: 4px; position: absolute; right: 12px; bottom: 10px; font-size: 12px; }

.work-section { padding: 15px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.task-form { display: grid; grid-template-columns: minmax(0, 1fr) 190px 128px; gap: 12px; align-items: end; }
.task-form label, .stack-form label { display: grid; gap: 5px; }
.task-form label > span, .stack-form label > span { font-size: 13px; font-weight: 650; }
input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #393d3a;
  border-radius: 6px;
  padding: 7px 11px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(27, 185, 120, .16); }
.submit-button { min-height: 38px; }

.content-tabs { display: flex; gap: 4px; margin: 28px 0 14px; border-bottom: 1px solid var(--line); }
.tab { background: transparent; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; font-weight: 650; }
.tab span { padding: 2px 7px; margin-left: 5px; background: var(--surface-muted); border-radius: 10px; font-size: 12px; }
.tab.is-active { color: var(--green); border-bottom-color: var(--green); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.audio-list { border-top: 1px solid var(--line); }
.audio-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 14px 8px; border-bottom: 1px solid var(--line); }
.audio-row:hover { background: rgba(255, 255, 255, .035); }
.cover-wrap { width: 64px; aspect-ratio: 16 / 10; border-radius: 5px; overflow: hidden; background: #171a18; display: grid; place-items: center; color: var(--green); font-size: 12px; font-weight: 750; }
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.audio-meta { min-width: 0; }
.audio-meta h3 { margin: 0 0 6px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta-line { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 7px; }
.icon-button { min-width: 42px; min-height: 36px; padding: 7px 10px; border-radius: 5px; background: var(--surface); border: 1px solid var(--line); color: var(--text); font-size: 13px; display: inline-grid; place-items: center; }
.icon-button:hover { border-color: #5c645f; }
.icon-button.danger { color: var(--coral); }
.icon-button.danger:hover { background: var(--coral-soft); border-color: #8c3c38; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; }
.task-table { border-collapse: collapse; width: 100%; min-width: 700px; }
.task-table th, .task-table td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.task-table tr:last-child td { border-bottom: 0; }
.task-table th { background: var(--surface-muted); color: var(--muted); font-size: 12px; }
.task-table td { font-size: 13px; }
.task-table td:first-child { max-width: 420px; }
.task-table td strong, .task-table td small { display: block; overflow-wrap: anywhere; }
.task-table td small { margin-top: 4px; color: var(--muted); }
.task-table .error-text { color: var(--coral); }
.status { display: inline-block; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 650; }
.status-queued { color: var(--amber); background: var(--amber-soft); }
.status-processing { color: var(--blue); background: #11283a; }
.status-completed { color: var(--green); background: var(--green-soft); }
.status-failed, .status-deleted { color: var(--coral); background: var(--coral-soft); }
.progress-cell { width: 150px; }
.progress-track { width: 100px; height: 5px; background: #2a2e2b; border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.progress-track span { display: block; height: 100%; background: var(--green); }
.progress-cell small { display: inline !important; }

.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state h1, .empty-state h2 { color: var(--text); margin: 0 0 7px; font-size: 19px; }
.empty-state p { margin: 0 0 18px; }

.auth-shell { background: #000; }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel, .install-panel { width: min(100%, 390px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 30px; box-shadow: var(--shadow); }
.install-panel { width: min(100%, 560px); }
.login-brand { margin-bottom: 26px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.login-brand p { color: var(--muted); margin: 2px 0 0; font-size: 13px; font-weight: 400; }
.stack-form { display: grid; gap: 17px; }
.alert { padding: 10px 12px; border-radius: 5px; font-size: 13px; margin-bottom: 18px; }
.alert-error { background: var(--coral-soft); color: #ff9b94; border: 1px solid #71312d; }

.qr-dialog { width: min(92vw, 390px); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 24px 80px rgba(0, 0, 0, .72); }
.qr-dialog::backdrop { background: rgba(0, 0, 0, .78); }
.dialog-header { height: 58px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 17px; }
.dialog-close { width: 34px; height: 34px; font-size: 25px; line-height: 1; color: var(--muted); background: transparent; border-radius: 4px; }
.dialog-close:hover { background: var(--surface-muted); }
.qr-stage { width: 320px; aspect-ratio: 1; margin: 22px auto 12px; background: #fff; display: grid; place-items: center; border: 1px solid var(--line); }
.qr-stage img, .qr-stage canvas { width: 100%; height: 100%; display: block; }
.qr-code { width: 280px; height: 280px; }
.qr-placeholder { color: var(--muted); font-size: 13px; }
.qr-status { min-height: 24px; margin: 0 20px 15px; text-align: center; color: var(--muted); font-size: 14px; }
.qr-dialog > .button { width: calc(100% - 40px); margin: 0 20px 20px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: min(360px, calc(100vw - 44px)); padding: 11px 15px; border-radius: 6px; background: #123724; color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #7d2a25; }

.requirement-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.requirement { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; }
.requirement strong { font-size: 12px; }
.requirement.is-ready strong { color: var(--green); }
.requirement.is-missing { background: var(--coral-soft); border-color: #71312d; }
.requirement.is-missing strong { color: var(--coral); }
.install-form { grid-template-columns: 1fr 1fr; }
.install-form label:first-of-type, .install-form .button { grid-column: 1 / -1; }

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .admin-name { display: none; }
  .main { width: calc(100% - 28px); padding-top: 16px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 24px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .task-form { grid-template-columns: 1fr; }
  .audio-row { grid-template-columns: 56px minmax(0, 1fr); gap: 11px; }
  .cover-wrap { width: 56px; }
  .row-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .meta-line span:last-child { display: none; }
}

@media (max-width: 420px) {
  .brand > span:last-child { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat { min-height: 70px; }
  .page-heading { flex-direction: column; align-items: stretch; }
  .page-heading .button { width: 100%; }
  .qr-stage { width: calc(100% - 40px); }
  .login-panel { padding: 24px 20px; }
  .install-panel { padding: 24px 20px; }
  .requirement-list, .install-form { grid-template-columns: 1fr; }
  .install-form label:first-of-type, .install-form .button { grid-column: auto; }
}
