* {
  box-sizing: border-box;
  font-family: "Segoe UI", Arial, sans-serif;
}

.theme-classic {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --header-bg: #0f172a;
  --header-text: #ffffff;
  --tab-bg: #1e293b;
  --tab-active: #2563eb;
  --btn: #2563eb;
  --btn-secondary: #475569;
  --btn-text: #ffffff;
  --table-head: #eef2ff;
  --code-bg: #111827;
}

.theme-modern {
  --bg: #f2f7ff;
  --surface: #ffffff;
  --surface-border: #d5e4ff;
  --text: #1f2a44;
  --muted: #445273;
  --header-bg: #12366f;
  --header-text: #ffffff;
  --tab-bg: #28569b;
  --tab-active: #14b8a6;
  --btn: #0ea5a4;
  --btn-secondary: #3b82f6;
  --btn-text: #ffffff;
  --table-head: #dbeafe;
  --code-bg: #102344;
}

.theme-labs {
  --bg: #f6fbf8;
  --surface: #ffffff;
  --surface-border: #d3e4dd;
  --text: #123128;
  --muted: #35574f;
  --header-bg: #0b3b2e;
  --header-text: #ffffff;
  --tab-bg: #16624b;
  --tab-active: #00a3a3;
  --btn: #007d79;
  --btn-secondary: #2f855a;
  --btn-text: #ffffff;
  --table-head: #d9f1ea;
  --code-bg: #103229;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 20px;
  background: var(--header-bg);
  color: var(--header-text);
  padding: 12px 18px;
}

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

.brand-logo {
  width: 34px;
  height: 34px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.nav {
  display: flex;
  gap: 14px;
}

.tabs a {
  color: var(--header-text);
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--tab-bg);
  min-width: 110px;
  text-align: center;
}

.tabs a:hover {
  background: var(--tab-active);
}

.container {
  max-width: 1250px;
  margin: 18px auto;
  padding: 0 12px;
}

.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--surface-border);
}

.narrow {
  max-width: 480px;
}

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

.back-row {
  margin-top: 14px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.full-width {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input,
select,
textarea,
button {
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: var(--text);
}

textarea {
  resize: vertical;
}

button,
.button-link {
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.secondary {
  background: var(--btn-secondary);
}

.icon-btn .icon {
  font-weight: 700;
}

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  overflow: hidden;
}

.view-toggle a {
  text-decoration: none;
  color: var(--text);
  padding: 8px 14px;
  background: var(--surface);
}

.view-toggle a.active {
  background: var(--btn);
  color: var(--btn-text);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border: 1px solid var(--surface-border);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--table-head);
}

.alert {
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 12px;
  transition: opacity 0.6s ease;
  opacity: 1;
}

.alert.dit-flash-fade {
  opacity: 0;
}

.alert-success {
  background: #dcfce7;
  color: #14532d;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
}

.alert-info {
  background: #dbeafe;
  color: #1e3a8a;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.product-context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}

.product-context-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--header-text);
  margin: 0;
}

.product-context-select {
  min-width: 220px;
  font-weight: 600;
  font-size: 16px;
  border: 1px solid #cbd5e1;
  background: #fff;
}

.inline-form {
  margin-bottom: 12px;
}

.content-box {
  background: var(--code-bg);
  color: #f9fafb;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
}

.editor-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.editor-toolbar button {
  min-width: 36px;
  padding: 6px 8px;
}

.html-editor {
  min-height: 280px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  overflow: auto;
}

