/*
 * CALLY CMS — giao diện quản trị.
 * File tĩnh, không qua build (laravel-mix 1.x không chạy trên Node 22). Sửa trực tiếp file này.
 * Màu và khoảng cách dùng token trên :root; component mới phải dùng lại token, không viết mã màu cứng.
 */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff4ff;
  --on-primary: #ffffff;

  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #047857;
  --success-soft: #ecfdf5;
  --warning: #b45309;
  --warning-soft: #fffbeb;

  --sidebar-bg: #0f1b33;
  --sidebar-text: #c7d2e5;
  --sidebar-muted: #6b7a96;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-active-text: #ffffff;

  --focus: 0 0 0 3px rgba(29, 78, 216, 0.35);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);

  --sidebar-width: 248px;
  --topbar-height: 56px;
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  padding: 8px 12px; background: var(--surface); border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

/* ---------- Buttons & forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  font: inherit; font-weight: 550; line-height: 1;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-muted); text-decoration: none; }
.btn-primary { color: var(--on-primary); background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-muted); }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-weight: 550; }
.input {
  display: block; width: 100%; min-height: 38px; padding: 8px 10px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input.is-invalid { border-color: var(--danger); }
.field-error { margin-top: 6px; color: var(--danger); font-size: 13px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ---------- Alerts ---------- */

