:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #17211f;
  --muted: #6b7673;
  --line: #dfe5e3;
  --line-strong: #c9d2cf;
  --accent: #1f6f5c;
  --accent-dark: #145244;
  --accent-soft: #e4f2ed;
  --signal: #f2a65a;
  --danger: #b42318;
  --shadow: 0 16px 45px rgba(25, 43, 38, .08);
}

[data-theme="dark"] {
  --bg: #0e1413;
  --surface: #151d1b;
  --surface-soft: #1a2421;
  --ink: #eef5f2;
  --muted: #9aa9a4;
  --line: #293632;
  --line-strong: #3a4a45;
  --accent: #67d4b5;
  --accent-dark: #9ce6d1;
  --accent-soft: #203b34;
  --signal: #efb36f;
  --danger: #ff8a80;
  --shadow: 0 18px 50px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Manrope", sans-serif;
  font-size: 16px;
}

button, textarea { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 68px;
  padding: 0 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

.brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 11px; font-size: 1.05rem; font-weight: 800; letter-spacing: -.04em; }
.brand-mark { width: 32px; height: 32px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; align-items: end; padding: 6px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-soft); }
.brand-mark i { display: block; background: var(--accent); border-radius: 2px 2px 1px 1px; }
.brand-mark i:nth-child(1) { height: 55%; }
.brand-mark i:nth-child(2) { height: 100%; }
.brand-mark i:nth-child(3) { height: 72%; }