.content-html-view {
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

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

.meta {
  color: var(--muted);
  margin-bottom: 12px;
}

.hidden-field {
  display: none;
}

.matrix-label {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 12px;
}

.hidden-panel {
  display: none;
  margin-top: 10px;
}

.show-panel {
  display: block;
}

.capability-visual-box {
  border-radius: 8px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

.capability-chart-panel {
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.capability-chart-panel h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
}

.capability-chart {
  width: 100%;
  height: auto;
  min-height: 240px;
  display: block;
}

.composer-generate-btn {
  width: 240px;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.composer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.composer-language-row {
  margin: 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-language-row select {
  padding: 4px 8px;
}

.registry-table td,
.registry-table th {
  vertical-align: top;
}

.registry-chapters-cell {
  max-width: 480px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted, #555);
}

table td.chapter-custom-name,
table tr td.chapter-custom-name,
.chapter-custom-name {
  background-color: #e8f7e0 !important;
  color: #14532d !important;
}

.raw-leaflet-status {
  color: var(--muted);
  font-size: 12px;
  min-height: 16px;
}

.config-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--surface-border);
  margin-bottom: 14px;
}

.config-tab {
  display: inline-block;
  padding: 10px 22px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: -2px;
}

.config-tab:hover {
  background: #f1f5f9;
}

.config-tab.active {
  background: var(--btn);
  color: var(--btn-text);
  border-color: var(--btn);
}

.mp-editor {
  margin-top: 12px;
}

.mp-steps-table {
  width: 100%;
  border-collapse: collapse;
}

.mp-steps-table th,
.mp-steps-table td {
  vertical-align: middle;
  padding: 6px 8px;
  border-bottom: 1px solid var(--surface-border);
}

.mp-steps-table input[type="text"],
.mp-steps-table textarea {
  width: 100%;
  box-sizing: border-box;
}

.mp-step-actions {
  display: flex;
  gap: 4px;
}

.mp-step-actions button {
  min-width: 34px;
  padding: 4px 8px;
}

.manufacturing-chart {
  margin: 16px 0;
  text-align: center;
}

.manufacturing-chart svg {
  max-width: 100%;
  height: auto;
}

.bilingual-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--surface-border);
}

.bilingual-tab {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}

.bilingual-tab.active {
  background: var(--tab-active);
  color: var(--btn-text);
  border-color: var(--tab-active);
}

.bilingual-pane .ck-editor__editable_inline {
  min-height: 320px;
}

.bilingual-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.bilingual-actions .primary {
  background: var(--btn);
  color: var(--btn-text);
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.dit-llm-status {
  display: none;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  color: #d97706;
  font-weight: 600;
  font-style: italic;
}

.dit-llm-status.is-active {
  display: inline-flex;
}

.dit-llm-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
}

.dit-llm-dots > span {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f97316;
  opacity: 0.25;
  animation: ditLlmDot 1.2s infinite ease-in-out;
}

.dit-llm-dots > span:nth-child(2) {
  animation-delay: 0.2s;
}

.dit-llm-dots > span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ditLlmDot {
  0%, 80%, 100% {
    opacity: 0.25;
    transform: scale(0.85);
  }
  40% {
    opacity: 1;
    transform: scale(1.25);
    box-shadow: 0 0 6px rgba(249, 115, 22, 0.7);
  }
}

.apqr-doc-form {
  display: grid;
  gap: 12px;
  max-width: 480px;
}

.apqr-doc-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.apqr-doc-form input {
  padding: 8px;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
}

.apqr-doc-form .actions {
  display: flex;
  gap: 8px;
}

.apqr-doc-form .primary {
  background: var(--btn);
  color: var(--btn-text);
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.dashboards-shell {
  padding: 18px;
}

.dashboards-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  margin-top: 12px;
}

.dashboards-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 8px;
  align-self: start;
}

.dashboards-tab {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  background: transparent;
  border: 1px solid transparent;
}

.dashboards-tab:hover {
  background: var(--table-head);
}

.dashboards-tab.active {
  background: var(--tab-active);
  color: var(--btn-text);
  border-color: var(--tab-active);
}

.dashboards-content {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 16px;
  min-height: 400px;
}

.dashboards-filters-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.dashboards-filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.dashboards-filter label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.dashboards-filter select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
}

.dashboards-info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.dashboards-info-card {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-radius: 8px;
  padding: 12px 16px;
}

.dashboards-info-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

.dashboards-info-card .value {
  font-size: 18px;
  font-weight: 600;
  margin-top: 4px;
}

.dashboards-grid-two {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 2fr;
  gap: 16px;
}

.dashboards-panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 12px;
}

.dashboards-panel-title {
  font-size: 14px;
  margin: 0 0 8px 0;
  color: var(--text);
}

.dashboards-stats-table {
  width: 100%;
  border-collapse: collapse;
}

.dashboards-stats-table th,
.dashboards-stats-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--surface-border);
  text-align: left;
  font-size: 13px;
}

.dashboards-stats-table th {
  background: var(--table-head);
}

.dashboards-chart {
  width: 100%;
  height: auto;
  max-width: 100%;
}

.dashboards-chart-wide {
  max-width: 100%;
}

