@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ---------- Design tokens ---------- */
:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-2: #F1F5F9;
  --color-border: #E2E8F0;
  --color-text: #0F172A;
  --color-text-muted: #64748B;
  --color-text-faint: #94A3B8;

  --color-primary: #0F172A;
  --color-accent: #0369A1;
  --color-accent-hover: #075985;
  --color-accent-soft: #E0F2FE;

  --color-success: #16A34A;
  --color-success-hover: #15803D;
  --color-success-soft: #DCFCE7;

  --color-danger: #DC2626;
  --color-danger-soft: #FEF2F2;

  --color-info-text: #4338CA;
  --color-info-soft: #EEF2FF;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.10);

  --dur-fast: 150ms;
  --dur-base: 220ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* prefers-color-scheme chỉ áp dụng khi chưa có lựa chọn theme tường minh (:root[data-theme]) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0B1220;
    --color-surface: #111A2C;
    --color-surface-2: #18233A;
    --color-border: #223047;
    --color-text: #E7ECF3;
    --color-text-muted: #97A6BC;
    --color-text-faint: #6B7A93;

    --color-primary: #E7ECF3;
    --color-accent: #38BDF8;
    --color-accent-hover: #7DD3FC;
    --color-accent-soft: rgba(56, 189, 248, 0.14);

    --color-success: #4ADE80;
    --color-success-hover: #86EFAC;
    --color-success-soft: rgba(74, 222, 128, 0.14);

    --color-danger: #F87171;
    --color-danger-soft: rgba(248, 113, 113, 0.12);

    --color-info-text: #A5B4FC;
    --color-info-soft: rgba(99, 102, 241, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
  }
}

/* Lựa chọn theme tường minh (nút chuyển đổi) — thắng cả hai chiều so với hệ thống */
:root[data-theme="dark"] {
  --color-bg: #0B1220;
  --color-surface: #111A2C;
  --color-surface-2: #18233A;
  --color-border: #223047;
  --color-text: #E7ECF3;
  --color-text-muted: #97A6BC;
  --color-text-faint: #6B7A93;

  --color-primary: #E7ECF3;
  --color-accent: #38BDF8;
  --color-accent-hover: #7DD3FC;
  --color-accent-soft: rgba(56, 189, 248, 0.14);

  --color-success: #4ADE80;
  --color-success-hover: #86EFAC;
  --color-success-soft: rgba(74, 222, 128, 0.14);

  --color-danger: #F87171;
  --color-danger-soft: rgba(248, 113, 113, 0.12);

  --color-info-text: #A5B4FC;
  --color-info-soft: rgba(99, 102, 241, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

/* Utility ẩn phần tử chung cho cả trang - các rule .xxx.is-hidden bên dưới (scoped riêng từng component)
   vẫn giữ nguyên, không xung đột vì cùng là display:none. */
.is-hidden { display: none; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
}

::selection { background: var(--color-accent-soft); }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
  font-weight: 600;
  font-size: 14px;
}
.skip-link:focus { left: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Shell layout ---------- */
.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 80px;
  display: flex;
  align-items: flex-start;
  gap: 36px;
}

.sidebar {
  position: sticky;
  top: 24px;
  width: 252px;
  flex-shrink: 0;
  display: none;
}

.brand {
  padding: 4px 4px 20px;
}
.brand-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.brand-subtitle {
  font-size: 12.5px;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.5;
}

.stepper { list-style: none; margin: 0; padding: 0; }

.stepper-item { position: relative; }
.stepper-item + .stepper-item { margin-top: 2px; }

.stepper-item::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 34px;
  width: 2px;
  height: calc(100% - 20px);
  background: var(--color-border);
}
.stepper-item:last-child::before { display: none; }

.stepper-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  color: var(--color-text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.stepper-link:hover { background: var(--color-surface-2); }

.stepper-dot {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-text-faint);
  transition: all var(--dur-base) var(--ease);
}
.stepper-dot svg { width: 15px; height: 15px; }

.stepper-label {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}

.stepper-item.is-current .stepper-link { color: var(--color-text); }
.stepper-item.is-current .stepper-dot {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  box-shadow: 0 0 0 4px var(--color-accent-soft);
}