.topbar-center { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.privacy { padding-left: 8px; border-left: 1px solid var(--line); font-weight: 500; }
.topbar-actions { justify-self: end; display: flex; gap: 9px; }

.button, .icon-button, .upload-button, .text-button {
  border: 0;
  cursor: pointer;
  transition: .18s ease;
}

.button { min-height: 40px; padding: 0 15px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: .82rem; }
.button svg, .upload-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button.primary { background: var(--accent); color: #fff; box-shadow: 0 7px 18px rgba(31, 111, 92, .2); }
.button.primary:hover { background: var(--accent-dark); transform: translateY(-1px); }
.button.secondary { background: var(--surface); border: 1px solid var(--line-strong); }
.button.secondary:hover { border-color: var(--accent); color: var(--accent); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.workspace { min-height: calc(100vh - 68px); display: grid; grid-template-columns: minmax(350px, 40%) 1fr; }
.editor-panel { border-right: 1px solid var(--line); background: var(--surface); padding: 28px; display: flex; flex-direction: column; min-width: 0; }
.results-panel { padding: 28px; min-width: 0; display: flex; flex-direction: column; }

.panel-heading, .results-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.eyebrow { display: block; color: var(--accent); font-family: "DM Mono", monospace; font-size: .68rem; letter-spacing: .12em; font-weight: 500; margin-bottom: 7px; }
h1, h2 { margin: 0; letter-spacing: -.04em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.45rem; }
.text-button { background: transparent; color: var(--muted); font-size: .78rem; font-weight: 700; padding: 6px; }
.text-button:hover { color: var(--accent); }

.format-tabs { margin-top: 24px; display: flex; padding: 4px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 9px; }
.format-tab { flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 6px; padding: 9px; cursor: pointer; font-weight: 700; font-size: .8rem; }
.format-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 7px rgba(20, 40, 34, .07); }

.editor-wrap { margin-top: 14px; position: relative; flex: 1; min-height: 390px; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: #101816; }
.editor-meta { height: 39px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; background: #19231f; color: #a6b4af; border-bottom: 1px solid #2d3935; font-family: "DM Mono", monospace; font-size: .69rem; }
#sourceInput { display: block; width: 100%; height: calc(100% - 39px); min-height: 350px; resize: none; border: 0; outline: 0; padding: 18px; background: #101816; color: #d9e6e1; caret-color: #67d4b5; font-family: "DM Mono", monospace; font-size: .78rem; line-height: 1.75; tab-size: 2; }
.drop-overlay { position: absolute; inset: 0; background: rgba(20, 82, 68, .94); color: #fff; display: none; place-items: center; font-weight: 800; z-index: 2; }
.editor-wrap.dragging .drop-overlay { display: grid; }

.error-box { display: none; color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--line)); padding: 10px 12px; margin-top: 10px; border-radius: 8px; font-size: .78rem; line-height: 1.5; }
.error-box.visible { display: block; }
.editor-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }
.upload-button { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.upload-button:hover { color: var(--accent); }
.tip { display: flex; gap: 10px; margin-top: 18px; padding: 14px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line)); border-radius: 9px; }
.tip-icon { flex: 0 0 auto; width: 20px; height: 20px; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; border-radius: 50%; font-size: .7rem; font-weight: 800; }
.tip p { margin: 0; color: var(--muted); font-size: .74rem; line-height: 1.55; }
.tip strong { color: var(--ink); }

.stats { display: flex; gap: 26px; }
.stats div { display: flex; flex-direction: column; min-width: 48px; }
.stats strong { font-size: 1.25rem; letter-spacing: -.04em; }
.stats span { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
.view-tabs { display: flex; gap: 24px; margin-top: 27px; border-bottom: 1px solid var(--line); }
.view-tab { display: inline-flex; align-items: center; gap: 8px; padding: 0 1px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: .8rem; font-weight: 700; }
.view-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.view-tab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.canvas-shell { flex: 1; min-height: 520px; margin-top: 20px; position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: auto; background-color: var(--surface-soft); background-image: radial-gradient(var(--line-strong) .7px, transparent .7px); background-size: 18px 18px; }
.view-pane { display: none; min-height: 100%; padding: 26px; }
.view-pane.active { display: block; }

.schema-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 22px; align-items: start; }
.schema-card { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: 0 8px 22px rgba(29, 49, 43, .06); overflow: hidden; animation: rise .32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.schema-card.parent { border-top: 3px solid var(--accent); }
.schema-card.child { border-top: 3px solid var(--signal); }
.schema-title { padding: 13px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.schema-title h3 { margin: 0; font-family: "DM Mono", monospace; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; }
.schema-title span { color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); padding: 2px 7px; border-radius: 10px; font-size: .62rem; white-space: nowrap; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-family: "DM Mono", monospace; font-size: .68rem; }
.field:last-child { border-bottom: 0; }
.field-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-key { color: var(--signal); font-weight: 500; margin-right: 5px; }
.field-type { color: var(--muted); }
.relation-strip { margin-bottom: 22px; display: flex; flex-wrap: wrap; gap: 8px; }
.relation-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 20px; font-family: "DM Mono", monospace; font-size: .65rem; box-shadow: 0 3px 10px rgba(29, 49, 43, .04); }
.relation-pill b { color: var(--accent); }
.relation-arrow { color: var(--signal); }
.empty-state { min-height: 440px; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-state-inner { max-width: 330px; }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 15px; background: var(--accent-soft); color: var(--accent); font-family: "DM Mono", monospace; font-size: 1.35rem; }
.empty-state h3 { color: var(--ink); margin: 0 0 7px; }
.empty-state p { font-size: .82rem; line-height: 1.6; margin: 0; }

.data-table-section { margin-bottom: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: 0 7px 22px rgba(29, 49, 43, .04); }
.data-table-heading { padding: 13px 15px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.data-table-heading h3 { margin: 0; font-family: "DM Mono", monospace; font-size: .8rem; }
.data-table-heading span { color: var(--muted); font-size: .69rem; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-family: "DM Mono", monospace; font-size: .68rem; white-space: nowrap; }
th, td { text-align: left; padding: 10px 13px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); max-width: 210px; overflow: hidden; text-overflow: ellipsis; }
th { color: var(--muted); background: var(--surface-soft); font-weight: 500; }
td:last-child, th:last-child { border-right: 0; }
tr:last-child td { border-bottom: 0; }

.toast { position: fixed; right: 24px; bottom: 24px; padding: 12px 16px; border-radius: 8px; background: var(--ink); color: var(--surface); box-shadow: var(--shadow); font-size: .78rem; font-weight: 700; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; z-index: 40; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-center { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .editor-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-wrap { min-height: 330px; }
  .results-panel { min-height: 760px; }
}

@media (max-width: 560px) {
  .topbar { height: 60px; padding: 0 16px; }
  .button.secondary { width: 40px; padding: 0; font-size: 0; }
  .editor-panel, .results-panel { padding: 20px 16px; }
  .results-header { flex-direction: column; }
  .stats { width: 100%; justify-content: space-between; }
  .schema-grid { grid-template-columns: 1fr; }
}
