/* VieVoice — giao diện chính (v2: app shell + sidebar, gọn + mở rộng được) */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef1f4;
  --text: #1d2733;
  --muted: #5d6b7a;
  --border: #d8dee5;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #e3f2f0;
  --navy: #0f2a33;
  --navy-deep: #0b3d3a;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 42, 67, 0.08), 0 4px 14px rgba(16, 42, 67, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* [hidden] phải thắng mọi display riêng (vd .nav-badge dùng inline-flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ================= App shell ================= */
.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ================= Sidebar ================= */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  background: linear-gradient(180deg, var(--navy-deep) 0%, var(--navy) 100%);
  color: #fff;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}
.brand-mark {
  width: 42px; height: 42px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  font-size: 23px; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; opacity: 0.75; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; }
.nav-section {
  margin: 14px 8px 6px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
}
.nav-section:first-child { margin-top: 0; }
.nav-section-note { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.7; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 10px;
  font: inherit; font-size: 14px; font-weight: 600;
  color: #fff;
  background: transparent;
  border: none; border-radius: 9px;
  cursor: pointer; text-align: left;
  transition: background 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.09); }
.nav-item.is-active { background: rgba(255, 255, 255, 0.16); box-shadow: inset 3px 0 0 #2dd4bf; }
.nav-icon { width: 18px; text-align: center; opacity: 0.85; flex: none; }
.nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  min-width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 6px;
  background: #2dd4bf; color: #07332f;
  border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.nav-tag {
  font-size: 10px; font-weight: 600;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
}
.nav-item.is-future { opacity: 0.55; cursor: not-allowed; }
.nav-item.is-future:hover { background: transparent; }

.sidebar-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.14); }
.sidebar-status { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: #a7f3d0; }
.sidebar-note { margin: 0; font-size: 12px; line-height: 1.5; opacity: 0.7; }

/* ================= Topbar ================= */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
  background: rgba(244, 246, 248, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.page-title { margin: 0; font-size: 21px; }
.status-pill {
  flex: none;
  font-size: 13px; font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-pill.is-ready { background: var(--accent-soft); color: var(--accent-dark); border-color: var(--accent); }
.status-pill.is-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ================= Content ================= */
.content {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 28px 8px;
  flex: 1;
}
.panel-title { margin: 0; font-size: 19px; }

/* ---- Studio grid: 2 cột desktop, 1 cột hẹp ---- */
.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}
.studio-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.studio-side {
  position: sticky; top: 76px;
  display: flex; flex-direction: column; gap: 20px;
  min-width: 0;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }

/* ---- Fields ---- */
.field-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 8px;
}
.field-head label, .field-label { font-weight: 600; font-size: 15px; }
.char-count, .voice-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Voice picker (gọn) ---- */
.voice-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%;
  padding: 12px 14px;
  font: inherit; text-align: left;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.voice-summary:hover:not(:disabled) { border-color: var(--accent); }
.voice-summary:disabled { cursor: wait; opacity: 0.75; }
.voice-summary-main { display: flex; flex-direction: column; min-width: 0; }
.voice-summary-name { font-weight: 700; font-size: 15px; }
.voice-summary-desc { color: var(--muted); font-size: 13px; }
.voice-summary-action {
  flex: none;
  color: var(--accent-dark);
  font-size: 13px; font-weight: 700;
  white-space: nowrap;
}
.voice-picker { margin-top: 12px; }
#voice-search {
  width: 100%;
  padding: 10px 12px;
  font: inherit; font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: var(--surface);
}
#voice-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.filter-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.filter-label { flex: none; width: 74px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.voice-list {
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
  display: flex; flex-direction: column; gap: 6px;
}
.voice-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.voice-row:hover { border-color: var(--accent); }
.voice-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.voice-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.voice-row:has(input:checked) .voice-name { color: var(--accent-dark); }
.voice-row:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.voice-name { font-weight: 600; font-size: 15px; white-space: nowrap; }
.voice-desc { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-empty { margin: 10px 0 0; }

/* ---- Status / progress ---- */
.status-line { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.spinner.stopped { animation: none; border-top-color: var(--border); }
@keyframes spin { to { transform: rotate(360deg); } }
.progress {
  height: 8px;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.status-detail { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.error-text {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  font-size: 14px;
}

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-size: 16px; font-weight: 600;
  border: none; border-radius: 10px;
  padding: 13px 22px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:not(:disabled):hover { background: var(--accent-dark); }
.btn-generate { font-size: 17px; padding: 14px 22px; }
.btn-secondary {
  background: var(--surface);
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  margin-top: 10px;
  padding: 9px 18px;
  font-size: 15px;
}
.btn-secondary:hover { background: var(--accent-soft); }
.btn-small {
  padding: 7px 14px;
  font-size: 14px;
  border-radius: 8px;
  width: auto;
}

/* ---- Result ---- */
#audio-player { width: 100%; margin-bottom: 14px; }
.result-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0 0 16px;
  font-size: 15px;
}
.result-meta dt { color: var(--muted); }
.result-meta dd { margin: 0; font-weight: 600; }
.result-actions .btn { width: auto; }

/* ---- Info card ---- */
.info-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.info-list li { margin-bottom: 6px; }
.info-list li:last-child { margin-bottom: 0; }

/* ---- History ---- */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.history-text { font-weight: 600; }
.history-meta { color: var(--muted); font-size: 13px; }
.history-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- Footer ---- */
.site-footer {
  margin: 24px 0 28px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 0 28px;
}
.site-footer p { margin: 0 auto; max-width: 720px; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .studio-grid { grid-template-columns: minmax(0, 1fr); }
  .studio-side { position: static; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px 14px 10px;
    overflow: visible;
  }
  .sidebar-brand { padding-bottom: 12px; }
  .sidebar-foot { display: none; }
  .sidebar-nav {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .nav-section { display: none; }
  .nav-item { width: auto; flex: none; padding: 8px 12px; font-size: 14px; }
  .nav-item.is-active { box-shadow: none; }
  .nav-tag { display: none; }
  .topbar { padding: 12px 16px; }
  .page-title { font-size: 19px; }
  .content { padding: 14px 14px 4px; }
  .card { padding: 16px; }
  .filter-row { align-items: flex-start; flex-direction: column; gap: 6px; }
  .filter-label { width: auto; }
  .voice-list { max-height: 280px; }
  .voice-desc { white-space: normal; }
  .result-actions .btn { width: 100%; }
  .result-meta { grid-template-columns: 1fr; gap: 0; }
  .result-meta dd { margin-bottom: 8px; }
  .site-footer { padding: 0 16px; }
}
