:root {
  --bg: #f3f5f9;
  --bg-elevated: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --panel-hover: #e8edf5;
  --border: #d5dbe6;
  --border-soft: #e4e8f0;
  --text: #1a2332;
  --muted: #5c6b7f;
  --muted-2: #8b97a8;
  --accent: #4f6ef7;
  --accent-2: #3b57e0;
  --accent-soft: rgba(79, 110, 247, 0.12);
  --ok: #0d9f6e;
  --ok-soft: rgba(13, 159, 110, 0.1);
  --warn: #b87a12;
  --warn-soft: rgba(184, 122, 18, 0.1);
  --err: #d64550;
  --err-soft: rgba(214, 69, 80, 0.1);
  --teal: #0d9f8c;
  --teal-2: #0b8a7a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --space: 16px;
  --toolbar-gap: 12px;
  --cell-x: 14px;
  --row-gap: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 480px at 6% -10%, rgba(79, 110, 247, 0.08) 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(13, 159, 140, 0.06) 0%, transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── App shell ── */
.app {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 14px var(--space) 20px;
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--toolbar-gap);
  overflow: hidden;
}

/* ── Header ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sub {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.health {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.3;
}

.health.ok {
  color: var(--ok);
  border-color: rgba(13, 159, 110, 0.35);
  background: var(--ok-soft);
}

.health.bad {
  color: var(--err);
  border-color: rgba(214, 69, 80, 0.35);
  background: var(--err-soft);
}

/* ── Shared panel ── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
}

.panel h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/*
  Main workspace — 2 cột + 5 hàng subgrid:
  1 head | 2 title | 3 sapo | 4 body | 5 foot
*/
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto minmax(160px, 1fr) auto;
  column-gap: var(--toolbar-gap);
  row-gap: 0;
  align-items: stretch;
}

.panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.lang-chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(79, 110, 247, 0.28);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
  margin-left: 8px;
  vertical-align: middle;
}

/* Cột trái: subgrid 5 hàng (head / title / sapo / body / foot) */
.source {
  display: grid;
  grid-template-rows: subgrid;
  grid-row: 1 / -1;
  min-height: 0;
  overflow: hidden;
  gap: 0;
}

/* Cột phải: 1 khối bài dịch gộp (không tách 3 ô) */
.result {
  display: flex;
  flex-direction: column;
  grid-row: 1 / -1;
  min-height: 0;
  overflow: hidden;
  gap: 0;
}

/* Direct children padding */
.source > *,
.result > * {
  min-width: 0;
  min-height: 0;
  padding-left: var(--cell-x);
  padding-right: var(--cell-x);
}

/* --- Kết quả EN: 1 ô article (giống trang Nhận xét) --- */
.result-article-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  padding-bottom: 12px;
  /* Không absolute / z-index — không đè meta trong panel-head */
  position: relative;
  z-index: 0;
}

.result .meta {
  margin-top: 4px;
  line-height: 1.45;
  word-break: break-word;
  white-space: normal;
  max-width: 100%;
}

.result-article {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  user-select: text;
  cursor: text;
}

.result-article.empty .result-article-title,
.result-article.empty .result-article-sapo,
.result-article.empty .result-article-body {
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
}

/* Title: HOA + đậm */
.result-article-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Sapo: đậm */
.result-article-sapo {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Body: regular */
.result-article-body {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1 1 auto;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 2px;
}

.panel-head-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-head {
  flex-direction: column;
  align-items: stretch;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  background: var(--bg-elevated, #fff);
}

.result-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Giọng đọc + Nhận xét: xếp dọc, Nhận xét dưới Giọng đọc */
.result-head-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  flex-shrink: 0;
}

.btn-tts-open,
.btn-feedback-open {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.82rem;
  min-width: 112px;
}

.btn-feedback-open {
  min-width: 112px;
}

.panel-foot {
  padding-top: 6px;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.panel-foot-empty {
  min-height: 0;
  padding-top: 0;
}

/* ── TTS badges (modal) ── */
.tts-badge {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #6366f1);
}

.tts-badge.vi {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.tts-badge.en {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  box-shadow: 0 4px 12px rgba(79, 110, 247, 0.28);
}

.tts-badge.lang-pair {
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  width: 44px;
  height: 36px;
}

.tts-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tts-actions .btn.accent {
  flex: 1 1 auto;
  min-width: 120px;
}

.tts-actions .btn.ghost {
  flex: 0 0 auto;
}

.tts-voice-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
}

.tts-voice-row select {
  flex: 1 1 160px;
  min-width: 0;
}

.tts-voice-row #btnTtsPreview {
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 40px;
}

/* ── Modal overlay (TTS popup) ── */
body.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: modal-fade 0.16s ease;
}

