:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #667085;
  --line: #d7dde7;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #d9f3ee;
  --accent: #2563eb;
  --surface: rgba(255, 255, 255, 0.9);
  --warning: #b45309;
  --danger: #b42318;
  --radius: 8px;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
.is-hidden { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, 0.16), transparent 32rem),
    linear-gradient(135deg, #f7fafc 0%, var(--bg) 48%, #f8fafc 100%);
  color: var(--ink);
}

body.dark {
  --bg: #0f172a;
  --panel: #111827;
  --ink: #e5edf8;
  --muted: #a8b3c5;
  --line: #263244;
  --surface: rgba(17, 24, 39, 0.92);
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, 0.18), transparent 32rem),
    linear-gradient(135deg, #0b1020 0%, #0f172a 54%, #111827 100%);
}

body.dark .sidebar,
body.dark .workspace-drawer,
body.dark .drawer-section,
body.dark .drawer-file-item,
body.dark .sidebar-account,
body.dark .panel,
body.dark .file-item,
body.dark .install-grid div,
body.dark .workspace-item,
body.dark .admin-row,
body.dark .message,
body.dark .provider-help,
body.dark .ai-usage-card,
body.dark .ai-workflow-controls,
body.dark .provider-tab-panel,
body.dark .usage-row,
body.dark input,
body.dark select,
body.dark textarea {
  background: #111827;
  color: var(--ink);
}

body.dark .markdown-preview {
  background: #0f172a;
  color: var(--ink);
}

body.dark .tab {
  color: #f8fafc;
}

body.dark .tab.is-active {
  background: rgba(20, 184, 166, 0.2);
  border-color: #2dd4bf;
  color: #ffffff;
}

body.dark .drawer-file-item.is-folder {
  background: #102033;
  border-color: #1e3a5f;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  color: #243142;
  font-weight: 700;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

button:hover {
  border-color: #aab6c6;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.07);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(135deg, var(--primary), #0f8f82);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.22);
}

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

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: #243142;
  font-weight: 800;
  text-decoration: none;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.field-help {
  color: #697586;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.field-help code {
  background: #eef6f5;
  color: #0f766e;
  border: 1px solid #cce7e2;
  border-radius: 6px;
  padding: 1px 5px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus, select:focus, textarea:focus {
  border-color: #14b8a6;
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.14);
}

textarea {
  resize: vertical;
}

.app-shell {
  min-height: calc(100vh - 52px);
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid rgba(215, 221, 231, 0.78);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 8px 0 32px rgba(15, 23, 42, 0.04);
  max-height: 100vh;
  overflow: auto;
  position: sticky;
  top: 0;
}

.workspace-drawer {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 252, 0.98));
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(15, 23, 42, 0.18);
  bottom: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  max-width: min(520px, 94vw);
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  width: 520px;
  z-index: 40;
}

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

.drawer-header strong,
.drawer-header span {
  display: block;
}

.drawer-header span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.drawer-list {
  max-height: none;
  overflow: auto;
  padding-right: 4px;
}

