:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #18212f;
  --muted: #647084;
  --line: #dce2ea;
  --accent: #2f6fed;
  --accent-dark: #1f55c7;
  --accent-soft: #eaf1ff;
  --danger: #b42318;
  --warning: #9a6700;
  --success: #067647;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input { min-height: 38px; }
button, label.button, select { cursor: pointer; }

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.app-header strong { display: block; font-size: 1.05rem; }
.app-header small { display: block; margin-top: 3px; color: var(--muted); }
.local-pill, .metric-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid #b7e2ce;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--success);
  background: #ecfdf3;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}

.workspace { display: grid; gap: 14px; padding: 16px; max-width: 1480px; margin: 0 auto; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 17px; background: var(--surface); box-shadow: 0 5px 18px rgba(24,33,47,.045); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 13px; }
h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 1.08rem; }
h3 { margin-bottom: 8px; font-size: .87rem; color: var(--muted); }
.section-label { margin-bottom: 3px; color: var(--accent); font-size: .69rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.subtle, .profile-description, .input-footer, .export-card p { color: var(--muted); font-size: .82rem; }

textarea, input[type="text"], input[type="search"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 9px 11px;
}
textarea { resize: vertical; line-height: 1.5; tab-size: 2; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .83rem; }
textarea:focus, input:focus, select:focus, button:focus-visible, label.button:focus-within { outline: 3px solid rgba(47,111,237,.24); outline-offset: 2px; border-color: var(--accent); }
.input-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.compact { justify-content: flex-end; }
.actions.compact select { width: auto; }
.button, label.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 13px;
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
}
.button.primary { color: #fff; background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--surface); border-color: var(--line); }
.button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.button:disabled { cursor: not-allowed; opacity: .48; }

.profile-tabs, .segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.profile-tab, .segmented button { border: 0; border-radius: 6px; padding: 7px 14px; background: transparent; font-weight: 700; }
.profile-tab.active, .segmented button.active { color: var(--accent-dark); background: var(--surface); box-shadow: 0 1px 4px rgba(24,33,47,.12); }
.profile-description { margin: 12px 0; }
.options-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; padding-top: 12px; border-top: 1px solid var(--line); }
.options-grid label { color: var(--muted); font-size: .76rem; font-weight: 700; }
.options-grid label > :is(input, select) { margin-top: 5px; }
.options-grid .wide { grid-column: span 2; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: .84rem; }
.check-row input { min-height: 0; }

.search { width: min(280px, 100%); }
.tree-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tree { min-height: 210px; max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); padding: 8px; }
.tree-row { width: 100%; display: flex; align-items: center; gap: 7px; min-height: 28px; border: 0; border-radius: 5px; padding: 4px 7px; text-align: left; background: transparent; font-family: "SFMono-Regular", Consolas, monospace; font-size: .77rem; }
.tree-row:hover, .tree-row.selected { background: var(--accent-soft); color: var(--accent-dark); }
.tree-kind { color: var(--muted); margin-left: auto; font-size: .68rem; }
.empty { color: var(--muted); text-align: center; }

.table-scroll { overflow: auto; max-height: 390px; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th { position: sticky; top: 0; z-index: 1; text-align: left; background: var(--surface-soft); color: var(--muted); }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td code { overflow-wrap: anywhere; }

.metric-summary { color: var(--muted); font-size: .78rem; text-align: right; }
.integrity-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.integrity-grid div { padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.integrity-grid strong, .integrity-grid span { display: block; }
.integrity-grid strong { font-size: 1.35rem; }
.integrity-grid span { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.diagnostics { display: grid; gap: 7px; margin: 12px 0 0; padding: 0; list-style: none; }
.diagnostics li { border-left: 3px solid var(--accent); padding: 8px 10px; background: var(--surface-soft); font-size: .8rem; }
.diagnostics li.warning { border-left-color: var(--warning); }
.diagnostics li.error { border-left-color: var(--danger); }

.export-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.export-card p { margin: 6px 0 0; max-width: 720px; }
.message { margin: 10px 0 0; padding: 9px 11px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); font-size: .8rem; }
.message.error { background: #fff1f0; color: var(--danger); }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(6,12,22,.64); }
.modal-card { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; border-radius: 14px; padding: 18px; background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,.3); }
.modal-card textarea { margin: 12px 0; }

.dth-guide-highlight { outline: 4px solid rgba(47,111,237,.35) !important; outline-offset: 4px !important; }

html[data-theme="dark"] {
  --bg: #0c111b;
  --surface: #121a28;
  --surface-soft: #0f1724;
  --text: #e8edf6;
  --muted: #9ba8bc;
  --line: #2b3749;
  --accent: #79a7ff;
  --accent-dark: #a9c7ff;
  --accent-soft: #172a4d;
  --success: #6ce9a6;
}
html[data-theme="dark"] body { background-color: #0c111b !important; color: #e8edf6 !important; }
html[data-theme="dark"] .local-pill { border-color: #175c43; background: #103a2c; }
html[data-theme="dark"] .message.error { background: #3b1718; }

@media (max-width: 900px) {
  .options-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tree-grid { grid-template-columns: 1fr; }
  .export-card { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 620px) {
  .workspace { padding: 10px; }
  .card { padding: 13px; border-radius: 11px; }
  .app-header, .card-header { align-items: stretch; flex-direction: column; }
  .actions.compact { justify-content: flex-start; }
  .actions.compact select { width: 100%; }
  .profile-tabs, .segmented { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .options-grid { grid-template-columns: 1fr; }
  .options-grid .wide { grid-column: auto; }
  .integrity-grid { grid-template-columns: repeat(2, 1fr); }
  .input-footer { flex-direction: column; }
  .search { width: 100%; }
}
