:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-alt: #eef4f7;
  --text: #17202a;
  --muted: #607180;
  --line: #d8e1e8;
  --primary: #005ea8;
  --primary-dark: #034f8b;
  --teal: #008575;
  --amber: #b87900;
  --red: #b42318;
  --purple: #6046a6;
  --shadow: 0 12px 30px rgba(15, 35, 52, 0.11);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(0, 94, 168, 0.2);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 60px;
  height: 44px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--teal));
  border-radius: var(--radius);
  font-weight: 800;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 10px;
  font-size: 17px;
}

h4 {
  margin-bottom: 8px;
  font-size: 15px;
}

.topbar-actions,
.note-manager,
.preview-actions,
.form-actions,
.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-manager {
  flex: 1 1 420px;
  justify-content: center;
  min-width: 280px;
}

.note-manager label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.note-manager select {
  width: min(360px, 42vw);
  min-width: 220px;
  background: #fbfdfe;
  font-weight: 700;
}

.cloud-state {
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tool-button,
.icon-button,
.segmented-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.tool-button {
  padding: 8px 12px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.tool-button:hover,
.icon-button:hover,
.segmented-button:hover {
  border-color: #9ab5c7;
  background: #f8fbfd;
}

.tool-button:active,
.icon-button:active,
.segmented-button:active {
  transform: translateY(1px);
}

.tool-button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.tool-button.primary:hover {
  background: var(--primary-dark);
}

.danger {
  color: var(--red);
}

.button-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.button-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.main-layout {
  display: grid;
  grid-template-columns: 236px minmax(360px, 1fr) minmax(330px, 36vw);
  gap: 18px;
  width: 100%;
  padding: 18px;
}

.side-nav,
.preview-pane,
.workspace {
  min-width: 0;
}

.side-nav {
  position: sticky;
  top: 94px;
  align-self: start;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.progress-panel,
.status-panel,
.form-panel,
.preview-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.progress-panel {
  padding: 14px;
  margin-bottom: 12px;
}

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

.progress-head span {
  color: var(--muted);
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce7ee;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--primary));
  transition: width 0.2s ease;
}

.save-state {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#section-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-button {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  border-color: var(--line);
  background: var(--surface);
}

.nav-button.active {
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-icon {
  color: var(--primary);
}

.nav-status {
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e7f1f7;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.status-panel {
  min-height: 130px;
  padding: 15px;
}

.status-panel .metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.metric strong {
  font-size: 22px;
  line-height: 1;
}

.status-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.status-list li {
  display: flex;
  gap: 8px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.pill,
.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e7f1f7;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.pill.ok {
  background: #e2f4ef;
  color: #006c5d;
}

.pill.warn {
  background: #fff3d6;
  color: #8a5a00;
}

.pill.bad {
  background: #fde6e3;
  color: #9b1c13;
}

.form-panel {
  padding: 0;
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfe;
}

.section-heading p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.section-score {
  flex: 0 0 auto;
  align-self: start;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 20px 22px 24px;
}

.field {
  min-width: 0;
}

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

.field label,
.check-row label {
  display: block;
  margin-bottom: 6px;
  color: #2c3a46;
  font-weight: 750;
}

.field .hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.required-dot {
  color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd9e2;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
}

input,
select {
  padding: 8px 10px;
}

textarea {
  min-height: 122px;
  padding: 10px;
  resize: vertical;
}

.textarea-sm textarea {
  min-height: 86px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfe;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
  flex: 0 0 18px;
}

.check-row label {
  margin-bottom: 0;
}

.check-row p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.helper-strip {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.helper-strip p {
  margin: 0;
  color: var(--muted);
}

.table-block {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.table-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.data-table th {
  background: #edf4f8;
  color: #2c3a46;
  font-size: 13px;
  text-align: left;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table input,
.data-table select,
.data-table textarea {
  min-height: 36px;
  border-color: #d6e1e7;
  border-radius: 6px;
}

.data-table textarea {
  min-height: 68px;
}

.row-tools {
  width: 48px;
  text-align: center;
}

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-weight: 750;
}

.mini-button:hover {
  background: #f7fafc;
}

.preview-pane {
  position: sticky;
  top: 94px;
  align-self: start;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 112px);
  min-height: 420px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfe;
  border-radius: var(--radius) var(--radius) 0 0;
}

.document-preview {
  overflow: auto;
  padding: 26px 30px 34px;
  background: #ffffff;
  border-radius: 0 0 var(--radius) var(--radius);
}

.document-preview h1 {
  margin-bottom: 8px;
  font-size: 24px;
}

.document-preview h2 {
  margin-top: 26px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #d9e2e8;
  font-size: 18px;
}

.document-preview h3 {
  margin-top: 18px;
  margin-bottom: 6px;
  font-size: 15px;
}

.document-preview p,
.document-preview li,
.document-preview td,
.document-preview th {
  color: #27333d;
}

.document-preview .doc-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin: 16px 0 20px;
  padding: 12px;
  border: 1px solid #d9e2e8;
  border-radius: var(--radius);
  background: #f7fafc;
}

.document-preview .placeholder {
  color: #7b8790;
  font-style: italic;
}

.document-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 16px;
}

.document-preview th,
.document-preview td {
  border: 1px solid #d9e2e8;
  padding: 7px;
  text-align: left;
  vertical-align: top;
}

.document-preview th {
  background: #eef4f7;
}

.admin-layout {
  width: min(980px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

.admin-panel + .admin-panel {
  margin-top: 18px;
}

.admin-panel label {
  display: block;
  margin: 16px 0 6px;
  font-weight: 800;
}

.admin-muted {
  color: var(--muted);
}

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

.admin-editor {
  min-height: 520px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.source-pill {
  text-decoration: none;
}

.source-pill:hover {
  background: #d8ebf5;
}

@media (max-width: 1380px) and (min-width: 981px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .main-layout {
    grid-template-columns: 228px minmax(420px, 1fr);
  }

  .preview-pane {
    position: static;
    grid-column: 2;
    max-height: none;
  }
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .main-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .side-nav,
  .preview-pane {
    position: static;
    max-height: none;
  }

  #section-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 12px;
  }

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

  .brand-mark {
    width: 50px;
    height: 38px;
  }

  h1 {
    font-size: 22px;
  }

  .topbar-actions {
    width: 100%;
  }

  .note-manager {
    justify-content: flex-start;
    width: 100%;
  }

  .note-manager select {
    flex: 1 1 100%;
    width: 100%;
  }

  .tool-button {
    flex: 1 1 120px;
  }

  #section-nav {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .preview-toolbar,
  .table-head,
  .helper-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-preview .doc-meta {
    grid-template-columns: 1fr;
  }

  .data-table {
    display: block;
    overflow-x: auto;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .side-nav,
  .workspace,
  .preview-toolbar {
    display: none;
  }

  .main-layout {
    display: block;
    padding: 0;
  }

  .preview-pane {
    position: static;
    max-height: none;
    border: 0;
    box-shadow: none;
  }

  .document-preview {
    padding: 0;
    overflow: visible;
  }
}