.modal-overlay[hidden] {
  display: none !important;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(440px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(255, 255, 255, 0.8) inset;
  animation: modal-pop 0.18s ease;
}

@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.modal-title-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.modal-title-wrap h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.modal-title-wrap .hint {
  margin-top: 3px;
}

.btn-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
}
/* X luôn click được (kể cả phase loading) */
.btn-icon:disabled {
  opacity: 1;
  cursor: pointer;
  pointer-events: auto;
}

.btn-icon:hover {
  background: var(--panel-2);
  color: var(--text);
}

.modal-body {
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body .field {
  height: auto;
}

/* ── Translate modal phases ── */
.modal-translate {
  width: min(420px, 100%);
}

.translate-phase[hidden] {
  display: none !important;
}

.translate-loading,
.translate-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 18px 8px 10px;
}

.translate-loading-title,
.translate-success-title {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border-soft);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-track {
  width: 100%;
  height: 6px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.progress-bar {
  height: 100%;
  width: 8%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  transition: width 0.35s ease;
}

.success-check {
  width: 64px;
  height: 64px;
}

.success-svg {
  width: 64px;
  height: 64px;
  display: block;
}

.success-circle {
  stroke: var(--ok);
  stroke-width: 2.5;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
}

.success-path {
  stroke: var(--ok);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
}

.translate-phase.play .success-circle {
  animation: success-circle 0.55s ease forwards;
}

.translate-phase.play .success-path {
  animation: success-check 0.35s 0.4s ease forwards;
}

@keyframes success-circle {
  to { stroke-dashoffset: 0; }
}

@keyframes success-check {
  to { stroke-dashoffset: 0; }
}

/* Reveal kết quả cột phải sau khi dịch */
.result.result-reveal {
  animation: result-pop 0.55s ease;
}

.result.result-reveal .out-text:not(.empty),
.result.result-reveal .result-article:not(.empty) {
  animation: result-fade-in 0.45s ease both;
}

@keyframes result-pop {
  0% { box-shadow: var(--shadow); }
  40% { box-shadow: 0 0 0 3px var(--accent-soft), 0 12px 32px rgba(79, 110, 247, 0.18); }
  100% { box-shadow: var(--shadow); }
}

@keyframes result-fade-in {
  from {
    opacity: 0.35;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  .translate-phase.play .success-circle,
  .translate-phase.play .success-path,
  .result.result-reveal,
  .result.result-reveal .out-text:not(.empty),
  .result.result-reveal .result-article:not(.empty) {
    animation: none !important;
  }
  .success-circle,
  .success-path {
    stroke-dashoffset: 0;
  }
}

/* ── Fields (workspace cells) ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.field > span {
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* Title row: fixed compact height, both sides match */
.field-title {
  padding-top: var(--row-gap);
}

.field-title input[type="text"],
.field-title .out-text {
  min-height: 42px;
  height: 42px;
  flex: 0 0 auto;
  overflow: auto;
}

/* Sapo row: both sides share same row height */
.field-sapo {
  padding-top: var(--row-gap);
}

.field-sapo textarea,
.field-sapo .out-text {
  flex: 1 1 auto;
  min-height: 84px;
  height: 100%;
  resize: none;
  overflow: auto;
}

/* Body row: takes remaining shared height */
.field-body {
  padding-top: var(--row-gap);
  padding-bottom: 4px;
}

.field-body textarea,
.field-body .out-text {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  resize: none;
  overflow: auto;
}

input[type="text"],
textarea,
select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

textarea {
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

input:hover,
textarea:hover,
select:hover {
  background: var(--panel-hover);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--panel-2);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c6b7f' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Range controls ── */
.pct-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pct-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

.pct-row output {
  min-width: 44px;
  text-align: right;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted-2);
  line-height: 1.4;
}

.hint code {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ── Counts / meta ── */
.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 0.74rem;
  color: var(--muted);
  align-items: center;
}

.counts span,
.counts strong {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
}

.counts strong {
  color: var(--text);
  border-color: rgba(79, 110, 247, 0.35);
  background: var(--accent-soft);
}

.meta {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.meta b {
  color: var(--text);
  font-weight: 600;
}

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  line-height: 1.2;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 110, 247, 0.28);
  min-width: 88px;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.accent {
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(20, 184, 166, 0.22);
  min-width: 112px;
}

.btn.accent:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--muted-2);
}

