:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dde4ef;
  --text: #162032;
  --text-muted: #5a677d;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #0f766e;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --info-bg: #e0ecff;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.topbar-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
}

.status-neutral { background: #e2e8f0; color: #334155; }
.status-ok { background: #dcfce7; color: #166534; }
.status-info { background: var(--info-bg); color: #1e40af; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px 24px;
  flex: 1;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.workspace-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel h2, .panel h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

.input, .input-file {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
}

.input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.packs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  font-size: 0.78rem;
  padding: 3px 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.86rem;
  cursor: pointer;
}

.checkbox-row small {
  display: block;
  color: var(--text-muted);
  font-size: 0.76rem;
  margin-top: 2px;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.15s ease;
}

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

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

.btn-secondary { background: #1e293b; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #0f172a; }

.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }

.feedback {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.84rem;
}

.feedback.ok { background: #dcfce7; color: #166534; }
.feedback.err { background: var(--error-bg); color: var(--error); }

.download-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.download-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.kpi-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.kpi-value {
  display: block;
  margin-top: 4px;
  font-size: 1.18rem;
}

.kpi-ok { color: #166534; }
.kpi-err { color: var(--error); }
.kpi-warn { color: var(--warning); }

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

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

.preview-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 70vh;
  box-shadow: var(--shadow);
}

.preview-columns-table th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  z-index: 1;
  white-space: nowrap;
}

.preview-columns-table td {
  min-width: 140px;
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-columns-table td.col-narrow {
  min-width: 80px;
  white-space: nowrap;
}

.search-input { flex: 1; }
.pack-filter { width: 220px; }

.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.formation-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.formation-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  background: var(--surface);
}

.formation-header:hover {
  background: var(--surface-alt);
}

.formation-title {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.badges-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.badge-cert { background: var(--info-bg); color: #1e40af; border-color: #bfdbfe; }
.badge-pack { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.badge-2026 { background: #ccfbf1; color: #115e59; border-color: #99f6e4; }
.badge-err { background: var(--error-bg); color: var(--error); border-color: #fecaca; }
.badge-warn { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }

.formation-body {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}

.action-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}

.action-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.84rem;
}

.sessions-list {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.code-viewer {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  max-height: 560px;
  font-size: 0.8rem;
  margin: 0;
}

.code-viewer-sm {
  max-height: 300px;
}

.spec-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.split-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.warnings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
}

.warning-item {
  padding: 9px 11px;
  border-radius: 7px;
  font-size: 0.83rem;
  border-left: 4px solid;
}

.warning-item.warning { background: var(--warning-bg); border-color: var(--warning); }
.warning-item.error { background: var(--error-bg); border-color: var(--error); }

.table-wrap {
  max-height: 460px;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th, .data-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.outputs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-folder {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-alt);
  font-size: 0.83rem;
}

.output-links {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  color: var(--text-muted);
}

.muted { color: var(--text-muted); font-size: 0.85rem; }
.hidden { display: none !important; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.stack-md { display: flex; flex-direction: column; gap: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; margin-top: 10px; }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.formation-description {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.desc-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.desc-text {
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.desc-empty {
  color: var(--text-muted);
}

.preview-columns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.preview-field {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
}

.preview-text-list {
  display: grid;
  gap: 8px;
}

.desc-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.desc-item-empty {
  opacity: 0.72;
}

.action-extra {
  font-size: 0.82rem;
  margin-top: 6px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.badge-edited {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}

.formation-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

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

.desc-html {
  font-size: 0.87rem;
  line-height: 1.5;
  word-break: break-word;
}

.desc-html p {
  margin: 0 0 6px;
}

.desc-html p:last-child {
  margin-bottom: 0;
}

.desc-html ul,
.desc-html ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}

.desc-html li {
  margin-bottom: 2px;
}

.desc-html h1,
.desc-html h2,
.desc-html h3,
.desc-html h4,
.desc-html h5,
.desc-html h6 {
  margin: 8px 0 4px;
  font-size: 0.95rem;
}

.table-html-cell {
  font-size: 0.81rem;
  line-height: 1.4;
}

.table-html-cell p {
  margin: 0 0 4px;
}

.table-html-cell ul,
.table-html-cell ol {
  margin: 2px 0 4px;
  padding-left: 18px;
}

.edit-form {
  background: var(--surface);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.edit-span-full {
  grid-column: 1 / -1;
}

.rich-editor-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.rich-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.rich-toolbar-btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.rich-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.rich-btn:hover {
  background: var(--info-bg);
}

.rich-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.rich-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.rich-visual {
  min-height: 92px;
  max-height: 280px;
  overflow: auto;
  padding: 10px 12px;
  font-size: 0.87rem;
  line-height: 1.5;
  outline: none;
}

.rich-visual:focus {
  box-shadow: inset 0 0 0 2px #93c5fd;
}

.rich-visual p {
  margin: 0 0 6px;
}

.rich-visual ul,
.rich-visual ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}

.rich-code {
  width: 100%;
  min-height: 110px;
  border: 0;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
  outline: none;
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split-panels { grid-template-columns: 1fr; }
}
