/* ── Reset & Base ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --panel:     #161b22;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;
  --green:     #3fb950;
  --red:       #f85149;
  --yellow:    #d29922;
  --purple:    #bc8cff;
  --radius:    12px;

  --cls-0: #58a6ff;
  --cls-1: #3fb950;
  --cls-2: #f85149;
  --cls-3: #d29922;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Erro de microfone (inline, não bloqueia o app) ── */
#mic-error {
  background: #2a1a1a;
  border: 1px solid #f8514950;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}
#mic-error.hidden { display: none; }
#mic-error-title { font-weight: 700; color: #f85149; margin-bottom: 4px; }
#mic-error-msg   { font-size: .85rem; color: var(--muted); line-height: 1.5; }

/* ── Overlay: Treinando ── */
#training-overlay {
  position: fixed; inset: 0;
  background: rgba(13,17,23,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 90;
}
#training-overlay.hidden { display: none; }

#training-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 48px;
  text-align: center;
  min-width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
#training-icon  { font-size: 2.5rem; animation: pulse 1s ease-in-out infinite; }
#training-title { font-size: 1.2rem; font-weight: 700; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.12)} }

#training-bar-wrap {
  width: 100%; height: 8px;
  background: var(--border); border-radius: 4px; overflow: hidden;
}
#training-bar {
  height: 100%; width: 0%;
  background: var(--accent); border-radius: 4px;
  transition: width .15s ease;
}
#training-epoch { font-size: .85rem; color: var(--muted); }
#training-acc   { font-size: 1rem; color: var(--green); font-weight: 600; }

/* ── Header ── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#header-left { display: flex; align-items: center; gap: 12px; }

#back-btn {
  color: var(--muted); text-decoration: none;
  font-size: 13px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  transition: color .2s, border-color .2s;
}
#back-btn:hover { color: var(--text); border-color: var(--accent); }

#header-title  { font-size: 1.05rem; font-weight: 700; }
#header-badge  {
  font-size: .72rem; color: var(--muted);
  background: #21262d; padding: 3px 10px;
  border-radius: 20px; border: 1px solid var(--border);
}

/* ── Botões globais ── */
.btn-primary {
  background: var(--accent); color: #0d1117;
  border: none; border-radius: 8px;
  padding: 12px 20px; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s, transform .1s;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { opacity: .88; }
.btn-primary:active:not(:disabled) { transform: scale(.97); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }

.btn-secondary {
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 18px; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .2s; width: 100%;
}
.btn-secondary:hover { background: rgba(88,166,255,.08); }

.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font-size: .85rem;
  cursor: pointer; transition: color .2s, border-color .2s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.hidden { display: none !important; }

/* ── Layout principal ── */
#main-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

/* ──────────────────────────────────────────────
   PAINEL DO MICROFONE (esquerda)
─────────────────────────────────────────────── */
#mic-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 20px;
  gap: 10px;
  min-width: 0;
  overflow-y: auto;
}

/* Bloco de visualização */
.viz-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.viz-label {
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.viz-hint {
  font-size: .75rem;
  font-weight: 400;
  color: #484f58;
  text-transform: none;
  letter-spacing: 0;
}

/* Canvas de waveform */
#canvas-wave {
  width: 100%;
  height: 110px;
  border-radius: var(--radius);
  background: #0a0e14;
  border: 1px solid var(--border);
  display: block;
  transition: border-color .3s;
}

/* Canvas de espectro */
#canvas-freq {
  width: 100%;
  height: 120px;
  border-radius: var(--radius);
  background: #0a0e14;
  border: 1px solid var(--border);
  display: block;
  transition: border-color .3s;
}

/* Escala de frequência */
#freq-scale {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: #484f58;
  padding: 0 4px;
}

/* Borda colorida durante gravação */
body[data-recording="true"] #canvas-wave,
body[data-recording="true"] #canvas-freq {
  border-color: var(--rec-color, var(--red));
}

/* Borda pulsante apenas enquanto o botão está segurado (ouvindo ativamente) */
body[data-listening="true"] #canvas-wave,
body[data-listening="true"] #canvas-freq {
  border-color: var(--accent);
  box-shadow: 0 0 0 0 rgba(88,166,255,.5);
  animation: mic-pulse 1.8s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(88,166,255,.4); }
  50%      { box-shadow: 0 0 0 6px rgba(88,166,255,.0); }
}

/* Status do microfone */
#mic-status {
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
  transition: color .2s;
}
body[data-recording="true"] #mic-status { color: var(--rec-color, var(--red)); }

/* Seção de previsão (injetada por JS quando em modo predicting) */
#pred-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#pred-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  justify-content: center;
}