.btn.is-loading {
  opacity: 0.85;
  cursor: wait;
  pointer-events: none;
}

/* ── Status / TTS ── */
.status {
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  line-height: 1.4;
}

.status.loading {
  color: var(--warn);
  border-color: rgba(240, 180, 41, 0.35);
  background: var(--warn-soft);
}

.status.error {
  color: var(--err);
  border-color: rgba(240, 113, 120, 0.35);
  background: var(--err-soft);
}

.status.ok {
  color: var(--ok);
  border-color: rgba(62, 207, 142, 0.35);
  background: var(--ok-soft);
}

.tts-player {
  padding-top: 2px;
}

.tts-player audio {
  width: 100%;
  height: 40px;
  border-radius: 8px;
}

/* ── Output blocks ── */
.out-text {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 0.92rem;
  overflow: auto;
  min-height: 42px;
}

.out-text.empty {
  color: var(--muted-2);
  font-style: italic;
}

.out-text.muted {
  color: var(--muted);
  font-size: 0.86rem;
  font-style: normal;
}

/* ── Summary details ── */
.summary-vi {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--bg-elevated);
  max-height: 220px;
  overflow: auto;
}

.summary-vi summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.summary-vi summary::-webkit-details-marker {
  display: none;
}

.summary-vi summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.75rem;
  transition: transform 0.15s ease;
}

.summary-vi[open] summary::before {
  transform: rotate(90deg);
}

.summary-vi[open] summary {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border-soft);
}

.out-block + .out-block {
  margin-top: 10px;
}

.out-block h4 {
  margin: 0 0 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
}

