:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #18212f;
  --muted: #667085;
  --line: #dfe5ec;
  --strong: #2563eb;
  --strong-hover: #1d4ed8;
  --ok: #15803d;
  --ok-bg: #e7f7ee;
  --bad: #b42318;
  --bad-bg: #fee4e2;
  --warn: #b54708;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  background: var(--strong);
  color: #fff;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--strong-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.secondary {
  background: #e9eef8;
  color: #223046;
}

button.secondary:hover {
  background: #dce5f5;
}

button.danger {
  background: var(--bad-bg);
  color: var(--bad);
}

button.danger:hover {
  background: #ffd1cc;
}

button.small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--strong);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  min-height: 172px;
  resize: vertical;
  line-height: 1.55;
}

code {
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.hidden {
  display: none !important;
}

.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 18px 42px;
}

.auth-view {
  min-height: 80vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-card h1,
.topbar h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: 0;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.error-text {
  min-height: 18px;
  color: var(--bad);
  font-size: 13px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 16px;
}

.top-actions,
.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 76px;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(420px, 0.9fr);
  gap: 14px;
}

.management-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 17px;
  letter-spacing: 0;
}

.model-list {
  display: grid;
  gap: 10px;
}

.model-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 12px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}

.model-item.active {
  border-color: #7bcaa0;
  background: #f3fbf6;
}

.model-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.model-title-row strong {
  font-size: 15px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.pill.ok {
  color: var(--ok);
  background: var(--ok-bg);
}

.pill.bad {
  color: var(--bad);
  background: var(--bad-bg);
}

.model-meta,
.model-description,
.model-path {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.model-description {
  color: #344054;
}

.model-side {
  display: grid;
  gap: 8px;
  align-content: center;
  justify-items: stretch;
}

.model-side span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

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

.upload-form input[type="text"],
.upload-form button {
  grid-column: span 2;
}

.result-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
}

.config-list {
  display: grid;
  gap: 10px;
}

.config-list > div {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.config-list span {
  color: var(--muted);
  font-size: 12px;
}

.config-list em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  text-align: right;
}

.config-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

.history-panel {
  margin-top: 14px;
}

.history-head {
  align-items: flex-start;
}

.history-actions {
  justify-content: flex-end;
}

.history-actions input {
  width: 210px;
}

.history-actions select {
  width: auto;
  min-width: 116px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--panel-soft);
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-top div:first-child {
  display: grid;
  gap: 3px;
}

.history-top span,
.history-time,
.history-metrics {
  color: var(--muted);
  font-size: 12px;
}

.history-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.history-text {
  margin: 10px 0;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

audio {
  width: 100%;
  height: 36px;
}

.empty-state {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: #fbfcfe;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  z-index: 10;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  padding: 11px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .status-grid,
  .dashboard-grid,
  .management-grid {
    grid-template-columns: 1fr;
  }

  .password-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 18px 12px 32px;
  }

  .topbar,
  .panel-head,
  .history-top {
    flex-direction: column;
    align-items: stretch;
  }

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

  .model-item,
  .config-list > div,
  .history-controls,
  .upload-form {
    grid-template-columns: 1fr;
  }

  .config-list em {
    text-align: left;
  }

  .upload-form input[type="text"],
  .upload-form button {
    grid-column: auto;
  }

  .history-actions,
  .top-actions {
    width: 100%;
  }

  .history-actions input,
  .history-actions select,
  .history-actions button,
  .top-actions button {
    width: 100%;
  }
}
