/* Hardware Audio Device Selectors in Latency Modal */
.latency-devices-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 14px 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.025);
  border: 1px solid var(--paper-border);
  border-radius: var(--radius-md);
}

.latency-device-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.latency-device-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 72px;
  font-family: var(--font-main);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--graphite-dark);
  cursor: pointer;
  user-select: none;
}

.latency-device-label .device-icon {
  width: 14px;
  height: 14px;
  stroke: var(--graphite-medium);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.latency-select-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}

.latency-device-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--paper-bg, #fff);
  border: 1px solid var(--paper-border-focus);
  border-radius: var(--radius-sm);
  padding: 5px 24px 5px 9px;
  font-family: var(--font-main);
  font-size: 0.78rem;
  color: var(--graphite-dark);
  cursor: pointer;
  outline: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" fill="none" stroke="%23736d64" stroke-width="1.2" stroke-linecap="round"/></svg>');
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.latency-device-select:hover,
.latency-device-select:focus {
  border-color: var(--pencil-orange, #ea580c);
}

.latency-device-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background-color: rgba(0, 0, 0, 0.04);
}

.latency-device-select option {
  background: var(--paper-bg, #fff);
  color: var(--graphite-dark);
}

[data-theme="dark"] .latency-devices-section {
  background: rgba(0, 0, 0, 0.22);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .latency-device-label {
  color: #ede9e1;
}

[data-theme="dark"] .latency-device-label .device-icon {
  stroke: rgba(235, 230, 220, 0.75);
}

[data-theme="dark"] .latency-device-select {
  background-color: #2b2825;
  border-color: rgba(255, 255, 255, 0.16);
  color: #f4f4f4;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" fill="none" stroke="%23f4f4f4" stroke-width="1.2" stroke-linecap="round"/></svg>');
}

[data-theme="dark"] .latency-device-select:hover,
[data-theme="dark"] .latency-device-select:focus {
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

[data-theme="dark"] .latency-device-select:disabled {
  background-color: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .latency-device-select option {
  background: #383531;
  color: #f0ede6;
}

/* Mic level meter (segmented: green ideal, yellow loud, red clipping) */
.mic-level-meter {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 2px;
  height: 14px;
  padding: 2px;
  border: 1px solid var(--paper-border-focus);
  border-radius: var(--radius-sm);
  background: var(--paper-bg, #fff);
  transition: border-color 0.15s ease;
}

.mic-level-meter.clipping {
  border-color: #dc2626;
}

.mic-meter-seg {
  flex: 1;
  border-radius: 1px;
  opacity: 0.18;
  transition: opacity 0.06s linear;
}

.mic-meter-seg.zone-green { background: #22c55e; }
.mic-meter-seg.zone-yellow { background: #eab308; }
.mic-meter-seg.zone-red { background: #dc2626; }
.mic-meter-seg.on { opacity: 1; }

.mic-level-readout {
  min-width: 42px;
  text-align: right;
  font-family: var(--font-main);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--graphite-medium);
}

.mic-level-readout.clipping {
  color: #dc2626;
  font-weight: 700;
}

[data-theme="dark"] .mic-level-meter {
  background: #2b2825;
  border-color: rgba(255, 255, 255, 0.16);
}

[data-theme="dark"] .mic-level-meter.clipping {
  border-color: #ef4444;
}

[data-theme="dark"] .mic-meter-seg { opacity: 0.14; }
[data-theme="dark"] .mic-meter-seg.on { opacity: 1; }

[data-theme="dark"] .mic-level-readout {
  color: rgba(235, 230, 220, 0.75);
}

/* Auto Calibration */
.latency-calib-section {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--paper-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  text-align: center;
  margin-bottom: 16px;
}

.calib-header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}

.calib-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--graphite-dark);
  text-align: center;
}

.btn-calib-action {
  background: var(--graphite-dark);
  color: #fff;
  border: none;
  font-family: var(--font-main);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.15s ease;
}

.btn-calib-action:hover {
  opacity: 0.88;
}

.btn-calib-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.calib-instructions {
  font-size: 0.71rem;
  line-height: 1.35;
  color: var(--graphite-light);
  margin: 8px 0;
  text-align: center;
}

.calib-status-box {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--graphite-medium);
  background: #fff;
  border: 1px solid var(--paper-border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.calib-status-box.success {
  border-color: var(--pencil-green);
  color: var(--pencil-green);
  background: rgba(63, 126, 88, 0.06);
}

.calib-status-box.measuring {
  border-color: var(--pencil-gold);
  color: var(--pencil-gold);
  background: rgba(199, 137, 50, 0.06);
}

.calib-status-box.error {
  border-color: var(--pencil-red-border);
  color: var(--pencil-red);
  background: var(--pencil-red-bg);
}

.btn-calib-large {
  width: 100%;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-md);
  background: #2563eb;
  color: #ffffff;
  border: 1px solid #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.15s ease;
}

.btn-calib-large:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  transform: translateY(-1px);
}

.btn-calib-large:active {
  background: #1e40af;
  border-color: #1e40af;
  transform: translateY(0);
}

.btn-calib-large:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.latency-visual-wrap {
  width: 100%;
  margin: 10px 0 2px 0;
  animation: fadeIn 0.2s ease-out;
}

.latency-calib-canvas {
  width: 100%;
  height: 160px;
  display: block;
  border-radius: var(--radius-md);
}

.latency-success-wrap {
  width: 100%;
  margin-top: 14px;
  text-align: center;
  animation: fadeIn 0.2s ease-out;
}

.btn-latency-start-looping {
  display: inline-block;
  padding: 10px 24px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font-main);
  text-align: center;
  border-radius: var(--radius-pill);
  background: #ea580c;
  color: #ffffff;
  border: 1px solid #ea580c;
  box-shadow: 0 3px 12px rgba(234, 88, 12, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn-latency-start-looping:hover {
  background: #ffffff;
  color: #ea580c !important;
  border-color: #ea580c;
  opacity: 1;
  transform: translateY(-1px);
}

.btn-latency-start-looping:active,
.btn-latency-start-looping.pressed {
  background: #000000 !important;
  color: #ffffff !important;
  border-color: #000000 !important;
  transform: translateY(0);
}

/* Latency Modal Dark Mode Overrides */
[data-theme="dark"] .btn-calib-large {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

[data-theme="dark"] .btn-calib-large:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

[data-theme="dark"] .btn-calib-large:active {
  background: #1e40af;
  border-color: #1e40af;
}

[data-theme="dark"] .btn-latency-start-looping {
  background: #ea580c;
  color: #ffffff;
  border-color: #ea580c;
}

[data-theme="dark"] .btn-latency-start-looping:hover {
  background: #ffffff;
  color: #ea580c !important;
  border-color: #ea580c;
}

[data-theme="dark"] .btn-latency-start-looping:active,
[data-theme="dark"] .btn-latency-start-looping.pressed {
  background: #000000 !important;
  color: #ffffff !important;
  border-color: #000000 !important;
}

[data-theme="dark"] .latency-calib-section {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .calib-title {
  color: var(--graphite-dark);
}

[data-theme="dark"] .calib-instructions {
  color: var(--graphite-light);
}

[data-theme="dark"] .calib-status-box {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--graphite-medium);
}

[data-theme="dark"] .btn-nudge {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--graphite-dark);
}

[data-theme="dark"] .btn-nudge:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.22);
}

[data-theme="dark"] .btn-nudge:active {
  background: rgba(255, 255, 255, 0.22);
}

[data-theme="dark"] .latency-input-wrapper {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.14);
}

[data-theme="dark"] #input-latency-val {
  color: var(--graphite-dark);
}

[data-theme="dark"] .btn-preset {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--graphite-medium);
}

[data-theme="dark"] .btn-preset:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--graphite-dark);
}

[data-theme="dark"] .btn-preset.active {
  background: #ea580c;
  color: #fff;
  border-color: #ea580c;
}
