:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #182230;
  --muted: #5a6678;
  --border: #dce2ea;
  --primary: #1463ff;
  --primary-hover: #0e4fd4;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --ok-bg: #e7f6ec;
  --ok-text: #116b36;
  --off-bg: #f1f3f6;
  --off-text: #4c5664;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.95rem;
}

.nav a.active,
.nav a:hover {
  background: #edf2ff;
  color: var(--primary);
}

.container {
  max-width: 1040px;
  margin: 28px auto;
  padding: 0 20px 48px;
}

.login-wrap {
  max-width: 420px;
  margin: 64px auto;
  padding: 0 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

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

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

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

.badge-off {
  background: var(--off-bg);
  color: var(--off-text);
}

.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 0.9rem;
  margin: 0 0 16px;
}

.meta-list dt {
  color: var(--muted);
}

.meta-list dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 16px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.85rem;
}

.status-banner {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.status-banner.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-banner.err {
  background: #fef3f2;
  color: #b42318;
  border: 1px solid #fecdca;
}

.hidden {
  display: none !important;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fcfdff;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.history-q {
  font-weight: 600;
  margin-bottom: 6px;
}

.history-a {
  color: #243042;
  white-space: pre-wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 420px;
  width: 100%;
  padding: 20px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.22);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-gap {
  margin-top: 16px;
}

.status-banner.warn {
  background: #fffaeb;
  color: #b54708;
  border: 1px solid #fedf89;
}

.invite-code-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #eff8ff;
  border: 1px solid #b2ddff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  word-break: break-all;
}

.cred-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
  background: #fcfdff;
  flex-wrap: wrap;
}

.section-gap-sm {
  margin-top: 8px;
}

.routing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.routing-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fcfdff;
}

.routing-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.routing-detail {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text);
}

.badge-byok {
  background: #edf2ff;
  color: #1849a9;
}

.badge-warn {
  background: #fffaeb;
  color: #b54708;
}

.tts-preview-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.tts-preview-bar input {
  flex: 1 1 240px;
}

.preview-audio {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.curl-box {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: #f9fbff;
}

.curl-box label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.curl-box textarea {
  width: 100%;
  min-height: 76px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  margin-bottom: 8px;
  resize: vertical;
}

.transfer-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fffaeb;
  color: #b54708;
  border: 1px solid #fedf89;
  font-size: 0.9rem;
}

.btn-warn {
  background: #fff;
  color: #b54708;
  border: 1px solid #f79009;
}

.btn-warn:hover {
  background: #fef0c7;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.ytlite-quick-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.ytlite-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fcfdff;
}

.metric-value {
  font-weight: 700;
  font-size: 1rem;
  margin-top: 4px;
  color: var(--text);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.checkbox-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.checkbox-grid label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
}

.token-status-box {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fcfdff;
}

.queue-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
  background: #fcfdff;
}

.queue-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.queue-tracks {
  margin: 8px 0 0 18px;
  padding: 0;
  font-size: 0.88rem;
  color: var(--text);
}

.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-left: 6px;
}

.badge-err {
  color: #b91c1c;
}

.callout {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  margin-top: 8px;
}

