:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --text: #17201c;
  --muted: #66716b;
  --line: #dce2df;
  --line-strong: #c4cec9;
  --green: #176b4d;
  --green-soft: #e5f2ec;
  --amber: #ad6b13;
  --amber-soft: #fff3dc;
  --red: #b43b35;
  --red-soft: #fbe9e7;
  --blue: #28658a;
  --shadow: 0 8px 24px rgba(25, 43, 34, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #16221d;
  color: #f7faf8;
  border-bottom: 1px solid #27362f;
}

.brand,
.model-state,
.topbar-actions,
.live-status,
.file-controls,
.realtime-controls,
.configuration-actions {
  display: flex;
  align-items: center;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #16221d;
}

.auth-gate[hidden] {
  display: none;
}

.login-panel {
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid #33463d;
  border-radius: 7px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.login-brand {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.login-panel h1 {
  margin: 5px 0 24px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.login-field input {
  width: 100%;
  height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
}

.login-field input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.1);
}

.login-error {
  display: block;
  min-height: 18px;
  margin-top: 12px;
  color: var(--red);
  font-size: 12px;
}

.login-button {
  width: 100%;
  margin-top: 4px;
}

.topbar-actions {
  gap: 14px;
}

.logout-button {
  padding: 5px 8px;
  border: 1px solid #4a5d54;
  border-radius: 5px;
  background: transparent;
  color: #cbd5d0;
  font-size: 12px;
}

.brand-name {
  font-size: 19px;
  font-weight: 750;
}

.brand-divider {
  width: 1px;
  height: 20px;
  margin: 0 12px;
  background: #53645c;
}

.brand-product {
  font-size: 14px;
  color: #c6d1cc;
}

.model-state {
  gap: 8px;
  font-size: 13px;
  color: #cbd5d0;
}

.state-dot,
.live-indicator {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #d2983d;
}

.model-state[data-state="ready"] .state-dot,
.live-indicator.active {
  background: #43c189;
  box-shadow: 0 0 0 4px rgba(67, 193, 137, 0.14);
}

.model-state[data-state="error"] .state-dot {
  background: #df625c;
}

.device-label {
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid #46574f;
  color: #91a39a;
}

.workspace {
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

.configuration-pane {
  display: flex;
  height: calc(100vh - 64px);
  min-height: 0;
  flex-direction: column;
  padding: 22px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
}

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

.section-kicker {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 22px;
}

h2 {
  margin: 0;
  font-size: 15px;
}

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
}

.button-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

.button-primary {
  background: var(--green);
  color: #fff;
}

.button-accent {
  min-width: 112px;
  background: #1f6850;
  color: #fff;
}

.button-danger {
  min-width: 122px;
  background: #243a31;
  color: #fff;
}

.button-danger.active {
  background: var(--red);
}

.category-list {
  flex: 1;
  min-height: 160px;
  padding-right: 5px;
  overflow-y: auto;
}

.category-item {
  margin-bottom: 10px;
  padding: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 7px;
}

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

.category-name,
.field input,
.prompt-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.category-name,
.field input {
  height: 36px;
  padding: 7px 9px;
}

.category-name:focus,
.field input:focus,
.prompt-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.1);
}

.normal-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.normal-toggle input {
  accent-color: var(--green);
}

.remove-category,
.text-button {
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 12px;
}

.prompt-label {
  display: block;
  margin: 11px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.prompt-input {
  min-height: 92px;
  resize: vertical;
  padding: 8px 9px;
  line-height: 1.45;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.configuration-actions {
  justify-content: flex-end;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.save-state {
  flex: 1;
  color: var(--muted);
  font-size: 12px;
}

.detection-pane {
  min-width: 0;
  padding: 22px 26px 32px;
}

.mode-tabs {
  display: inline-flex;
  padding: 3px;
  background: #e4e9e6;
  border-radius: 7px;
}

.mode-tab {
  min-width: 104px;
  padding: 8px 14px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(30, 45, 37, 0.12);
}

.mode-panel {
  margin-top: 22px;
}

.file-toolbar,
.realtime-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.file-drop {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  min-height: 88px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px dashed #aebbb5;
  border-radius: 7px;
  cursor: pointer;
}

.file-drop.dragging {
  background: var(--green-soft);
  border-color: var(--green);
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-drop-title {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.file-controls,
.realtime-controls {
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.compact-field {
  width: 88px;
}

.audio-player {
  width: 100%;
  height: 42px;
  margin-top: 14px;
}

.result-surface {
  min-height: 330px;
  margin-top: 20px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.result-surface.empty {
  display: grid;
  place-items: center;
  color: #8a9690;
  box-shadow: none;
}

.result-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.result-status {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 750;
}

.result-status.normal {
  background: var(--green-soft);
  color: var(--green);
}

.result-status.unknown {
  background: #edf0ef;
  color: #66716b;
}

.prediction-name {
  margin: 0;
  font-size: 27px;
  line-height: 1.25;
}

.analysis-meta {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.score-block {
  min-width: 110px;
  text-align: right;
}

.score-value {
  display: block;
  font-size: 25px;
  font-weight: 750;
}

.score-caption {
  color: var(--muted);
  font-size: 11px;
}

.ranking {
  margin-top: 18px;
}

.ranking-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) minmax(90px, 1fr) 70px;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  font-size: 13px;
}

.ranking-track {
  height: 7px;
  overflow: hidden;
  background: #e7ece9;
  border-radius: 3px;
}

.ranking-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
}

.ranking-score {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.live-status {
  gap: 12px;
}

.live-status strong,
.live-status span {
  display: block;
}

.live-status strong {
  font-size: 15px;
}

.live-status span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.level-track {
  height: 6px;
  margin-top: 18px;
  overflow: hidden;
  background: #dfe5e2;
  border-radius: 3px;
}

.level-fill {
  width: 0;
  height: 100%;
  background: #3eaa7c;
  transition: width 80ms linear;
}

.realtime-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(240px, 0.7fr);
  gap: 18px;
}

.history-panel {
  min-height: 330px;
  margin-top: 20px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.history-list {
  max-height: 276px;
  overflow-y: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #edf0ee;
  font-size: 12px;
}

.history-time,
.history-score,
.history-empty {
  color: var(--muted);
}

.history-score {
  font-variant-numeric: tabular-nums;
}

.history-empty {
  display: block;
  padding: 28px 0;
  text-align: center;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(380px, calc(100vw - 44px));
  padding: 11px 14px;
  transform: translateY(20px);
  border-radius: 6px;
  background: #17231e;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: #8d302c;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .configuration-pane {
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .category-list {
    max-height: 520px;
  }

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

@media (max-width: 680px) {
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
    padding: 13px 16px;
  }

  .device-label {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .configuration-pane,
  .detection-pane {
    padding: 18px 15px;
  }

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

  .file-controls,
  .realtime-controls {
    align-items: end;
    flex-wrap: wrap;
  }

  .button-accent,
  .button-danger {
    flex: 1;
  }

  .result-summary {
    grid-template-columns: 1fr;
  }

  .score-block {
    text-align: left;
  }

  .ranking-row {
    grid-template-columns: 96px minmax(60px, 1fr) 60px;
  }
}