.stepper-item.is-done .stepper-dot {
  background: var(--color-success-soft);
  border-color: var(--color-success);
  color: var(--color-success);
}
.stepper-item.is-done .stepper-link { color: var(--color-text); }

.stepper-item.is-locked .stepper-link { cursor: not-allowed; pointer-events: none; opacity: 0.55; }

.stepper-item.is-neutral .stepper-dot { color: var(--color-text-muted); }

/* ---------- Main column ---------- */
.main-col { flex: 1; min-width: 0; max-width: 720px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  padding: 16px 0 12px;
  margin-bottom: 8px;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.topbar-title { font-size: 16px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.topbar-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.topbar-step-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-accent);
  background: var(--color-accent-soft);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.topbar-action {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.topbar-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
.topbar-action-icon svg { width: 16px; height: 16px; }
.topbar-action-label { min-width: 0; font-size: 12.5px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.topbar-action-copy { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.topbar-action-meta { margin-top: 1px; color: var(--color-text-muted); font-size: 10.5px; line-height: 1.2; white-space: nowrap; }
.topbar-action:hover { border-color: var(--color-accent); background: var(--color-accent-soft); }
.topbar-action:hover .topbar-action-icon { color: var(--color-accent-hover); background: var(--color-surface); }
.topbar-action:active { background: var(--color-surface-2); }
.topbar-action:focus-visible { outline: 3px solid color-mix(in srgb, var(--color-accent) 35%, transparent); outline-offset: 2px; }
.topbar-progress-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  overflow: hidden;
}
.topbar-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--color-accent), var(--color-success));
  transition: width var(--dur-base) var(--ease);
}

@media (min-width: 960px) {
  .app-shell { padding-top: 32px; }
  .sidebar { display: block; }
  .topbar { position: static; backdrop-filter: none; background: none; padding-top: 0; }
  .topbar-title { display: none; }
}

@media (max-width: 520px) {
  .topbar-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-action-theme { grid-column: 1 / -1; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: opacity var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
  scroll-margin-top: 90px;
}

.step.locked {
  opacity: 0.5;
  pointer-events: none;
}

.step-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.step-head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.step-head-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.step-num {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
}

.card h2 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.step-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}
.step-badge svg { width: 12px; height: 12px; }
.step-badge.is-current { background: var(--color-accent-soft); color: var(--color-accent-hover); }
.step-badge.is-done { background: var(--color-success-soft); color: var(--color-success-hover); }

.hint {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 6px 0 14px;
  line-height: 1.55;
}

.step-model {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-text-faint);
  background: var(--color-surface-2);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  display: inline-block;
}

/* ---------- Form elements ---------- */
label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--color-text);
}

