/* AI_VOICE 蓝牙按键配置工具 — 网页版样式 */

:root {
  --bg:           #f5f5f7;
  --card-bg:      #ffffff;
  --border:       #e6e6ea;
  --text:         #1f2330;
  --text-dim:     #6b7180;
  --text-faint:   #999aa3;
  --accent:       #0066cc;
  --accent-hover: #0050a3;
  --success:      #1f9d55;
  --warn:         #d97706;
  --error:        #d4453a;
  --shadow:       0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.03);
  --radius:       8px;
  --mono:         ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
               "PingFang SC", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  background: #0d1117;
  border-bottom: 1px solid #21262d;
  padding: 0 28px;
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.topbar-titles {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #e6edf3;
  line-height: 1;
}
.topbar-sub {
  font-size: 11px;
  color: #7d8590;
  letter-spacing: 0.04em;
  line-height: 1;
}
.topbar-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #00C9FF;
  background: rgba(0, 201, 255, 0.1);
  border: 1px solid rgba(0, 201, 255, 0.25);
  border-radius: 4px;
  padding: 3px 8px;
}
.back-home {
  font-size: 13px;
  color: #94a3b8;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  transition: all 0.2s ease;
}
.back-home:hover {
  color: #e6edf3;
  background: rgba(255, 255, 255, 0.08);
}

/* Container */
.container {
  max-width: 980px;
  margin: 20px auto;
  padding: 0 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Tabs (e.g. 单按键设备 / 4 按键设备) — sitting between the card title and
   the key rows. Pill-style switch, the active one is filled with the accent
   color. */
.tabs {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 14px;
  padding: 4px;
  background: #f3f4f7;
  border-radius: 8px;
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-width: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab:hover:not(.active):not(:disabled) {
  color: var(--text);
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.row .spacer { flex: 1; }

/* Apply status badge, next to the "应用到设备" button. Empty by default;
   gets a class from JS once SET_KEY commands have been dispatched.        */
.apply-status {
  display: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  align-self: center;
}
.apply-status.show {
  display: inline-block;
  background: #e6f6ec;
  color: var(--success);
  border: 1px solid #b6e2c6;
}
.apply-status.error {
  background: #fdecea;
  color: var(--error);
  border: 1px solid #f5c2bd;
}
.apply-status.warn {
  background: #fff5e0;
  color: var(--warn);
  border: 1px solid #f4d99f;
}

/* Auto-off setting */
.setting-label {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.setting-select {
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  min-width: 120px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.setting-select:hover {
  border-color: var(--accent);
}
.setting-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

/* Buttons */
button {
  font: inherit;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  min-width: 80px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
button:active:not(:disabled) {
  background: #f0f4fa;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#btn-pick-port {
  min-width: 260px;
  text-align: center;
  white-space: nowrap;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}
button.success {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}
button.success:hover:not(:disabled) {
  background: #178048;
  border-color: #178048;
  color: #ffffff;
}
/* Connected-state variant of the toggle button: stops looking like a primary
   CTA and signals "click here to disconnect" with a fully-filled red
   destructive color. Size matches the default button — same base style
   applies. */
button.connected {
  background: var(--error);
  border-color: var(--error);
  color: #ffffff;
}
button.connected:hover:not(:disabled) {
  background: #b5362c;
  border-color: #b5362c;
  color: #ffffff;
}

/* Status */
.status {
  font-weight: 600;
  color: var(--text-faint);
  font-size: 13px;
  margin-left: 6px;
}
/* LED indicator that mirrors the device LED.
   Default state = idle (unconnected) = blue.
   .on = connected = purple. */
.led {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-left: 14px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  transition: background 0.18s, box-shadow 0.18s;
  vertical-align: middle;
}
.led.idle {
  background: #2d8df0;
  box-shadow: 0 0 6px rgba(45, 141, 240, 0.55);
}
.led.on {
  background: #9b30ff;
  box-shadow: 0 0 8px rgba(155, 48, 255, 0.65);
}

/* Browser warn */
.browser-warn {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fff7e6;
  border: 1px solid #f3c178;
  border-radius: 6px;
  color: #92580f;
  font-size: 13px;
}

/* Key rows */
.key-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.key-row {
  display: grid;
  grid-template-columns: 80px 140px 220px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-top: 1px solid #f0f0f3;
}
.key-row.header {
  border-top: none;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
/* Step 2 has two visual modes:
   - Before device is connected: show a single full-width hint.
   - After connection: show the tab + table.                       */
.key-config { display: none; }
.key-config.shown { display: block; }
.key-empty-hint {
  display: none;
  padding: 28px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  background: #f6f8fb;
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.key-empty-hint.shown { display: block; }
.key-empty-hint strong {
  color: var(--accent);
  font-weight: 600;
}
@media (max-width: 760px) {
  .key-row { grid-template-columns: 70px 1fr; gap: 8px; }
  .key-row.header { display: none; }
  .col-id { grid-column: 1; }
  .col-current, .col-capture, .col-hint {
    grid-column: 2;
  }
}

.col-id {
  font-family: var(--mono);
  color: var(--text);
  font-weight: 600;
}
.col-current {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 600;
}
.col-hint {
  color: var(--text-faint);
  font-size: 12px;
}
.col-hint.hint-success {
  color: var(--success);
  font-weight: 500;
}

/* Capture button (the main "new key" cell) */
.col-capture {
  text-align: left;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.col-capture:hover {
  background: #f0f6ff;
}
/* In the header row this cell is a non-interactive label. Strip the
   button-like affordances so users aren't misled into clicking it. */
.key-row.header .col-capture {
  background: transparent;
  border: none;
  cursor: default;
  font-weight: 600;
  color: var(--text-dim);
  padding: 8px 14px;
  min-height: 0;
}
.key-row.header .col-capture:hover {
  background: transparent;
}
.capture-display { font-size: 14px; }
.capture-display.placeholder {
  color: var(--text-faint);
  font-weight: 400;
  font-style: italic;
  font-size: 13px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.12s ease-out;
}
.modal {
  background: #ffffff;
  border-radius: 10px;
  padding: 24px;
  width: 460px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideIn 0.16s ease-out;
}
.modal-title {
  font-size: 15px;
  color: var(--text);
}
.capture-area {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 18px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafc;
  outline: none;
}
.capture-area:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}
.capture-display-large {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
  text-align: center;
}
.capture-display-large.locked { color: #cc9900; }
.capture-hint {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}
.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }