/* ── PolyTalk · CafeKit Design System ─────────────────────────────
   Tokens cloned from cafekit.haposoft.com */

/* ── Reset ─────────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Surface — exact CafeKit tokens */
  --background:         #fcfcf5;
  --foreground:         #101820;
  --card:               #ffffff;
  --card-foreground:    #101820;
  --popover:            #ffffff;
  --popover-foreground: #101820;

  /* Brand */
  --primary:            #006242;
  --primary-foreground: #f7faf8;
  --secondary:          #a7c5ee;
  --secondary-foreground:#101820;
  --muted:              #eef5f1;
  --muted-foreground:   #456055;
  --accent:             #f2ea9d;
  --accent-foreground:  #101820;

  /* Feedback */
  --destructive:        #ef4444;
  --destructive-foreground: #fff;
  --info:               #a7c5ee;
  --info-foreground:    #101820;
  --success:            #006242;
  --success-foreground: #f7faf8;
  --warning:            #f2ea9d;
  --warning-foreground: #101820;

  /* Borders & inputs */
  --border:             #1018201f;
  --input:              #1018201f;
  --ring:               #006242;

  /* Radius — CafeKit: 0.5rem */
  --radius:             0.5rem;
  --radius-sm:          0.375rem;

  /* Layout */
  --sidebar-w:          300px;
  --transition:         0.18s ease;
}

html { font-size: 17px; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--background);
  color: var(--foreground);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

/* ── Grid background pattern (CafeKit: 28px cells) ─────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(16,24,32,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16,24,32,.06) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* Radial glow at top-left (CafeKit hero effect) */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 0% 0%, rgba(167,197,238,.28), transparent 36%),
    linear-gradient(135deg, #fcfcf5 0%, #f4f8ee 44%, #eaf4ef 100%);
  opacity: 0.85;
}

/* ── App Shell ────────────────────────────────────────────────── */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 20;
}

.sidebar-header {
  padding: 1.25rem 1.35rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--foreground);
}

.logo-mark {
  flex-shrink: 0;
  margin-left: -4px;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.logo-tag {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--primary);
  background: var(--muted);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

/* ── Sidebar nav ──────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 0.85rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-label {
  font-size: 0.8rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Badge ─────────────────────────────────────────────────────── */
.badge {
  font-size: 0.8rem;
  font-weight: 650;
  background: var(--secondary);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  color: var(--secondary-foreground);
}

/* ── Engine cards ─────────────────────────────────────────────── */
.engine-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.engine-radio { cursor: pointer; }

.engine-radio input {
  position: absolute; opacity: 0; pointer-events: none;
}

.engine-card {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  transition: all var(--transition);
}

.engine-radio input:checked + .engine-card {
  border-color: var(--primary);
  background: var(--muted);
}

.engine-name {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--foreground);
}

.engine-desc {
  font-size: 0.8rem;
  color: var(--muted-foreground);
  margin-top: 0.05rem;
}

.warn {
  font-size: 0.8rem;
  color: var(--warning-foreground);
  background: var(--warning);
  border: 1px solid rgba(242, 234, 157, .4);
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  margin-top: 0.25rem;
}

/* ── Participants ──────────────────────────────────────────────── */
#participants-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.participant-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0.55rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.participant-row:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(0,98,66,.08);
}

.participant-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* Speaker avatar — color set inline via JS */
.avatar {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: var(--muted-foreground);
  user-select: none;
}

/* Borderless name — frame appears on hover/focus only */
.participant-name {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 650;
  background: transparent;
  color: var(--foreground);
  transition: background var(--transition), border-color var(--transition);
}

.participant-name:hover { background: var(--muted); }

.participant-name:focus {
  outline: none;
  background: var(--background);
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(0,98,66,.1);
}

.participant-name::placeholder { color: var(--muted-foreground); opacity: 0.7; font-weight: 500; }

/* ── Custom select (mic icon + caret) ──────────────────────────── */
.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.select-wrap select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 0.4rem 1.8rem 0.4rem 0.5rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  background: var(--background);
  color: var(--foreground);
  cursor: pointer;
  transition: border-color var(--transition);
}

.select-wrap.has-icon select { padding-left: 1.85rem; }

.select-wrap select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(0,98,66,.07);
}

.select-icon {
  position: absolute;
  left: 0.6rem;
  color: var(--muted-foreground);
  pointer-events: none;
}

.select-caret {
  position: absolute;
  right: 0.55rem;
  color: var(--muted-foreground);
  pointer-events: none;
}

/* Gender color cue on the mic icon */
.select-icon.g-female { color: #db2777; }
.select-icon.g-male { color: #2563eb; }

/* ── Voice row: select + preview + download ────────────────────── */
.voice-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.voice-row .select-wrap { flex: 1; min-width: 0; }

.voice-play,
.voice-download {
  border: 1px solid var(--border);
  color: var(--muted-foreground);
  background: var(--card);
}

.voice-play:hover,
.voice-download:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--muted);
}

.voice-download { text-decoration: none; }

/* Play/stop icon toggle */
.voice-play .ic-stop { display: none; }
.voice-play.playing .ic-play { display: none; }
.voice-play.playing .ic-stop { display: inline-flex; }
.voice-play.playing { color: var(--primary); border-color: var(--primary); }

/* Disabled state (no sample available) */
.voice-play:disabled,
.voice-download.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ── Pause ─────────────────────────────────────────────────────── */
.pause-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#pause-ms {
  flex: 1;
  accent-color: var(--primary);
  cursor: pointer;
  height: 4px;
}

#pause-label {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--muted-foreground);
  min-width: 55px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Sidebar footer ───────────────────────────────────────────── */
.sidebar-footer {
  padding: 0.85rem 1.35rem;
  border-top: 1px solid var(--border);
}

.kbd-hint {
  font-size: 0.78rem;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.kbd-hint kbd {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--foreground);
}

.kbd-sep { opacity: 0.5; margin: 0 0.15rem; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn-primary:hover:not(:disabled) {
  background: #005335;
}

.btn-ghost {
  background: transparent;
  color: var(--muted-foreground);
  border: 1px dashed var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--foreground);
  border-color: var(--primary);
  background: var(--muted);
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.7rem 1.6rem; font-size: 0.95rem; }

.btn-icon {
  width: 24px; height: 24px; padding: 0;
  border-radius: 999px;
  background: transparent; border: 1px solid transparent;
  color: var(--muted-foreground); font-size: 0.85rem; flex-shrink: 0;
}
.btn-icon:hover {
  color: var(--destructive);
  background: #fef2f2;
  border-color: #fecaca;
}

/* ── Icons (Lucide) ────────────────────────────────────────────── */
.lucide {
  width: 1.05em;
  height: 1.05em;
  stroke-width: 2;
  flex-shrink: 0;
  vertical-align: -0.16em;
}
.btn .lucide { width: 1em; height: 1em; }
.btn-icon .lucide { width: 15px; height: 15px; }
.select-icon.lucide, .select-caret.lucide { width: 15px; height: 15px; }

/* ── Main area ─────────────────────────────────────────────────── */
.main {
  flex: 1;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* Inner wrapper aligns header / body / footer to one column */
.main-inner {
  max-width: none;
  width: 100%;
  margin: 0 auto;
}

.main-header {
  flex-shrink: 0;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
}

.main-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
}

.main-body > .main-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.main-footer {
  flex-shrink: 0;
  padding: 0.9rem 2rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
}

/* ── Section header ────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h1 {
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--foreground);
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.turn-count {
  font-size: 0.85rem;
  color: var(--muted-foreground);
  font-weight: 500;
}

/* ── Turns (ElevenLabs-style script editor) ────────────────────── */
.turns-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-bottom: 1rem;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  text-align: center;
  color: var(--muted-foreground);
  padding: 3rem 1.5rem;
  margin: auto;
  width: 100%;
}

.empty-icon {
  width: 2.4rem;
  height: 2.4rem;
  color: var(--muted-foreground);
  opacity: 0.5;
  stroke-width: 1.5;
}

.empty-title { font-size: 1.05rem; font-weight: 700; color: var(--foreground); }
.empty-sub { font-size: 0.9rem; max-width: 26rem; line-height: 1.55; }
.empty-state .btn { margin-top: 0.5rem; }

/* Turn row */
.turn-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  position: relative;
  transition: background var(--transition);
}

.turn-row:hover,
.turn-row:focus-within { background: var(--muted); }

/* Speaker pill — colored avatar + caret, native select overlaid */
.turn-speaker-pill {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0.15rem 0.3rem 0.15rem 0.15rem;
  margin-top: 0.1rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition);
}

.turn-speaker-pill:hover { border-color: var(--ring); }

.avatar-sm { width: 22px; height: 22px; font-size: 0.66rem; }

.pill-caret { width: 13px; height: 13px; color: var(--muted-foreground); pointer-events: none; }

/* Transparent native select covers the whole pill */
.turn-speaker {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* Vertical rule between speaker and text */
.turn-rule {
  flex-shrink: 0;
  width: 2px;
  align-self: stretch;
  min-height: 1.7rem;
  background: var(--border);
  border-radius: 2px;
}

/* Inline text — borderless, auto-grow */
.turn-text {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0.2rem 0.1rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--foreground);
  resize: none;
  overflow: hidden;
}

.turn-text:focus { outline: none; }
.turn-text::placeholder { color: var(--muted-foreground); opacity: 0.6; }

/* Remove button reveals on row hover/focus */
.turn-row .remove-turn {
  opacity: 0;
  margin-top: 0.15rem;
  transition: opacity var(--transition);
}

.turn-row:hover .remove-turn,
.turn-row:focus-within .remove-turn { opacity: 1; }

/* ── Actions bar ───────────────────────────────────────────────── */
.actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* ── Error ─────────────────────────────────────────────────────── */
.error {
  padding: 0.7rem 0.85rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--destructive);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

/* ── Player ────────────────────────────────────────────────────── */
.player-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-top: 0.5rem;
}

.player-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.player-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--success-foreground);
  background: var(--success);
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
}

.player-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--foreground);
}

#audio-player {
  width: 100%;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-sm);
}

#download-btn { margin-top: 0.25rem; }

/* ── Spinner ───────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 1.1em; height: 1.1em;
  border: 2.5px solid rgba(247,250,248,.3);
  border-top-color: var(--primary-foreground);
  border-radius: 50%;
  animation: spin .55s linear infinite;
  vertical-align: middle;
  margin-left: 0.3rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* hidden attribute must override display utilities */
[hidden] { display: none !important; }

/* ── Mobile toggle ─────────────────────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 60;
  width: 44px; height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16,24,32,.06);
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: 0 4px 24px rgba(16,24,32,.12);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }

  .main-header { padding: 0.9rem 1rem; }
  .main-body { padding: 1rem 1rem; }
  .main-footer { padding: 0.8rem 1rem; }

  .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .section-actions { width: 100%; justify-content: space-between; }

  /* Touch: always show remove button */
  .turn-row .remove-turn { opacity: 1; }
}