input[type="text"], input[type="password"], input[type="file"], textarea, select {
  width: 100%;
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  resize: vertical;
  margin-bottom: 12px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
textarea { line-height: 1.55; }

input[type="text"]::placeholder, input[type="password"]::placeholder, textarea::placeholder { color: var(--color-text-faint); }

input[type="text"]:hover, input[type="password"]:hover, input[type="file"]:hover, textarea:hover, select:hover:not(:disabled) { border-color: var(--color-text-faint); }

input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

/* Select: bỏ chrome mặc định của trình duyệt, thay bằng mũi tên SVG tự vẽ để khớp theme sáng/tối */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
select:disabled { cursor: not-allowed; opacity: 0.6; }
select[multiple] {
  appearance: auto;
  -webkit-appearance: auto;
  -moz-appearance: auto;
  background-image: none;
  padding: 6px;
}
select[multiple] option { padding: 6px 8px; border-radius: var(--radius-sm); }

input[type="file"] { padding: 8px 12px; cursor: pointer; }
input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  margin-right: 10px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
input[type="file"]::file-selector-button:hover { background: var(--color-accent-soft); color: var(--color-accent-hover); }

.field-note {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin: 16px 0 4px;
  color: var(--color-text);
}

/* ---------- Buttons ---------- */
button { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.btn:active { transform: scale(0.97); }

.btn-run, .btn-primary {
  background: var(--color-primary);
  color: var(--color-bg);
}
.btn-run:hover, .btn-primary:hover { background: var(--color-accent-hover); }

.btn-approve {
  background: var(--color-success);
  color: #fff;
  margin-top: 10px;
}
.btn-approve:hover { background: var(--color-success-hover); }

.btn-run:disabled, .btn-approve:disabled {
  background: var(--color-surface-2);
  color: var(--color-text-faint);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.step2-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.step2-actions .btn { margin-top: 0; }

.btn-ghost {
  background: transparent;
  color: var(--color-accent-hover);
  border: 1.5px solid var(--color-border);
}
.btn-ghost:hover { border-color: var(--color-accent); background: var(--color-accent-soft); }
.btn-ghost:disabled {
  background: transparent;
  color: var(--color-text-faint);
  border-color: var(--color-border);
  cursor: not-allowed;
}

/* ---------- Output area ---------- */
.output-wrap { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--color-border); }

.output-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.output-header label { margin-bottom: 0; }

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

.view-toggle {
  display: inline-flex;
  background: var(--color-surface-2);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.view-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.view-toggle-btn svg { width: 13px; height: 13px; }
.view-toggle-btn.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.view-toggle-btn:hover:not(.is-active) { color: var(--color-text); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-text-faint); }

.btn-copy .btn-icon-success { display: none; color: var(--color-success); }
.btn-copy.is-copied { border-color: transparent; background: var(--color-success-soft); }
.btn-copy.is-copied .btn-icon-default { display: none; }
.btn-copy.is-copied .btn-icon-success { display: inline-flex; }

/* ---------- Yêu cầu chỉnh sửa theo prompt ---------- */
.refine-box { margin-top: 4px; }
.refine-row { display: flex; gap: 8px; align-items: center; }
.refine-input {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}
.btn-refine { background: var(--color-surface-2); }
.btn-refine:hover { background: var(--color-accent-soft); color: var(--color-accent-hover); border-color: transparent; }

/* ---------- Panel cấu hình phụ (chọn dự án/ngôn ngữ ở Bước 0, chọn bài plan ở Bước 1) ---------- */
.settings-panel {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin: 4px 0 18px;
}
.settings-panel.is-hidden { display: none; }
.settings-panel > label:first-child { margin-top: 0; }
.settings-panel .hint:last-child { margin-bottom: 0; }
.settings-panel .form-grid { margin-bottom: 0; }

.settings-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.settings-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 3px;
}
.settings-panel-subtitle {
  font-size: 12.5px;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.5;
  max-width: 460px;
}
.btn-projects-link {
  flex-shrink: 0;
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
  border-color: transparent;
  white-space: nowrap;
  text-decoration: none;
}
.btn-projects-link:hover { background: var(--color-accent); color: #fff; }

/* ---------- Ảnh minh họa (bước 7) ---------- */
.image-gen-section { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--color-border); }
.image-gen-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.image-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin: 12px 0 14px;
}
.image-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--color-surface);
}
.image-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.image-card-position { font-size: 12.5px; font-weight: 700; color: var(--color-text-muted); line-height: 1.4; }
.image-card-prompt { margin-bottom: 0; font-size: 13.5px; min-height: 56px; }
.image-card-status { font-size: 12.5px; color: var(--color-text-muted); min-height: 0; }
.image-card-status.error { color: var(--color-danger); }
.image-card-status:empty { display: none; }

.image-card-result { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.image-card-result.is-hidden { display: none; }
.image-card-img { width: 100%; border-radius: var(--radius-md); border: 1px solid var(--color-border); display: block; }
.image-card-edit-row { display: flex; gap: 6px; align-items: center; }
.image-card-edit-input { flex: 1; min-width: 0; margin-bottom: 0; font-size: 13px; padding: 8px 10px; }
.image-card-download { text-align: center; font-size: 13px; padding: 8px 14px; }

/* ---------- Output preview/edit ---------- */
.output-body { position: relative; }
.output-textarea.is-hidden { display: none; }

.md-preview {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  background: var(--color-bg);
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--color-text);
  overflow-x: auto;
}
.md-preview.is-hidden { display: none; }
.md-preview > *:first-child { margin-top: 0 !important; padding-top: 0 !important; border-top: none !important; }
.md-preview > *:last-child { margin-bottom: 0; }
.md-preview:empty::before {
  content: 'Chưa có nội dung.';
  color: var(--color-text-faint);
  font-style: italic;
}