.drawer-section {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

.drawer-section h3 {
  font-size: 13px;
  margin: 0 0 4px;
  text-transform: uppercase;
  color: var(--muted);
}

.drawer-file-item {
  align-items: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 3px;
  height: auto;
  justify-content: stretch;
  min-height: 0;
  padding: 9px 10px;
  text-align: left;
}

.drawer-file-item.is-folder {
  border-color: #bae6fd;
  background: #f0f9ff;
}

.drawer-file-item strong,
.drawer-file-item span {
  overflow-wrap: anywhere;
}

.drawer-file-item span {
  color: var(--muted);
  font-size: 12px;
}

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

.brand img {
  border-radius: 10px;
  height: 34px;
  width: 34px;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.brand h1, .brand p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.tabs {
  display: grid;
  gap: 4px;
}

.tab {
  text-align: left;
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  min-height: 38px;
  padding: 8px 10px;
}

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

.status-panel {
  display: grid;
  gap: 6px;
}

body.dark .link {
    color: #fff;
}

.site-footer {
  align-items: center;
  background: rgba(255, 255, 255, 0.86);
  border-top: 1px solid rgba(215, 221, 231, 0.82);
  bottom: 0;
  color: var(--muted);
  display: flex;
  gap: 14px;
  justify-content: flex-end;
  min-height: 52px;
  padding: 10px 24px;
  position: sticky;
  z-index: 20;
}

.site-footer .footer-text {
  margin-right: auto;
}

body.dark .site-footer {
  background: rgba(15, 23, 42, 0.94);
  border-color: rgba(71, 85, 105, 0.9);
}

.sidebar-account {
  background: rgba(255, 255, 255, 0.46);
  border: 1px solid rgba(215, 221, 231, 0.72);
  border-radius: 10px;
  display: grid;
  gap: 9px;
  padding: 10px;
}

.sidebar-auth {
  display: grid;
  gap: 7px;
}

.sidebar-auth strong {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.sidebar-account .workspace-list {
  max-height: 210px;
  overflow: auto;
}

.sidebar-account .workspace-item {
  grid-template-columns: 1fr;
  padding: 8px;
}

.sidebar-account .file-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.install-button {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.update-banner {
  border: 1px solid #facc15;
  background: #fefce8;
  color: #854d0e;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
}

.update-banner a {
  color: #0f766e;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef6f5;
  color: #0f766e;
  font-size: 12px;
  font-weight: 700;
}

.version-badge {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 2px;
}

.main {
  padding: 28px;
  min-width: 0;
}

.view {
  display: none;
}

.view.is-active {
  display: grid;
  gap: 18px;
}

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

.section-header h2, .section-header p {
  margin: 0;
}

.section-header h2 {
  font-size: 28px;
  letter-spacing: 0;
}

.section-header p, .note {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.panel {
  background: var(--surface);
  border: 1px solid rgba(215, 221, 231, 0.82);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin: 0;
  font-size: 17px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #ecfdf3;
  color: #047857;
  border: 1px solid #bbf7d0;
  font-size: 12px;
  font-weight: 800;
}

.pill.subtle {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.install-panel {
  display: grid;
  gap: 14px;
}

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

.install-grid div {
  border: 1px solid #dfe6ef;
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.install-grid strong {
  display: block;
  margin-bottom: 6px;
}

.install-grid p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  line-height: 1.45;
}

.install-grid code {
  color: #0f766e;
  background: #eef6f5;
  border-radius: 6px;
  padding: 1px 5px;
}

.provider-help {
  border: 1px solid #dfe6ef;
  background: #fff;
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 6px;
}

.provider-tabs {
  display: grid;
  gap: 12px;
}

.provider-tab-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.provider-tab-buttons button {
  align-items: start;
  display: grid;
  gap: 3px;
  height: auto;
  justify-content: stretch;
  padding: 10px;
  text-align: left;
}

.provider-tab-buttons button.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.provider-tab-buttons span {
  color: var(--muted);
  font-size: 12px;
}

.provider-tab-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  display: none;
  gap: 12px;
  padding: 12px;
}

.provider-tab-panel.is-active {
  display: grid;
}

.provider-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.provider-links a {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 9px;
  text-decoration: none;
}

.ai-usage-card,
.ai-workflow-controls {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(248, 250, 252, 0.9);
  display: grid;
  gap: 10px;
  padding: 12px;
}

.ai-workflow-controls {
  grid-template-columns: minmax(140px, 1fr) minmax(160px, 1.2fr);
  align-items: end;
}

.ai-workflow-controls .note {
  grid-column: 1 / -1;
}

.usage-bars {
  display: grid;
  gap: 8px;
}

.usage-meter {
  background: #e2e8f0;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.usage-meter span {
  background: linear-gradient(90deg, #14b8a6, #f59e0b);
  display: block;
  height: 100%;
  min-width: 2px;
}

.usage-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.usage-row strong,
.usage-row span {
  display: block;
}

.usage-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

body.dark .provider-help p,
body.dark .usage-row span,
body.dark .provider-tab-buttons span,
body.dark .ai-workflow-controls .note,
body.dark .ai-usage-card .note {
  color: #cbd5e1;
}

body.dark .provider-links a {
  background: #0f172a;
  border-color: #334155;
  color: #67e8f9;
}

body.dark .provider-tab-buttons button.is-active {
  background: #102033;
  color: #67e8f9;
}

.pill.warning {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.provider-help p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  line-height: 1.45;
}

.provider-help a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

.account-panel {
  display: grid;
  gap: 14px;
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.account-actions {
  align-items: end;
}

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

.file-tree {
  display: grid;
  gap: 6px;
  padding: 4px 2px 4px 0;
}

.tree-row {
  padding-left: calc(var(--tree-depth, 0) * 18px);
  position: relative;
}

.tree-row::before {
  background: rgba(100, 116, 139, 0.18);
  bottom: 0;
  content: "";
  left: calc((var(--tree-depth, 0) * 18px) - 10px);
  position: absolute;
  top: -6px;
  width: 1px;
}

.tree-row[style*="--tree-depth:0"]::before {
  display: none;
}

.tree-node {
  width: 100%;
}

.tree-label {
  align-items: start;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.tree-label strong,
.tree-label small {
  display: block;
  overflow-wrap: anywhere;
}

.tree-label small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.tree-icon {
  color: var(--primary);
  flex: 0 0 auto;
  font-weight: 900;
  line-height: 1.2;
}

.tree-node.is-folder {
  background: #f8fbff;
  border-color: #dbeafe;
}

.builder-library .workspace-item,
.report-library .workspace-item,
.drawer-file-item.tree-node {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.builder-library .file-actions,
.report-library .file-actions {
  justify-content: flex-start;
}

.workspace-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid #dfe6ef;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff;
}

.workspace-item.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.workspace-item strong {
  display: block;
}

.workspace-item span {
  color: var(--muted);
  font-size: 12px;
}

.segmented-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

form.panel {
  display: grid;
  gap: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-button.is-active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  box-shadow: none;
}

.notice {
  border: 1px solid #b7dfd8;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #f0fdfa, #f8fffd);
  color: #134e4a;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.notice.warning {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.notice.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--danger);
}

.field-group {
  display: grid;
  gap: 14px;
}

.field-group.is-hidden {
  display: none;
}

.row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
}

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

.actions.split {
  justify-content: space-between;
}

.file-layout {
  min-height: 620px;
}

.search {
  margin-bottom: 12px;
}

.pathbar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.pathbar span {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.file-list {
  display: grid;
  gap: 6px;
  max-height: 560px;
  overflow: auto;
}

.file-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid #dfe6ef;
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.file-item:hover {
  border-color: #b8c4d3;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
}

.file-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.file-item strong {
  overflow-wrap: anywhere;
}

.file-item span {
  color: var(--muted);
  font-size: 12px;
}

.preview-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.selected-context {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

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

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  background: linear-gradient(180deg, #101827, #111827);
  color: #f9fafb;
  border-radius: var(--radius);
  padding: 14px;
  min-height: 480px;
  max-height: 580px;
}

.audit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 12px;
}

.audit-chat {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.chat {
  min-height: 420px;
  max-height: 540px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.message {
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.message.user {
  background: linear-gradient(135deg, #e7f5f2, #f2fbf9);
  border-color: #99d8cf;
}

.message.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--danger);
}

.message strong {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.message-files span {
  background: #eef6f5;
  border: 1px solid #cce7e2;
  border-radius: 999px;
  color: #0f766e;
  font-size: 12px;
  font-weight: 750;
  padding: 4px 8px;
}

.composer {
  display: grid;
  gap: 10px;
}

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

.selection-cta {
  margin-top: 12px;
  width: 100%;
}

.prompt-wrap {
  position: relative;
}

.prompt-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  position: relative;
}

.mention-suggestions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  bottom: calc(100% + 8px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  left: 0;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  z-index: 20;
}

.mention-suggestions button {
  align-items: start;
  display: grid;
  gap: 2px;
  height: auto;
  justify-content: stretch;
  min-height: 0;
  padding: 8px 10px;
  text-align: left;
}

.mention-suggestions span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #172033;
  padding: 5px 10px;
  font-size: 13px;
}

body.dark .chip {
  background: #f8fafc;
  border-color: #d7dde7;
  color: #172033;
}

.chip button {
  border: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  color: #334155;
}

.report-editor {
  min-height: 660px;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.5;
}

.report-workspace {
  align-items: stretch;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
}

.report-library {
  align-content: start;
  display: grid;
  gap: 12px;
}

.report-library .workspace-list {
  max-height: 520px;
  overflow: auto;
}

.pro-doc-panel {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
}

.compact-fields {
  gap: 8px;
}

.pro-doc-panel .workspace-list {
  max-height: 170px;
  overflow: auto;
}

.live-report {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 560px;
}

#liveReportPreview.flash {
  outline: 2px solid #14b8a6;
}

.live-report-editor {
  min-height: 500px;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.5;
  resize: none;
}

.markdown-preview {
  display: none;
  min-height: 500px;
  max-height: 580px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  line-height: 1.55;
}

.markdown-preview.preview-active {
  display: block;
}

.live-report-editor.preview-active {
  display: none;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  margin: 12px 0 8px;
}

.markdown-preview p {
  margin: 8px 0;
}

.markdown-preview code {
  background: #eef6f5;
  border-radius: 6px;
  color: #0f766e;
  padding: 1px 5px;
}

.markdown-preview pre {
  min-height: 0;
  max-height: none;
  background: #111827;
  color: #f9fafb;
}

.document-workspace {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  align-items: stretch;
}

.document-library {
  align-self: stretch;
}

.document-editor-panel {
  display: grid;
  grid-template-rows: minmax(360px, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.document-edit-shell {
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr);
  gap: 10px;
  min-height: 420px;
}

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

.document-preview {
  display: none;
  min-height: 360px;
  overflow: auto;
}

.report-editor.preview-active {
  display: none;
}

.doc-finder {
  display: grid;
  gap: 12px;
}

.compact-chat {
  max-height: clamp(260px, 42vh, 620px);
  min-height: 170px;
}

.doc-finder .compact-chat {
  max-height: none;
  min-height: 220px;
  overflow: visible;
}

.update-confirm {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
}

.update-confirm .note {
  flex-basis: 100%;
  margin: 0;
}

.stacked-actions {
  display: grid;
  gap: 8px;
}

.builder-workspace {
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  align-items: start;
}

.builder-main {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.builder-composer {
  display: grid;
  gap: 12px;
  grid-template-rows: auto minmax(180px, 1fr) auto;
  max-height: clamp(360px, 48vh, 620px);
  min-height: 360px;
  overflow: hidden;
}

.builder-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.builder-editor-panel,
.builder-preview-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr);
  gap: 10px;
  min-width: 0;
}

.code-editor {
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  min-height: 520px;
}

.html-preview {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 560px;
  width: 100%;
}

.builder-text-preview {
  min-height: 420px;
}

.builder-composer .compact-chat {
  max-height: none;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.builder-composer .prompt-row {
  align-items: end;
}

.builder-composer textarea {
  max-height: 150px;
  resize: vertical;
}

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

.guide-grid.single {
  grid-template-columns: 1fr;
}

.guide-grid.single article {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.guide-grid.single article:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.guide-grid p {
  color: var(--muted);
  line-height: 1.55;
}

.guide-grid code {
  background: #eef6f5;
  color: #0f766e;
  border-radius: 6px;
  padding: 1px 5px;
}

.version-log {
  line-height: 1.5;
  max-height: 720px;
  overflow: auto;
}

.version-entry {
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.version-entry:first-child {
  padding-top: 0;
}

.version-entry h3 {
  margin: 0 0 8px;
}

.version-entry h3 span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.version-entry ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.admin-main {
  max-width: 1240px;
  margin: 0 auto;
}

.admin-dashboard {
  display: grid;
  gap: 18px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding-bottom: 10px;
  padding: 10px;
  position: sticky;
  top: 10px;
  z-index: 8;
}

.admin-tab {
  background: transparent;
  border-color: transparent;
}

.admin-tab.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: none;
}

.admin-section {
  display: none;
}

.admin-section.is-active {
  display: grid;
  gap: 18px;
}

.admin-hero-panel {
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(37, 99, 235, 0.08)),
    var(--panel);
}

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

.metric-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,250,252,0.96));
  border: 1px solid rgba(203, 213, 225, 0.92);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric-card strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-top: 8px;
  text-transform: uppercase;
}

.admin-chart {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
  min-height: 170px;
  padding: 12px 4px 0;
}

.chart-bar {
  align-items: center;
  display: grid;
  gap: 8px;
  justify-items: center;
}

.chart-bar span {
  background: linear-gradient(180deg, var(--primary), #38bdf8);
  border-radius: 8px 8px 2px 2px;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.2);
  display: block;
  min-height: 8px;
  width: 100%;
}

.chart-bar small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.admin-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #dfe6ef;
  border-radius: var(--radius);
  background: #fff;
  padding: 10px 12px;
}

.admin-row select {
  min-width: 132px;
}

.ticket-row {
  grid-template-columns: minmax(0, 1fr) 150px;
}

.admin-row strong,
.admin-row span {
  overflow-wrap: anywhere;
}

.admin-row span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.compact-list {
  background: rgba(15, 118, 110, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.compact-list .admin-row {
  align-items: start;
  background: var(--panel);
  grid-template-columns: 1fr;
}

.compact-list code,
.compact-list strong {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: block;
  font-size: 0.86rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  width: 100%;
}

.webhook-card {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(59, 130, 246, 0.08));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 10px;
  padding: 12px;
}

.webhook-card div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.webhook-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.webhook-card code,
.webhook-card strong {
  color: var(--text);
  display: block;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

body.dark .admin-tabs,
body.dark .metric-card {
  background: rgba(15, 23, 42, 0.92);
  border-color: rgba(71, 85, 105, 0.9);
}

body.dark .webhook-card {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(71, 85, 105, 0.9);
}

body.dark .webhook-card div {
  background: rgba(2, 6, 23, 0.66);
  border-color: rgba(71, 85, 105, 0.9);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.inline-check input,
label span input[type="checkbox"] {
  width: auto;
}

.feature-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.feature-list li {
  margin: 4px 0;
}

.install-form {
  display: grid;
  gap: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(80px);
  background: #111827;
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
  opacity: 0;
  transition: 180ms ease;
  max-width: min(520px, calc(100vw - 32px));
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    position: static;
  }

  .tabs {
    grid-template-columns: repeat(4, 1fr);
  }

  .tab {
    text-align: center;
    padding-inline: 8px;
  }

  .status-panel {
    margin-top: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .install-grid {
    grid-template-columns: 1fr;
  }

  .account-grid,
  .guide-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .ai-workflow-controls {
    grid-template-columns: 1fr;
  }

  .provider-tab-buttons {
    grid-template-columns: 1fr;
  }

  .audit-layout {
    grid-template-columns: 1fr;
  }

  .builder-workspace,
  .document-workspace,
  .report-workspace {
    grid-template-columns: 1fr;
  }

  .builder-library,
  .document-library,
  .report-library {
    max-height: none;
  }

  .builder-library .workspace-list,
  .document-library .workspace-list,
  .report-library .workspace-list {
    max-height: 360px;
    overflow: auto;
  }

  .builder-composer {
    max-height: 560px;
    min-height: 340px;
  }

  .builder-editor-grid {
    grid-template-columns: 1fr;
  }

  .builder-editor-panel,
  .builder-preview-panel {
    grid-template-rows: auto minmax(320px, 1fr);
  }

  .code-editor,
  .html-preview,
  .builder-text-preview {
    min-height: 360px;
  }

  .document-editor-panel {
    grid-template-rows: minmax(320px, 1fr) auto;
  }

  .document-edit-shell,
  .document-preview,
  .live-report-editor,
  .markdown-preview {
    min-height: 320px;
  }

  .tree-row {
    padding-left: calc(var(--tree-depth, 0) * 12px);
  }

  .workspace-item.tree-node {
    padding: 9px;
  }

  .file-actions {
    gap: 6px;
  }

  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .main {
    padding: 14px;
  }
}

@media (max-width: 560px) {
  .tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .prompt-row {
    grid-template-columns: 1fr;
  }

  .builder-composer {
    max-height: 520px;
  }

  .builder-composer textarea {
    max-height: 120px;
  }

  .tree-label {
    gap: 6px;
  }

  .file-actions button {
    flex: 1 1 auto;
  }
}