.alert {
  padding: 10px 12px; margin-bottom: 16px;
  border: 1px solid; border-radius: var(--radius-sm);
}
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-danger { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }
.alert-success { color: var(--success); background: var(--success-soft); border-color: #a7f3d0; }
.alert-warning { color: var(--warning); background: var(--warning-soft); border-color: #fde68a; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block; padding: 2px 8px;
  font-size: 12px; font-weight: 550; line-height: 18px;
  color: var(--text-muted); background: var(--surface-muted);
  border: 1px solid var(--border); border-radius: 999px;
}
.badge-primary { color: var(--primary); background: var(--primary-soft); border-color: #c7d7fe; }

/* ---------- App shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  display: flex; flex-direction: column;
  width: var(--sidebar-width);
  color: var(--sidebar-text); background: var(--sidebar-bg);
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-height); padding: 0 20px;
  color: #ffffff; font-weight: 700; letter-spacing: 0.02em;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  font-size: 13px; color: var(--sidebar-bg); background: #ffffff; border-radius: 7px;
}
.nav { padding: 8px 12px 24px; }
.nav-group { margin-top: 18px; }
.nav-group-title {
  padding: 0 8px 6px; font-size: 11px; font-weight: 650;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-muted);
}
.nav-list { margin: 0; padding: 0; list-style: none; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; color: var(--sidebar-text); border-radius: var(--radius-sm);
}
.nav-link:hover { color: #ffffff; background: var(--sidebar-active-bg); text-decoration: none; }
.nav-link.is-active { color: var(--sidebar-active-text); background: var(--sidebar-active-bg); font-weight: 600; }
.nav-link.is-disabled { color: var(--sidebar-muted); cursor: default; }
.nav-link.is-disabled:hover { background: transparent; color: var(--sidebar-muted); }
.nav-phase { font-size: 11px; color: var(--sidebar-muted); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-height); padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.menu-toggle { display: none; }
.workspace-chip { display: flex; align-items: center; gap: 8px; flex: 0 1 auto; min-width: 0; }
.workspace-chip-label { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.workspace-chip-name { min-width: 0; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-chip-name:hover { color: var(--primary); }
.user-name { color: var(--text-muted); white-space: nowrap; }

.locale-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.locale-switch button {
  min-height: 30px; padding: 0 10px; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--surface); border: 0; cursor: pointer;
}
.locale-switch button + button { border-left: 1px solid var(--border-strong); }
.locale-switch button[aria-pressed="true"] { color: var(--on-primary); background: var(--primary); }

.content { flex: 1; width: 100%; max-width: 1280px; padding: 24px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); }

/* ---------- Cards & KPI ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.kpi { padding: 16px; }
.kpi-label { color: var(--text-muted); font-size: 13px; }
.kpi-value { margin-top: 6px; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-value.is-empty { color: var(--text-faint); }

.empty-state { padding: 28px 16px; text-align: center; color: var(--text-muted); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-muted); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { text-align: right; white-space: nowrap; }
.table .muted { color: var(--text-muted); }
.table tr.is-inactive td { color: var(--text-faint); }

/* ---------- Layout helpers ---------- */

.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.inline-form { display: inline; }
.mono, code { font-family: var(--font-mono); font-size: 12.5px; }
code { padding: 1px 5px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 4px; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.breadcrumb { margin: 0 0 6px; font-size: 13px; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }
.section-title { margin: 0 0 10px; font-size: 15px; }
.divider { height: 1px; margin: 20px 0; background: var(--border); border: 0; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.field-help { margin-top: 4px; font-size: 12.5px; color: var(--text-muted); }
textarea.input { min-height: 88px; resize: vertical; }
textarea.input.code { font-family: var(--font-mono); font-size: 12.5px; min-height: 110px; }
select.input[multiple] { min-height: 120px; }
fieldset.fieldset { margin: 0 0 16px; padding: 12px 14px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
fieldset.fieldset legend { padding: 0 6px; font-weight: 600; }

.layout-split { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.side-list { margin: 0; padding: 6px; list-style: none; }
.side-list a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; color: var(--text); border-radius: var(--radius-sm); }
.side-list a:hover { background: var(--surface-muted); text-decoration: none; }
.side-list a.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.badge-success { color: var(--success); background: var(--success-soft); border-color: #a7f3d0; }
.badge-warning { color: var(--warning); background: var(--warning-soft); border-color: #fde68a; }
.badge-danger { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }

.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-link { min-height: 0; padding: 0; color: var(--primary); background: none; border: 0; font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }

/* Schema editor */
.schema-section { scroll-margin-top: calc(var(--topbar-height) + 12px); }
.schema-section .card-header { gap: 12px; }
.schema-section-meta { margin-top: 2px; font-size: 12.5px; color: var(--text-muted); }
.schema-children { margin: 6px 0 0; padding-left: 14px; border-left: 2px solid var(--border); }
.origin-inherited { color: var(--text-muted); }
.errors-list { margin: 0; padding-left: 18px; }

/* Dynamic form preview */
.form-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.form-tabs a { padding: 8px 12px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.form-tabs a:hover { color: var(--text); text-decoration: none; }
.form-tabs a.has-error { color: var(--danger); }
.repeat-item { position: relative; padding: 12px 14px 2px; margin-bottom: 10px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.repeat-item-title { margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.required-mark { color: var(--danger); }

/* ---------- Topic Editor ---------- */

.editor-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.editor-tabs { position: sticky; top: calc(var(--topbar-height) + 16px); }
.editor-tabs ol { margin: 0; padding: 6px; list-style: none; }
.editor-tabs a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; color: var(--text); border-radius: var(--radius-sm); }
.editor-tabs a:hover { background: var(--surface-muted); text-decoration: none; }
.editor-tabs a.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.editor-tabs .tab-num { color: var(--text-faint); font-variant-numeric: tabular-nums; margin-right: 6px; }
.editor-progress { padding: 12px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.progress-bar { height: 6px; margin-top: 6px; background: var(--surface-muted); border-radius: 999px; overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--success); }

.state-badge { flex-shrink: 0; padding: 1px 7px; font-size: 11px; font-weight: 600; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface); }
.state-badge[data-state="in_progress"] { color: var(--warning); background: var(--warning-soft); border-color: #fde68a; }
.state-badge[data-state="complete"] { color: var(--success); background: var(--success-soft); border-color: #a7f3d0; }
.state-badge[data-state="needs_changes"] { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }

.editor-toolbar { position: sticky; top: var(--topbar-height); z-index: 20; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: -8px 0 16px; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--border); }
.save-indicator { font-size: 13px; color: var(--text-muted); min-width: 120px; }
.save-indicator[data-state="saving"] { color: var(--primary); }
.save-indicator[data-state="saved"] { color: var(--success); }
.save-indicator[data-state="dirty"] { color: var(--warning); }
.save-indicator[data-state="error"] { color: var(--danger); font-weight: 600; }
.editor-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }

.repeat-item-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.repeat-item-bar .repeat-item-title { margin: 0; }
.repeat-item-tools { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.repeat-item-tools .btn { min-height: 26px; padding: 0 8px; font-size: 12px; }
.repeat-actions { margin-bottom: 12px; }
.paste-panel { margin-bottom: 12px; padding: 10px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }

.rte-toolbar { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 4px; }
.rte-toolbar .btn { min-height: 28px; padding: 0 9px; }
.rte-area { min-height: 110px; overflow-wrap: anywhere; }
.rte-area:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.rte-area p { margin: 0 0 8px; }
.rte.is-invalid .rte-area { border-color: var(--danger); }
fieldset[disabled] .rte-area, .rte-area:not([contenteditable]) { background: var(--surface-muted); }

/* Learner preview */
.learner { max-width: 860px; margin: 0 auto; }
.learner-section { margin-bottom: 20px; }
.learner-section h2 { margin-bottom: 10px; font-size: 18px; }
.learner dl { margin: 0; }
.learner dt { margin-top: 12px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.learner dd { margin: 4px 0 0; }
.learner dd p:first-child { margin-top: 0; }
.learner .item-card { padding: 10px 12px; margin-top: 8px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.learner audio, .learner img { max-width: 100%; }

/* Prompt Studio */
.prompt-text { margin: 0; padding: 14px; max-height: 520px; overflow: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  white-space: pre-wrap; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.diff { margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 12.5px; }
.diff li { padding: 1px 10px; white-space: pre-wrap; }
.diff .add { background: var(--success-soft); color: var(--success); }
.diff .add::before { content: '+ '; }
.diff .remove { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.diff .remove::before { content: '− '; }
.diff .same::before { content: '  '; }

.asset-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 160px; }
.pagination { display: flex; gap: 4px; padding: 0; margin: 16px 0 0; list-style: none; }
.pagination li > * { display: inline-block; min-width: 32px; padding: 6px 10px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.pagination .active > * { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pagination .disabled > * { color: var(--text-faint); }

/* ---------- Auth & workspace pages ---------- */

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-box.is-wide { max-width: 560px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 18px; font-weight: 700; }
.auth-brand .brand-mark { color: #ffffff; background: var(--sidebar-bg); }
.auth-tagline { margin: 2px 0 0; font-size: 13px; font-weight: 400; color: var(--text-muted); }
.auth-card { padding: 24px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-intro { margin: 0 0 20px; color: var(--text-muted); }
.auth-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

.workspace-list { margin: 0; padding: 0; list-style: none; }
.workspace-list li + li { margin-top: 8px; }
.workspace-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 12px 14px; font: inherit; text-align: left; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.workspace-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.workspace-option-name { font-weight: 600; }
.workspace-option-code { color: var(--text-muted); font-family: var(--font-mono); font-size: 12px; }

/* ---------- Error pages ---------- */

.error-code { font-size: 48px; font-weight: 750; color: var(--text-faint); line-height: 1; }
.error-actions { display: flex; gap: 8px; margin-top: 20px; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .layout-split { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-tabs { position: static; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 23, 42, 0.4); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .user-name { display: none; }
}

@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .grid-kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .workspace-chip-label,
  .workspace-switch { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