/* ── Responsive ── */
@media (max-width: 960px) {
  .app {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .layout {
    display: flex;
    flex-direction: column;
    flex: none;
    gap: var(--toolbar-gap);
    grid-template-rows: none;
  }

  .source,
  .result {
    display: flex;
    flex-direction: column;
    grid-row: auto;
    overflow: visible;
    min-height: 320px;
  }

  .source > *,
  .result > * {
    height: auto;
  }

  .result-article-wrap {
    min-height: 280px;
  }

  .result-article {
    min-height: 240px;
  }

  .field-title input[type="text"],
  .field-title .out-text {
    height: 42px;
  }

  .field-sapo textarea,
  .field-sapo .out-text {
    min-height: 84px;
    height: auto;
  }

  .field-body {
    flex: 1 1 auto;
    min-height: 180px;
  }

  .field-body textarea,
  .field-body .out-text {
    min-height: 180px;
    height: auto;
    resize: vertical;
  }
} /* end @media (max-width: 960px) */

@media (max-width: 640px) {
  .app {
    padding: 10px 12px 16px;
    gap: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .health {
    white-space: normal;
    text-align: right;
    max-width: 50%;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-head-actions {
    width: 100%;
  }

  .panel-head-actions .btn,
  .btn-tts-open {
    flex: 1;
    min-width: 0;
  }

  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: 88vh;
    border-radius: 16px 16px 12px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* ── Feedback page: 3 cửa sổ ngang (như Asko Translate) ──
   [ Bài gốc: Title/Sapo/Body ] | [ Kết quả dịch 1 ô ] | [ Nhận xét 1 ô ]
*/
body.feedback-page {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(900px 480px at 6% -10%, rgba(79, 110, 247, 0.08) 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(13, 159, 140, 0.06) 0%, transparent 50%),
    var(--bg);
}

body.feedback-page .feedback-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 14px var(--space) 16px;
  height: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-sizing: border-box;
  overflow: hidden;
}

body.feedback-page .feedback-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

body.feedback-page .feedback-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

body.feedback-page .muted-chip {
  color: var(--muted);
  background: var(--panel-2);
  border-color: var(--border);
}

/* 3 cửa sổ ngang */
body.feedback-page .fb-windows {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--toolbar-gap);
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

body.feedback-page .fb-windows[hidden] {
  display: none !important;
}

/* Mỗi cửa sổ = panel Asko Translate (card trắng + shadow) */
body.feedback-page .fb-win {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

body.feedback-page .fb-win > .panel-head {
  flex-shrink: 0;
  padding-left: var(--cell-x);
  padding-right: var(--cell-x);
}

/*
  Cửa sổ 1: Title / Sapo / Body.
  Global .field { height:100% } là cho subgrid trang dịch — ở đây phải
  height:auto + flex, nếu không ô Title chiếm hết panel (Sapo/Body bị clip).
*/
body.feedback-page .fb-win-source {
  overflow: hidden;
}

body.feedback-page .fb-win-source > .field {
  padding-left: var(--cell-x);
  padding-right: var(--cell-x);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  height: auto !important; /* override .field { height: 100% } */
  max-height: none;
}

body.feedback-page .fb-win-source > .field-title {
  flex: 0 0 auto;
  padding-top: 10px;
}

body.feedback-page .fb-win-source > .field-title .out-text {
  height: 42px;
  min-height: 42px;
  flex: 0 0 auto;
  overflow: auto;
}

body.feedback-page .fb-win-source > .field-sapo {
  flex: 0 0 auto;
  min-height: 100px;
}

body.feedback-page .fb-win-source > .field-sapo .out-text {
  min-height: 80px;
  max-height: 140px;
  height: auto !important;
  flex: 0 0 auto;
  overflow: auto;
}

body.feedback-page .fb-win-source > .field-body {
  flex: 1 1 auto;
  min-height: 140px;
  padding-bottom: 12px;
}

body.feedback-page .fb-win-source > .field-body .out-text {
  flex: 1 1 auto;
  min-height: 120px;
  height: auto !important;
  overflow: auto;
}

body.feedback-page .fb-win-source .out-text {
  background: var(--bg-elevated);
}

/* Cửa sổ 2: 1 ô bài dịch gộp */
body.feedback-page .fb-article-wrap {
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px var(--cell-x) 14px;
  display: flex;
  flex-direction: column;
}

body.feedback-page .fb-article {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Title: viết HOA + in đậm */
body.feedback-page .fb-article-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Sapo: in đậm */
body.feedback-page .fb-article-sapo {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Body: giữ nguyên (regular) */
body.feedback-page .fb-article-body {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Cửa sổ 3: ô nhận xét */
body.feedback-page .fb-note-wrap {
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px var(--cell-x) 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.feedback-page .fb-note-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 160px;
  resize: none;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

body.feedback-page .fb-note-input:focus {
  border-color: rgba(79, 110, 247, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

body.feedback-page .fb-note-foot {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body.feedback-page .feedback-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

body.feedback-page .feedback-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 48px 20px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

body.feedback-page .feedback-empty[hidden] {
  display: none !important;
}

body.feedback-page .feedback-empty-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

@media (max-width: 900px) {
  body.feedback-page {
    overflow: auto;
  }

  body.feedback-page .feedback-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  body.feedback-page .fb-windows {
    grid-template-columns: 1fr !important;
    min-height: 0;
  }

  body.feedback-page .fb-win {
    min-height: 320px;
  }

  body.feedback-page .fb-win-source > .field-body {
    min-height: 160px;
  }
}