.md-preview h1, .md-preview h2, .md-preview h3, .md-preview h4, .md-preview h5, .md-preview h6 {
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin: 22px 0 10px;
}
.md-preview h1 { font-size: 19px; }
.md-preview h2 { font-size: 16.5px; padding-top: 14px; border-top: 1px solid var(--color-border); }
.md-preview h3 { font-size: 14.5px; color: var(--color-accent-hover); }
.md-preview h4, .md-preview h5, .md-preview h6 { font-size: 13.5px; }

.md-preview p { margin: 0 0 12px; }
.md-preview strong { font-weight: 700; color: var(--color-text); }
.md-preview em { font-style: italic; }

.md-preview ul, .md-preview ol { margin: 0 0 12px; padding-left: 22px; }
.md-preview li { margin-bottom: 5px; }

.md-preview hr { border: none; border-top: 1px dashed var(--color-border); margin: 20px 0; }

.md-preview blockquote {
  margin: 0 0 12px;
  padding: 8px 14px;
  border-left: 3px solid var(--color-accent);
  background: var(--color-accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-muted);
}

.md-preview code {
  background: var(--color-surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.md-preview pre {
  background: var(--color-surface-2);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0 0 12px;
}
.md-preview pre code { background: none; padding: 0; }

.md-preview a { color: var(--color-accent-hover); text-decoration: underline; text-underline-offset: 2px; }
.md-preview a:hover { color: var(--color-accent); }

.md-table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.md-preview table { width: 100%; border-collapse: collapse; font-size: 13px; }
.md-preview th, .md-preview td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.md-preview th { background: var(--color-surface-2); font-weight: 700; white-space: nowrap; }
.md-preview tr:last-child td { border-bottom: none; }

/* ---------- Modal đọc toàn màn hình ---------- */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(2px);
}
.fullscreen-modal[hidden] { display: none; }

.fullscreen-modal-panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  width: min(820px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.fullscreen-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.fullscreen-modal-header h2 { margin: 0; font-size: 15px; font-weight: 700; }
.fullscreen-modal-body { padding: 20px 24px; overflow-y: auto; }
.fullscreen-modal-body .md-preview { border: none; padding: 0; background: none; margin: 0; }

body.modal-open { overflow: hidden; }

/* ---------- Lịch sử ---------- */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}
.history-item-main { min-width: 0; }
.history-item-keyword {
  margin: 0 0 3px;
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item-meta { margin: 0; font-size: 12px; color: var(--color-text-muted); }
.history-item-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.history-resume-btn { padding: 7px 14px; font-size: 13px; white-space: nowrap; }

@media (max-width: 640px) {
  .fullscreen-modal { padding: 0; }
  .fullscreen-modal-panel { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
}

/* ---------- Status messages ---------- */
.status-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
}
.status-msg svg { width: 16px; height: 16px; flex-shrink: 0; }
.status-msg.loading { background: var(--color-info-soft); color: var(--color-info-text); }
.status-msg.error { background: var(--color-danger-soft); color: var(--color-danger); }

.spin { animation: spin 0.85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Footer ---------- */
.app-footer {
  max-width: 720px;
  margin: 12px auto 0;
  padding-top: 12px;
  color: var(--color-text-faint);
  font-size: 12px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .card { padding: 18px 16px; border-radius: var(--radius-md); }
  .app-shell { padding: 0 14px 60px; }
  .btn { width: 100%; }
  .step-badge { display: none; }
}

/* ---------- Đăng nhập quản lý dự án ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-sm);
}
.login-card h1 { font-size: 18px; margin: 0 0 6px; }

/* ---------- Trang quản lý Dự án ---------- */
.projects-shell { max-width: 980px; margin: 0 auto; padding: 24px 20px 80px; }
.projects-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}
.projects-topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.projects-main .card h2 { font-size: 16px; margin: 0 0 4px; }

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.project-list-item:hover { border-color: var(--color-accent); background: var(--color-accent-soft); }
.project-list-item svg { width: 16px; height: 16px; color: var(--color-text-faint); flex-shrink: 0; }
.project-list-name { font-weight: 700; margin: 0 0 2px; }
.project-list-meta { font-size: 12.5px; color: var(--color-text-muted); margin: 0; }

.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.inline-form input[type="text"], .inline-form input[type="file"] { margin-bottom: 0; flex: 1; min-width: 200px; }

.edit-panel {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px;
  margin: 14px 0;
  background: var(--color-surface-2);
}
.edit-panel.is-hidden { display: none; }
.edit-panel h3 { font-size: 14px; margin: 0 0 12px; }
.edit-panel-actions { display: flex; gap: 10px; margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid > div { min-width: 0; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.prompt-user-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13.5px;
  margin: 10px 0;
}
.checkbox-label input { margin: 0; }

/* ---------- Badge dùng chung ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.count-pill {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

/* ---------- Internal Link Rule: nhóm theo Cluster / Pillar ---------- */
.rule-groups { display: flex; flex-direction: column; gap: 22px; margin-top: 16px; }
.rule-group-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.rule-group-badge-cluster { background: var(--color-accent-soft); color: var(--color-accent-hover); font-size: 12.5px; padding: 5px 12px; }
.rule-group-badge-pillar { background: var(--color-success-soft); color: var(--color-success-hover); font-size: 12.5px; padding: 5px 12px; }
.rule-group-badge-both { background: var(--color-info-soft); color: var(--color-info-text); font-size: 12.5px; padding: 5px 12px; }

.rule-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}
.rule-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--color-surface);
}
.rule-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.rule-card-name { font-weight: 700; font-size: 13.5px; line-height: 1.4; }
.rule-card-actions { display: flex; gap: 4px; flex-shrink: 0; }
.rule-card-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-mandatory { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-optional { background: var(--color-surface-2); color: var(--color-text-muted); }
.badge-context { background: var(--color-info-soft); color: var(--color-info-text); }
.badge-dynamic { background: var(--color-accent-soft); color: var(--color-accent-hover); }
.rule-card-detail { font-size: 12.5px; color: var(--color-text-muted); margin: 0; line-height: 1.5; word-break: break-word; }
.rule-card-detail strong { color: var(--color-text); font-weight: 600; }
.rule-card-url { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 11.5px; }

/* ---------- Content Plan: nhóm theo Nhóm nội dung (accordion) ---------- */
.content-groups { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.content-groups-toolbar { display: flex; justify-content: flex-end; margin-bottom: 2px; }

.content-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
}
.content-group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  font-weight: 700;
  font-size: 13.5px;
  background: var(--color-surface-2);
}
.content-group > summary::-webkit-details-marker { display: none; }
.content-group > summary::before {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(-45deg);
  transition: transform var(--dur-fast) var(--ease);
  flex-shrink: 0;
  margin-right: 2px;
}
.content-group[open] > summary::before { transform: rotate(45deg); }
.content-group > summary > span:first-child { flex: 1; display: flex; align-items: center; gap: 8px; }
.content-group-count { font-weight: 600; font-size: 11.5px; color: var(--color-text-muted); background: var(--color-surface); padding: 3px 10px; border-radius: var(--radius-pill); flex-shrink: 0; }

.content-group-body { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 4px; }

.plan-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
}
.plan-item:hover { background: var(--color-surface-2); }
.plan-item-pillar { background: var(--color-accent-soft); }
.plan-item-pillar:hover { background: var(--color-accent-soft); filter: brightness(0.97); }
.badge-pillar { background: var(--color-success); color: #fff; flex-shrink: 0; }
.badge-cluster { background: var(--color-surface-2); color: var(--color-text-muted); flex-shrink: 0; }
.plan-item-main { flex: 1; min-width: 0; }
.plan-item-title {
  font-weight: 600;
  font-size: 13px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plan-item-meta { font-size: 11.5px; color: var(--color-text-muted); margin: 2px 0 0; }
.plan-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .projects-topbar { flex-direction: column; }
  .plan-item-title { white-space: normal; }
}