#pred-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}

#pred-name {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: .02em;
  text-align: center;
  transition: color .15s, text-shadow .15s;
}

#pred-bars { display: flex; flex-direction: column; gap: 6px; }

/* Botão segurar-para-ouvir */
.btn-listen {
  background: rgba(88,166,255,.10);
  border: 2px solid var(--accent);
  border-radius: 10px;
  color: var(--accent);
  font-size: .88rem;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  width: 100%;
  transition: background .15s, transform .1s, box-shadow .2s;
}
.btn-listen:hover {
  background: rgba(88,166,255,.18);
}
.btn-listen.listening {
  background: var(--accent);
  color: #0d1117;
  transform: scale(.98);
  box-shadow: 0 0 18px rgba(88,166,255,.55);
  animation: listen-pulse 1s ease-in-out infinite;
}
@keyframes listen-pulse {
  0%,100% { box-shadow: 0 0 10px rgba(88,166,255,.4); }
  50%      { box-shadow: 0 0 24px rgba(88,166,255,.8); }
}

.pred-bar-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .82rem; opacity: .6;
  transition: opacity .15s;
}
.pred-bar-row.active { opacity: 1; }
.pred-bar-label { width: 80px; text-align: right; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pred-bar-track { flex: 1; height: 7px; background: rgba(255,255,255,.1); border-radius: 4px; overflow: hidden; }
.pred-bar-fill  { height: 100%; border-radius: 4px; transition: width .1s ease; }
.pred-bar-pct   { width: 36px; font-size: .75rem; color: var(--muted); }

/* ──────────────────────────────────────────────
   PAINEL DE PESSOAS (direita)
─────────────────────────────────────────────── */
#classes-panel {
  width: 320px;
  flex-shrink: 0;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px;
  overflow-y: auto;
}

#classes-header { display: flex; flex-direction: column; gap: 3px; }
#classes-title  { font-size: .95rem; font-weight: 700; }
#classes-sub    { font-size: .78rem; color: var(--muted); }

#classes-list { display: flex; flex-direction: column; gap: 10px; }

/* ── Cartão de pessoa ── */
.class-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cls-color, var(--accent));
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}

.class-card-header {
  display: flex; align-items: center; gap: 8px;
}
.class-color-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.class-name-input {
  flex: 1; background: transparent;
  border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: .95rem; font-weight: 700;
  outline: none; padding: 2px 4px;
  transition: border-color .2s;
}
.class-name-input:focus { border-bottom-color: var(--accent); }
.class-name-input::placeholder { color: #484f58; font-weight: 400; }

.btn-delete-class {
  background: none; border: none; color: var(--muted);
  font-size: .85rem; cursor: pointer; padding: 2px 6px;
  border-radius: 4px; transition: color .2s, background .2s;
}
.btn-delete-class:hover { color: var(--red); background: rgba(248,81,73,.1); }

.sample-progress-wrap {
  height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.sample-progress-fill {
  height: 100%; background: var(--cls-color, var(--accent));
  border-radius: 2px; transition: width .2s ease;
}
.sample-count-label {
  font-size: .78rem; color: var(--muted); transition: color .2s;
}
.sample-count-label.ready { color: var(--cls-color, var(--green)); }

/* Botão gravar */
.btn-record {
  background: rgba(248,81,73,.1);
  border: 1px solid var(--red); color: var(--red);
  border-radius: 8px; padding: 9px 12px;
  font-size: .85rem; font-weight: 700;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .15s, transform .1s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-record:hover { background: rgba(248,81,73,.18); }
.btn-record:active, .btn-record.recording {
  background: var(--red); color: #fff; transform: scale(.97);
}
.btn-record:disabled { opacity: .35; cursor: not-allowed; }

/* ── Seção de treino ── */
#train-section {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: auto; padding-top: 12px;
  position: sticky; bottom: 0;
  background: var(--panel);
  padding-bottom: 4px;
}
#train-hint {
  font-size: .8rem; color: var(--green); text-align: center; font-weight: 600;
}



/* ── Responsividade ── */
@media (max-width: 700px) {
  body { height: auto; overflow-y: auto; }
  #main-layout { flex-direction: column; overflow: visible; height: auto; }
  #classes-panel {
    width: 100%; border-left: none;
    border-top: 1px solid var(--border);
    max-height: none; overflow-y: visible;
  }
  #mic-panel { padding: 12px; overflow-y: visible; min-height: 0; }
  #canvas-wave { height: 80px; }
  #canvas-freq { height: 90px; }
  #train-section { position: static; }
}