.dashboards-empty {
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.dashboards-grid-yield {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
}

.dashboards-side-filters {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--table-head);
  border-radius: 8px;
  padding: 10px;
}

.dashboards-side-block h4 {
  margin: 0 0 6px 0;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.dashboards-check-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  padding: 6px;
}

.dashboards-check {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
}

.dashboards-side-filters input[type="date"] {
  width: 100%;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
}

.dashboards-main {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 12px;
}

.dashboards-summary-table {
  width: 100%;
  border-collapse: collapse;
}

.dashboards-summary-table th,
.dashboards-summary-table td {
  border: 1px solid var(--surface-border);
  padding: 6px 10px;
  font-size: 12px;
}

.dashboards-summary-table th {
  background: var(--table-head);
}

.dashboards-summary-table td.center {
  text-align: center;
  font-weight: 600;
  color: #16a34a;
}

.dashboards-grid-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.dashboards-chart-block {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  padding: 8px;
}

.dashboards-chart-label {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .dashboards-layout {
    grid-template-columns: 1fr;
  }
  .dashboards-grid-two,
  .dashboards-grid-yield {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1000px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }
}

.chapter-tree {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.chapter-tree .chapter-tree {
  margin-left: 28px;
  border-left: 1px dashed var(--surface-border);
  padding-left: 8px;
}

.chapter-tree-node {
  margin: 4px 0;
  padding: 0;
}

.chapter-tree-node.dragging {
  opacity: 0.4;
}

.chapter-tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  position: relative;
}

.chapter-tree-handle {
  cursor: grab;
  user-select: none;
  color: var(--muted);
  font-size: 16px;
  padding: 0 2px;
}

.chapter-tree-handle:active {
  cursor: grabbing;
}

.chapter-tree-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.chapter-tree-fields input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  font-size: 13px;
}

.chapter-tree-uitype {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 4px;
}

.apqr-workflow-table {
  width: 100%;
  table-layout: auto;
}

.apqr-workflow-table th,
.apqr-workflow-table td {
  vertical-align: middle;
  padding: 6px 8px;
}

.apqr-workflow-table .col-chapter {
  width: auto;
  white-space: normal;
  word-break: break-word;
}

.apqr-workflow-table th.col-narrow,
.apqr-workflow-table td.col-narrow {
  width: 1%;
  white-space: nowrap;
}

.apqr-workflow-table select {
  min-width: 220px;
  max-width: 320px;
}

.apqr-workflow-table tr.approver-only-row {
  background: rgba(0, 0, 0, 0.025);
}

.apqr-workflow-table .approver-only-badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-border);
  color: var(--muted);
  margin-left: 4px;
  vertical-align: middle;
}

.apqr-workflow-table .approver-only-value {
  display: inline-block;
  color: var(--muted);
  font-style: italic;
  white-space: nowrap;
}

.chapter-tree-approver {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 4px;
  cursor: help;
}

.chapter-tree-approver input[type="checkbox"] {
  margin: 0;
}

.chapter-tree-delete {
  font-size: 18px;
  line-height: 1;
  padding: 0 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

.chapter-tree-node.drop-before > .chapter-tree-row {
  box-shadow: 0 -2px 0 0 var(--btn);
}

.chapter-tree-node.drop-after > .chapter-tree-row {
  box-shadow: 0 2px 0 0 var(--btn);
}

.chapter-tree-node.drop-into > .chapter-tree-row {
  outline: 2px solid var(--btn);
  outline-offset: -2px;
}

@media (max-width: 700px) {
  .chapter-tree-fields {
    grid-template-columns: 1fr;
  }
}

.dit-onlyoffice-card {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 110px);
  margin-bottom: 24px;
}

.dit-onlyoffice-card .bilingual-tabs {
  flex: 0 0 auto;
}

.dit-onlyoffice-stage {
  flex: 1 1 auto;
  display: flex;
  min-height: 480px;
  margin-top: 12px;
}

.dit-onlyoffice-mount {
  flex: 1 1 auto;
  width: 100%;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  min-height: 480px;
}

.dit-onlyoffice-mount > * {
  width: 100% !important;
  height: 100% !important;
}

.dit-onlyoffice-mount iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  display: block !important;
}

.dit-onlyoffice-card .bilingual-actions {
  flex: 0 0 auto;
}
