@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --surface-blue: #eff6ff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #1d73c9;
  --primary-strong: #0957d9;
  --success: #059669;
  --warning: #b45309;
  --danger: #e11d48;
  --purple: #6d5bd0;
  --paper: var(--bg);
  --paper-deep: #eef2f7;
  --blue: var(--primary);
  --blue-dark: var(--primary-strong);
  --blue-soft: var(--surface-blue);
  --coral: var(--danger);
  --coral-soft: #fff1f2;
  --green: var(--success);
  --green-soft: #ecfdf5;
  --gold: var(--warning);
  --gold-soft: #fffbeb;
  --shadow-sm: 0 1px 3px rgb(15 23 42 / 5%), 0 1px 2px -1px rgb(15 23 42 / 5%);
  --shadow-md: 0 10px 15px -3px rgb(15 23 42 / 8%), 0 4px 6px -4px rgb(15 23 42 / 8%);
  font-family: "Kanit", "Noto Sans Thai", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { min-height: 100dvh; overflow-x: hidden; background: var(--bg); color: var(--ink); }
button, input, select, textarea { color: inherit; font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid rgb(29 115 201 / 25%); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.eyebrow, .panel-eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-size: 10px; font-weight: 700; letter-spacing: .12em; line-height: 1.2; text-transform: uppercase; }
.eyebrow::before { width: 20px; height: 2px; background: var(--danger); content: ""; }
.panel-eyebrow { color: var(--muted); font-size: 9px; letter-spacing: .1em; }

.brand { display: inline-flex; min-width: 0; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border-radius: 11px; color: white; background: var(--primary); box-shadow: 4px 4px 0 rgb(225 29 72 / 28%); }
.brand-mark svg { width: 23px; height: 23px; }
.brand-mark--small { width: 30px; height: 30px; border-radius: 8px; box-shadow: 3px 3px 0 rgb(225 29 72 / 24%); }
.brand-mark--small svg { width: 18px; height: 18px; }
.brand-name { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.brand-name em, .editor-brand em { color: var(--danger); font-style: normal; }
.brand-tagline { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

.primary-button, .secondary-button, .outline-button, .tool-button, .add-table-button, .add-relation-button, .text-button, .button, .mini-action, .danger-button, .back-to-table {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.primary-button { min-height: 44px; padding: 0 17px; color: white; background: var(--primary); box-shadow: var(--shadow-sm); }
.primary-button:hover { background: var(--primary-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.secondary-button, .outline-button, .tool-button { padding: 0 12px; border: 1px solid rgb(29 115 201 / 28%); color: var(--primary); background: var(--surface); }
.secondary-button { min-height: 44px; }
.secondary-button:hover, .outline-button:hover, .tool-button:hover { border-color: var(--primary); background: var(--surface-blue); }
.text-button { min-height: 30px; padding: 0 3px; color: var(--primary); background: transparent; }
.text-button:hover { color: var(--primary-strong); }
.button--primary { padding-inline: 16px; color: white; border: 1px solid var(--primary); background: var(--primary); }
.button--primary:hover { background: var(--primary-strong); }
.button--quiet { padding-inline: 16px; color: var(--muted); border: 1px solid var(--line); background: var(--surface); }
.button--quiet:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-soft); }
.danger-button { min-height: 36px; padding: 0 12px; color: var(--danger); border: 1px solid #fecdd3; background: var(--coral-soft); }
.danger-button:hover { border-color: #fda4af; background: #ffe4e6; }
.danger-button svg { width: 15px; height: 15px; }
.icon-button { display: inline-grid; width: 36px; height: 36px; flex: none; place-items: center; border: 1px solid transparent; border-radius: 8px; color: var(--primary); background: transparent; }
.icon-button:hover:not(:disabled) { border-color: rgb(29 115 201 / 18%); background: var(--surface-blue); }
.icon-button--danger { color: var(--danger); }
.icon-button--danger:hover:not(:disabled) { border-color: #fecdd3; background: var(--coral-soft); }
.icon-button svg { width: 18px; height: 18px; }

/* Home */
.home-shell { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding-bottom: 72px; }
.home-nav { display: flex; min-height: 72px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.home-nav-right { display: flex; align-items: center; gap: 18px; }
.local-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.local-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgb(5 150 105 / 11%); }
.home-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, .88fr); align-items: center; gap: 58px; padding: 72px 0 66px; }
.hero-copy { max-width: 620px; }
.hero-copy h1 { margin: 16px 0 18px; font-size: clamp(44px, 5.7vw, 76px); font-weight: 700; letter-spacing: -.07em; line-height: 1.05; }
.hero-copy h1 em { position: relative; color: var(--primary); font-style: normal; }
.hero-copy h1 em::after { position: absolute; right: 0; bottom: 2px; left: 1%; height: 8px; z-index: -1; background: rgb(225 29 72 / 18%); content: ""; transform: rotate(-1deg); }
.hero-copy > p { max-width: 590px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.75; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.hero-note { display: flex; max-width: 500px; align-items: center; gap: 9px; margin-top: 24px; color: var(--muted); font-size: 11px; }
.hero-note-icon { display: grid; width: 28px; height: 28px; flex: none; place-items: center; border-radius: 8px; color: var(--warning); background: var(--gold-soft); }
.hero-note-icon svg { width: 16px; height: 16px; }
.hero-diagram { position: relative; height: 360px; }
.hero-diagram__paper { position: absolute; inset: 8px 0 22px; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); background-image: radial-gradient(rgb(203 213 225 / 75%) 1px, transparent 1px); background-size: 18px 18px; box-shadow: var(--shadow-md); }
.hero-diagram__image { display: block; width: 100%; height: 100%; object-fit: contain; }
.template-section, .recent-section { margin-top: 10px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 0 0 20px; }
.section-heading h2 { margin: 8px 0 3px; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.05em; line-height: 1.1; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.template-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; }
.template-card { position: relative; min-width: 0; overflow: hidden; padding: 12px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); text-align: left; background: var(--surface); transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.template-card::after { position: absolute; top: -44px; right: -44px; width: 112px; height: 112px; border-radius: 50%; background: var(--accent-soft); content: ""; }
.template-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.template-card-title { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.template-card-title span { min-width: 0; }
.template-card-title strong { display: block; overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.template-card-title small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.template-card-title i { display: grid; width: 28px; height: 28px; flex: none; place-items: center; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-style: normal; }
.template-card-title i svg { width: 15px; height: 15px; }
.template-card p { min-height: 40px; margin: 8px 0 10px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.template-focus { display: block; padding: 7px 8px; border-left: 3px solid var(--accent); color: var(--accent); background: var(--accent-soft); font-size: 10px; line-height: 1.4; }
.learning-strip { display: grid; grid-template-columns: .9fr 1.1fr; gap: 36px; margin-top: 58px; padding: 25px 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.learning-strip h2 { margin: 8px 0 5px; font-size: 25px; letter-spacing: -.04em; }
.learning-strip p { max-width: 420px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.learning-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.learning-steps > div { display: grid; gap: 4px; min-height: 96px; padding: 13px; border-left: 2px solid var(--primary); background: var(--surface-soft); }
.learning-steps b { color: var(--primary); font-family: Consolas, monospace; font-size: 10px; }
.learning-steps strong { font-size: 13px; }
.learning-steps span { color: var(--muted); font-size: 10px; }
.recent-section { margin-top: 58px; }
.recent-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.recent-card { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.recent-open { width: 100%; padding: 0; color: inherit; text-align: left; background: transparent; }
.recent-kicker { display: block; overflow: hidden; color: var(--primary); font-size: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.recent-card h3 { overflow: hidden; margin: 6px 0 2px; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.recent-card small { color: var(--muted); font-size: 10px; }
.recent-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 13px; color: var(--muted); font-size: 10px; }
.recent-footer > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { display: grid; justify-items: center; padding: 34px; border: 1px dashed var(--line-strong); border-radius: 14px; color: var(--muted); text-align: center; background: var(--surface); }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 8px; color: var(--purple); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 4px 0 0; font-size: 11px; }

/* Editor shell */
.editor-shell { min-height: 100dvh; height: 100dvh; overflow: hidden; background: var(--bg); }
.editor-header { position: fixed; top: 0; right: 0; left: 0; z-index: 100; display: grid; height: 64px; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; min-width: 0; padding: 0 16px; border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 96%); box-shadow: 0 1px 4px rgb(15 23 42 / 6%); backdrop-filter: blur(10px); }
.editor-header-left, .editor-actions { display: flex; min-width: 0; align-items: center; gap: 5px; }
.back-button { display: inline-flex; min-height: 36px; align-items: center; gap: 5px; padding: 0 8px 0 3px; border-radius: 8px; color: var(--primary); background: transparent; font-size: 11px; font-weight: 600; }
.back-button:hover { background: var(--surface-blue); }
.back-button svg { width: 17px; height: 17px; }
.editor-brand { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.editor-title-wrap { display: flex; min-width: 0; align-items: center; gap: 8px; }
.editor-title-wrap input { width: min(420px, 100%); min-width: 0; overflow: hidden; padding: 6px 8px; border: 1px solid transparent; border-radius: 7px; color: var(--ink); font-size: 16px; font-weight: 700; text-overflow: ellipsis; background: transparent; }
.editor-title-wrap input:hover { border-color: var(--line); }
.editor-title-wrap input:focus { border-color: var(--primary); outline: 0; background: var(--surface-blue); }
.editor-title-wrap span { color: var(--muted); font-size: 10px; white-space: nowrap; }
.compact-select { min-height: 36px; max-width: 124px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--primary); background: var(--surface); font-size: 11px; }
.compact-select:hover { border-color: var(--primary); }
.export-menu { position: relative; }
.export-menu summary { list-style: none; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-menu[open] .export-menu__panel { display: grid; }
.export-menu__panel { position: absolute; top: calc(100% + 7px); right: 0; display: none; width: 190px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-md); }
.export-menu__panel button { display: grid; gap: 1px; padding: 9px 10px; border-radius: 7px; color: var(--ink); text-align: left; background: transparent; }
.export-menu__panel button:hover { background: var(--surface-blue); }
.export-menu__panel b { font-size: 11px; }
.export-menu__panel small { color: var(--muted); font-size: 9px; }
.workspace-menu { position: relative; }
.workspace-menu summary { list-style: none; }
.workspace-menu summary::-webkit-details-marker { display: none; }
.workspace-menu[open] .workspace-menu__panel { display: grid; }
.workspace-menu__panel { position: absolute; top: calc(100% + 7px); right: 0; z-index: 120; display: none; width: 250px; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-md); }
.workspace-menu__panel section { display: grid; gap: 3px; }
.workspace-menu__panel section + section { padding-top: 9px; border-top: 1px solid var(--line); }
.workspace-menu__panel section > b { padding: 2px 8px 5px; color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.workspace-menu__panel button { display: flex; width: 100%; min-height: 34px; align-items: center; gap: 8px; padding: 0 8px; border-radius: 7px; color: var(--ink); text-align: left; background: transparent; font-size: 11px; }
.workspace-menu__panel button:hover { color: var(--primary); background: var(--surface-blue); }
.workspace-menu__panel button svg { width: 15px; height: 15px; color: var(--primary); }
.workspace-menu__panel select { width: 100%; min-height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--surface-soft); font-size: 11px; }
.editor-main { display: grid; height: calc(100dvh - 64px); margin-top: 64px; grid-template-columns: 260px minmax(0, 1fr) 320px; }
.editor-shell--personal { --integration-offset: 120px; }
.editor-shell--classroom-teacher { --integration-offset: 218px; }
.editor-shell--classroom-student { --integration-offset: 168px; }
.editor-shell--classroom-review { --integration-offset: 132px; }
.editor-shell--personal .editor-main, .editor-shell--classroom-teacher .editor-main, .editor-shell--classroom-student .editor-main, .editor-shell--classroom-review .editor-main { height: calc(100dvh - var(--integration-offset)); margin-top: var(--integration-offset); }
.integration-panel { position: fixed; top: 64px; right: 0; left: 0; z-index: 90; display: grid; gap: 8px; min-height: 56px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 97%); box-shadow: 0 2px 8px rgb(15 23 42 / 5%); }
.integration-panel__heading, .integration-panel__student-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.integration-panel__heading > div, .integration-panel--review > div, .integration-panel--student > div { display: grid; min-width: 0; gap: 3px; }
.integration-panel__heading strong, .integration-panel--personal strong, .integration-panel--review strong, .integration-panel--student strong { color: var(--ink); font-size: 13px; }
.integration-panel p { margin: 0; color: var(--muted); font-size: 10px; }
.integration-panel__eyebrow { color: var(--primary); font-size: 9px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.integration-panel--personal { display: flex; align-items: center; gap: 9px; }
.integration-panel--personal .integration-status { margin-left: auto; }
.integration-panel__fields { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(170px, 220px) 150px auto; align-items: end; gap: 9px; }
.integration-panel__fields label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 600; }
.integration-panel__fields input, .integration-panel__fields textarea, .integration-panel__fields select { width: 100%; min-height: 32px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--surface-soft); font: inherit; font-size: 11px; }
.integration-panel__fields textarea { resize: vertical; }
.integration-badge { flex: none; padding: 5px 9px; border: 1px solid #bfdbfe; border-radius: 999px; color: var(--primary); background: var(--surface-blue); font-size: 10px; font-weight: 700; }
.integration-panel__save { min-height: 34px; white-space: nowrap; }
.integration-status { color: var(--muted); font-size: 10px; }
.integration-status[data-tone="error"] { color: var(--danger); }
.integration-panel--review { display: flex; align-items: center; justify-content: space-between; }
.integration-panel--student { display: flex; align-items: center; justify-content: space-between; }
.integration-panel__student-actions { justify-content: flex-end; flex: none; }
.integration-panel .button { min-height: 32px; padding: 0 11px; border-radius: 7px; font-size: 10px; }
.editor-shell--read-only .canvas-panel { pointer-events: none; user-select: none; }
.editor-shell--read-only .structure-panel, .editor-shell--read-only .inspector-panel { user-select: text; }
.mobile-structure-toggle { display: none; }
.editor-shell--classroom-teacher { height: auto; min-height: 100dvh; overflow: visible; padding-top: 64px; }
.editor-shell--classroom-teacher .integration-panel { position: relative; top: auto; right: auto; left: auto; width: min(calc(100% - 48px), 1240px); min-height: 0; margin: 20px auto 0; padding: 20px 24px 17px; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm); }
.editor-shell--classroom-teacher .editor-main { height: min(680px, calc(100dvh - 420px)); min-height: 560px; margin-top: 20px; }
.editor-shell--embedded .back-button { display: none; }
.editor-shell.editor-shell--review-modal { height: 100dvh; min-height: 0; padding-top: 0; overflow: hidden; }
.editor-shell.editor-shell--review-modal .editor-header, .editor-shell.editor-shell--review-modal .integration-panel { display: none; }
.editor-shell.editor-shell--review-modal .editor-main { height: 100dvh; margin-top: 0; }
.integration-panel--teacher { gap: 11px; }
.integration-panel--teacher > * { width: min(100%, 1120px); margin-inline: auto; }
.integration-panel__form { display: grid; gap: 10px; }
.integration-panel__form label, .integration-panel__meta label { display: grid; gap: 4px; color: var(--ink); font-size: 10px; font-weight: 600; }
.integration-panel__form input, .integration-panel__form textarea, .integration-panel__form select { width: 100%; min-height: 36px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface-soft); font-size: 11px; }
.integration-panel__form textarea { min-height: 62px; resize: vertical; }
.integration-panel__form input:focus, .integration-panel__form textarea:focus, .integration-panel__form select:focus { border-color: var(--primary); outline: 0; background: var(--surface); }
.integration-panel__meta { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 10px; }
.integration-panel__template-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.integration-panel__template-heading strong { color: var(--ink); font-size: 11px; }
.integration-panel__template-heading span { color: var(--muted); font-size: 10px; }
.integration-panel__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.integration-panel__actions .button:first-child { margin-right: auto; }
.integration-panel__actions .button { min-height: 36px; }
.integration-error { display: grid; min-height: 100dvh; place-content: center; justify-items: center; gap: 10px; padding: 24px; color: var(--ink); text-align: center; }
.integration-error h1 { max-width: 560px; margin: 0; font-size: clamp(22px, 4vw, 38px); }
.integration-error p { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.structure-panel, .inspector-panel { min-width: 0; min-height: 0; overflow-y: auto; background: var(--surface); }
.structure-panel { padding: 18px 13px 20px; border-right: 1px solid var(--line); }
.inspector-panel { border-left: 1px solid var(--line); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 9px; }
.panel-heading h2 { margin: 5px 0 0; font-size: 18px; letter-spacing: -.04em; }
.panel-heading--compact { align-items: center; }
.panel-heading--compact h2 { margin-top: 3px; }
.panel-description { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.count-badge { display: grid; min-width: 25px; height: 25px; place-items: center; border-radius: 7px; color: var(--primary); background: var(--surface-blue); font-family: Consolas, monospace; font-size: 11px; font-weight: 700; }
.count-badge--soft { color: var(--purple); background: #f3f1ff; }
.add-table-button, .add-relation-button { width: 100%; margin-top: 14px; border: 1px dashed rgb(29 115 201 / 38%); color: var(--primary); background: var(--surface-blue); }
.add-table-button:hover, .add-relation-button:hover { border-style: solid; background: #dbeafe; }
.add-table-button svg, .add-relation-button svg { width: 15px; height: 15px; }
.add-relation-button { min-height: 36px; margin-top: 8px; border-color: rgb(109 91 208 / 35%); color: var(--purple); background: #f3f1ff; }
.add-relation-button:hover { background: #ede9fe; }
.table-list, .relation-list { display: grid; gap: 3px; margin-top: 10px; }
.table-list-row, .relation-list-row { display: flex; width: 100%; min-width: 0; align-items: center; gap: 8px; padding: 8px 6px; border: 1px solid transparent; border-radius: 8px; color: var(--ink); text-align: left; background: transparent; }
.table-list-row:hover, .relation-list-row:hover { background: var(--surface-soft); }
.table-list-row.is-selected, .relation-list-row.is-selected { border-color: #bfdbfe; color: var(--primary-strong); background: var(--surface-blue); }
.relation-list-row > span:last-child { display: grid; min-width: 0; gap: 2px; overflow: hidden; }
.table-list-icon, .relation-list-icon { display: grid; width: 27px; height: 27px; flex: none; place-items: center; border-radius: 7px; color: var(--row-color, var(--purple)); background: var(--surface-soft); }
.table-list-icon svg, .relation-list-icon svg { width: 15px; height: 15px; }
.table-list-copy { display: grid; min-width: 0; gap: 2px; }
.table-list-copy b, .relation-list-row b { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.table-list-copy small, .relation-list-row small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.table-list-arrow { display: grid; margin-left: auto; color: var(--muted); }
.table-list-arrow svg { width: 14px; height: 14px; }
.panel-divider { height: 1px; margin: 18px 0; background: var(--line); }
.sidebar-workflow-hint { display: grid; gap: 3px; margin-top: 13px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface-soft); font-size: 10px; line-height: 1.4; }
.sidebar-workflow-hint b { color: var(--ink); font-size: 11px; }
.relation-list-icon { color: var(--purple); background: #f3f1ff; }
.list-empty { padding: 14px 8px; color: var(--muted); font-size: 11px; line-height: 1.6; text-align: center; }
.list-empty small { font-size: 10px; }
.sidebar-lesson { display: flex; align-items: start; gap: 9px; margin-top: 20px; padding: 12px; border: 1px solid #fde68a; border-radius: 10px; color: var(--warning); background: var(--gold-soft); }
.sidebar-lesson__icon { display: grid; width: 24px; height: 24px; flex: none; place-items: center; }
.sidebar-lesson__icon svg { width: 16px; height: 16px; }
.sidebar-lesson b { display: block; font-size: 11px; }
.sidebar-lesson p { margin: 4px 0 7px; color: #78350f; font-size: 10px; line-height: 1.45; }
.sidebar-lesson small { color: #78350f; font-size: 10px; }

/* Canvas */
.canvas-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #eef2f7; background-image: radial-gradient(#cbd5e1 1px, transparent 1px); background-size: 20px 20px; }
.canvas-toolbar { position: absolute; top: 17px; left: 18px; z-index: 10; display: flex; min-height: 36px; align-items: center; gap: 8px; pointer-events: none; }
.canvas-toolbar > * { pointer-events: auto; }
.canvas-title { display: flex; min-width: 0; height: 36px; min-height: 36px; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; background: rgb(255 255 255 / 94%); box-shadow: var(--shadow-sm); }
.canvas-title strong { max-width: 300px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.canvas-tools { display: flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-sm); }
.tool-button { min-height: 32px; padding-inline: 9px; box-shadow: none; }
.canvas-tools .tool-button { white-space: nowrap; }
.tool-button svg { width: 14px; height: 14px; }
.detail-select { width: 118px; min-height: 32px; padding: 0 7px; border: 1px solid var(--line); border-radius: 7px; color: var(--primary); background: var(--surface); font-size: 11px; }
.detail-select:focus { border-color: var(--primary); outline: 0; background: var(--surface-blue); }
.model-status { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 99px; color: var(--success); background: var(--green-soft); font-size: 10px; white-space: nowrap; }
.model-status i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.model-status--warning { color: var(--warning); background: var(--gold-soft); }
.notation-toggle { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.notation-toggle button { min-height: 28px; padding: 0 9px; border-radius: 5px; color: var(--muted); background: transparent; font-family: Consolas, monospace; font-size: 10px; font-weight: 700; }
.notation-toggle button:hover { color: var(--primary); }
.notation-toggle button.is-active { color: white; background: var(--primary); }
.canvas-viewport { position: relative; width: 100%; height: 100%; overflow: hidden; cursor: grab; touch-action: none; }
.canvas-viewport.is-panning { cursor: grabbing; }
.diagram-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.diagram-stage > svg { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; overflow: visible; }
.table-layer { position: absolute; inset: 0; z-index: 2; transform-origin: 0 0; }
.canvas-empty { position: absolute; top: 50%; left: 50%; z-index: 5; display: grid; width: min(270px, calc(100% - 30px)); justify-items: center; padding: 22px; border: 1px dashed var(--line-strong); border-radius: 14px; color: var(--muted); text-align: center; background: rgb(255 255 255 / 96%); box-shadow: var(--shadow-md); transform: translate(-50%, -50%); }
.canvas-empty[hidden] { display: none; }
.canvas-empty > span { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 11px; color: var(--primary); background: var(--surface-blue); }
.canvas-empty > span svg { width: 22px; height: 22px; }
.canvas-empty strong { margin-top: 10px; color: var(--ink); font-size: 15px; }
.canvas-empty p { margin: 5px 0 14px; font-size: 11px; line-height: 1.5; }
.canvas-hint { position: absolute; bottom: 22px; left: 50%; z-index: 8; max-width: calc(100% - 170px); overflow: hidden; padding: 7px 12px; border-radius: 999px; color: var(--muted); background: rgb(255 255 255 / 78%); font-size: 11px; pointer-events: none; text-overflow: ellipsis; transform: translateX(-50%); white-space: nowrap; }
.zoom-control { position: absolute; right: 18px; bottom: 18px; z-index: 8; display: flex; align-items: center; gap: 2px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: rgb(255 255 255 / 94%); box-shadow: var(--shadow-sm); }
.zoom-control button { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 5px; color: var(--primary); background: transparent; font-size: 13px; }
.zoom-control button:hover { background: var(--surface-blue); }
.zoom-control > span { display: grid; min-width: 42px; min-height: 27px; place-items: center; color: var(--muted); font-family: Consolas, monospace; font-size: 11px; }
.canvas-context-menu { position: absolute; z-index: 30; width: 190px; padding: 5px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-md); }
.canvas-context-menu[hidden] { display: none; }
.canvas-context-menu button { display: flex; width: 100%; min-height: 36px; align-items: center; gap: 8px; padding: 0 9px; border-radius: 6px; color: var(--ink); background: transparent; font-size: 11px; text-align: left; }
.canvas-context-menu button:hover { color: var(--primary); background: var(--surface-blue); }
.canvas-context-menu svg { width: 15px; height: 15px; color: var(--primary); }
.canvas-floating-layer { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.canvas-floating-actions { position: absolute; z-index: 20; display: grid; width: 190px; gap: 3px; padding: 6px; border: 1px solid #bfdbfe; border-radius: 9px; background: rgb(255 255 255 / 97%); box-shadow: var(--shadow-md); }
.canvas-floating-actions { pointer-events: auto; }
.canvas-floating-actions__title { display: flex; min-width: 0; align-items: center; gap: 6px; padding: 4px 6px 6px; border-bottom: 1px solid var(--line); color: var(--primary); }
.canvas-floating-actions__title svg { width: 14px; height: 14px; }
.canvas-floating-actions__title strong { overflow: hidden; font-family: Consolas, monospace; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.canvas-floating-actions button { display: flex; width: 100%; min-height: 31px; align-items: center; gap: 7px; padding: 0 7px; border-radius: 6px; color: var(--ink); background: transparent; font-size: 11px; text-align: left; }
.canvas-floating-actions button:hover { color: var(--primary); background: var(--surface-blue); }
.canvas-floating-actions button svg { width: 14px; height: 14px; color: var(--primary); }

/* Relational cards */
.table-card { position: absolute; display: grid; width: 280px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-sm); cursor: grab; user-select: none; transition: border-color .15s ease, box-shadow .15s ease; }
.table-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.table-card.is-selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(29 115 201 / 14%), var(--shadow-md); }
.table-card.is-dragging { cursor: grabbing; opacity: .9; }
.table-card__header { display: flex; min-height: 66px; align-items: start; justify-content: space-between; padding: 11px 12px 9px; color: white; background: var(--table-accent); }
.table-card__eyebrow { display: block; margin-bottom: 3px; color: rgb(255 255 255 / 74%); font-family: Consolas, monospace; font-size: 9px; letter-spacing: .1em; }
.table-card h3 { max-width: 225px; overflow: hidden; margin: 0; font-family: Consolas, "Courier New", monospace; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.table-card__header p { overflow: hidden; margin: 2px 0 0; color: rgb(255 255 255 / 84%); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.table-card__grip { color: rgb(255 255 255 / 66%); font-size: 16px; line-height: 1; }
.table-card__columns { background: var(--surface); }
.table-card__column { display: grid; grid-template-columns: 41px minmax(0, 1fr) auto; min-height: 40px; align-items: center; gap: 5px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.column-key-badges { display: flex; gap: 3px; }
.key-badge { padding: 2px 3px; border-radius: 3px; font-family: Consolas, monospace; font-size: 9px; font-style: normal; font-weight: 700; line-height: 1.1; }
.key-badge--pk { color: var(--warning); background: var(--gold-soft); }
.key-badge--fk { color: var(--primary); background: var(--surface-blue); }
.table-card__column-name { overflow: hidden; font-family: Consolas, monospace; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.table-card__column-type { color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.table-card__footer { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; color: var(--muted); background: var(--surface-soft); font-size: 10px; }
.table-card__footer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-card__empty { padding: 18px; color: var(--muted); font-size: 11px; text-align: center; }

/* Chen notation */
.chen-entity { position: absolute; z-index: 6; display: grid; width: 170px; min-height: 58px; align-content: center; justify-items: center; padding: 8px 10px; border: 2px solid var(--entity-color); color: var(--ink); background: var(--surface); box-shadow: var(--shadow-sm); cursor: grab; user-select: none; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.chen-entity:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.chen-entity.is-selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(29 115 201 / 14%), var(--shadow-md); }
.chen-entity.is-dragging { cursor: grabbing; opacity: .9; }
.chen-entity strong { max-width: 100%; overflow: hidden; font-family: Consolas, monospace; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.chen-attribute { position: absolute; z-index: 4; display: grid; width: 142px; height: 48px; align-content: center; justify-items: center; padding: 6px 10px; overflow: hidden; border: 1.7px solid #94a3b8; border-radius: 50%; color: var(--ink); background: rgb(255 255 255 / 95%); box-shadow: var(--shadow-sm); cursor: pointer; user-select: none; }
.chen-attribute:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(29 115 201 / 12%); }
.chen-attribute span { max-width: 100%; overflow: hidden; font-family: Consolas, monospace; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.chen-attribute.is-key { border-color: var(--warning); }
.chen-attribute.is-key span { font-weight: 700; text-decoration: none; }
.chen-attribute.is-key u { display: inline-block; padding-bottom: 2px; color: inherit; text-decoration: none; border-bottom: 2px solid var(--warning); }
.chen-attribute.is-foreign { border-style: solid; }
.chen-relationship { position: absolute; z-index: 5; display: grid; width: 126px; height: 64px; place-items: center; padding: 12px 22px; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); color: var(--purple); background: var(--purple); cursor: pointer; user-select: none; filter: drop-shadow(0 2px 4px rgb(15 23 42 / 10%)); }
.chen-relationship::after { position: absolute; inset: 3px; z-index: 0; background: #f3f1ff; content: ""; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.chen-relationship span { position: relative; z-index: 1; max-width: 82px; overflow: hidden; color: var(--purple); font-size: 11px; line-height: 1.2; text-align: center; text-overflow: ellipsis; }
.chen-relationship.is-selected { background: var(--primary); }
.chen-relationship.is-selected::after { background: var(--surface-blue); }
.chen-relationship.is-selected span { color: var(--primary); }
.chen-attribute-line { fill: none; stroke: #94a3b8; stroke-width: 1.5; }
.chen-relation-line { fill: none; stroke: #64748b; stroke-width: 2; }
.chen-relation-line--parallel { stroke-width: 1.4; }
.chen-relation-hit { fill: none; stroke: transparent; stroke-width: 24; cursor: pointer; }
.chen-relation.is-selected .chen-relation-line { stroke: var(--primary); stroke-width: 3; }
.chen-cardinality-badge rect { fill: var(--surface); stroke: var(--primary); stroke-width: 1.2; }
.chen-cardinality-badge text { fill: var(--primary-strong); stroke: none; font-family: Consolas, monospace; font-size: 12px; font-weight: 600; }
.chen-cardinality-badge--child rect { stroke: var(--purple); }
.chen-cardinality-badge--child text { fill: var(--purple); }
.chen-cardinality text { fill: var(--primary); font-family: Consolas, monospace; font-size: 11px; font-weight: 600; paint-order: stroke; stroke: white; stroke-width: 3px; stroke-linejoin: round; }
.chen-relation--invalid text { fill: var(--danger); font-family: "Kanit", sans-serif; font-size: 10px; }
.relation-line { fill: none; stroke: #64748b; stroke-width: 2; }
.relation-hit { fill: none; stroke: transparent; stroke-width: 24; cursor: pointer; }
.relation-endpoint { fill: var(--surface); stroke: #64748b; stroke-width: 2; }
.relation.is-selected .relation-line { stroke: var(--primary); stroke-width: 3; }
.cardinality-badge rect { fill: var(--surface); stroke: var(--primary); stroke-width: 1.2; }
.cardinality-badge text { fill: var(--primary-strong); stroke: none; font-family: Consolas, monospace; font-size: 12px; font-weight: 600; }
.cardinality-badge--child rect { stroke: var(--purple); }
.cardinality-badge--child text { fill: var(--purple); }
.relation-description { fill: var(--purple); stroke: none; font-family: "Kanit", sans-serif; font-size: 11px; }
.relation--invalid text { fill: var(--danger); stroke: none; font-family: "Kanit", sans-serif; font-size: 10px; }

/* Inspector */
.inspector-header { display: flex; min-width: 0; align-items: start; justify-content: space-between; gap: 10px; padding: 13px 14px 11px; border-bottom: 1px solid var(--line); }
.inspector-header > div:first-child { min-width: 0; }
.inspector-header h2 { margin: 4px 0 2px; font-size: 18px; letter-spacing: -.04em; }
.inspector-header h2, .inspector-header small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inspector-header small { color: var(--muted); font-size: 10px; }
.inspector-header-tools { display: flex; align-items: center; gap: 9px; }
.inspector-collapse-button { display: none; min-height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--primary); background: var(--surface); font-size: 11px; }
.inspector-collapse-button:hover { border-color: var(--primary); background: var(--surface-blue); }
.inspector-dot { width: 13px; height: 13px; flex: none; margin-top: 4px; border: 3px solid var(--surface); border-radius: 50%; background: var(--dot-color); box-shadow: 0 0 0 2px var(--dot-color); }
.relation-inspector-icon { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 9px; color: var(--purple); background: #f3f1ff; }
.relation-inspector-icon svg { width: 18px; height: 18px; }
.inspector-scroll { display: grid; gap: 12px; padding: 12px; }
.field-group { display: grid; gap: 6px; }
.field-group--table-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-group--table-summary .read-only-field:nth-child(3), .field-group--table-summary .inspector-edit-button { grid-column: 1 / -1; }
.read-only-field { display: grid; gap: 3px; min-height: 44px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.read-only-field span { color: var(--muted); font-size: 9px; }
.read-only-field strong { overflow: hidden; font-family: Consolas, monospace; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.read-only-field p { margin: 0; color: var(--ink); font-size: 11px; line-height: 1.3; }
.inspector-edit-button { width: 100%; min-height: 34px; font-size: 11px; }
.inspector-section { display: grid; gap: 7px; }
.inspector-section__heading { display: flex; align-items: center; justify-content: space-between; gap: 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
.inspector-section__heading small { color: var(--muted); font-size: 10px; font-weight: 400; }
.inspector-section__heading b { color: var(--primary); font-family: Consolas, monospace; }
.inspector-details { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.inspector-details summary { display: flex; min-height: 35px; align-items: center; justify-content: space-between; gap: 8px; padding: 0 9px; color: var(--ink); cursor: pointer; font-size: 11px; font-weight: 600; list-style: none; }
.inspector-details summary::-webkit-details-marker { display: none; }
.inspector-details summary::after { color: var(--primary); content: "+"; font-family: Consolas, monospace; font-size: 15px; font-weight: 400; }
.inspector-details[open] summary::after { content: "−"; }
.inspector-details summary small { margin-left: auto; color: var(--muted); font-size: 10px; font-weight: 400; }
.inspector-details__body { display: grid; gap: 8px; padding: 0 8px 8px; }
.inspector-details__body > .read-only-field { background: var(--surface); }
.inspector-details--danger summary { color: var(--danger); }
.inspector-details--danger summary::after { color: var(--danger); }
.attribute-quick-meta { display: grid; gap: 7px; }
.attribute-type-row { display: flex; min-height: 40px; align-items: center; justify-content: space-between; gap: 8px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.attribute-type-row span { color: var(--muted); font-size: 10px; }
.attribute-type-row strong { color: var(--ink); font-family: Consolas, monospace; font-size: 12px; }
.column-editor__meta { display: flex; min-width: 0; align-items: center; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.column-editor__meta .check-chip { flex: none; }
.column-note { min-width: 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.column-default-state { color: var(--muted); font-size: 10px; }
.attribute-description { margin: 0; color: var(--ink); font-size: 11px; line-height: 1.4; }
.attribute-properties { display: grid; gap: 6px; }
.attribute-properties > div { display: grid; gap: 3px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.attribute-properties span { color: var(--muted); font-size: 8px; }
.attribute-properties strong { font-family: Consolas, monospace; font-size: 11px; }
.attribute-properties p { margin: 0; color: var(--ink); font-size: 10px; line-height: 1.3; }
.color-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.read-only-color { display: flex; align-items: center; gap: 8px; min-height: 24px; color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.read-only-color .color-dot { flex: none; pointer-events: none; }
.color-dot { width: 24px; height: 24px; border: 3px solid var(--surface); border-radius: 50%; background: var(--dot-color); box-shadow: 0 0 0 1px var(--line-strong); }
.color-dot:hover, .color-dot.is-selected { box-shadow: 0 0 0 2px var(--dot-color); }
.mini-action { min-height: 27px; padding: 0 7px; color: var(--primary); background: transparent; font-size: 10px; }
.mini-action:hover { background: var(--surface-blue); }
.column-editor-list { display: grid; gap: 7px; }
.column-editor { padding: 8px; border: 1px solid var(--line); border-left: 3px solid var(--column-accent); border-radius: 9px; background: var(--surface); }
.column-editor__top { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto auto; align-items: center; gap: 5px; }
.column-editor__top--read-only { grid-template-columns: 22px minmax(0, 1fr); }
.column-index { color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.column-name-display { display: flex; min-width: 0; align-items: baseline; gap: 6px; }
.column-name-display strong { overflow: hidden; font-family: Consolas, monospace; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.column-name-display span { flex: none; color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.column-edit-button { min-height: 32px; padding: 0 8px; font-size: 10px; }
.column-editor__options { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.check-chip, .toggle-label { display: inline-flex; min-height: 22px; align-items: center; gap: 4px; padding: 0 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface-soft); font-size: 10px; }
.check-chip.is-on { color: var(--primary); border-color: #bfdbfe; background: var(--surface-blue); }
.toggle-label { border: 0; background: transparent; }
.column-description-readonly { margin: 6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.35; }
.inspector-tip { display: flex; align-items: start; gap: 8px; padding: 10px; border: 1px solid #bfdbfe; border-radius: 8px; color: var(--primary-strong); background: var(--surface-blue); }
.inspector-tip > span { display: grid; flex: none; }
.inspector-tip svg { width: 15px; height: 15px; }
.inspector-tip p { margin: 0; font-size: 10px; line-height: 1.45; }
.inspector-danger { padding-top: 2px; border-top: 1px solid var(--line); }
.inspector-danger .danger-button { width: 100%; margin-top: 13px; }
.inspector-details .inspector-danger .danger-button { margin-top: 0; }
.inspector-empty-state { display: grid; min-height: 100%; align-content: center; justify-items: center; padding: 24px; color: var(--muted); text-align: center; }
.inspector-empty-state > span { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 13px; color: var(--purple); background: #f3f1ff; }
.inspector-empty-state svg { width: 24px; height: 24px; }
.inspector-empty-state h2 { margin: 14px 0 4px; color: var(--ink); font-size: 16px; }
.inspector-empty-state p { max-width: 210px; margin: 0 0 17px; font-size: 10px; line-height: 1.5; }
.inspector-empty-state .outline-button { min-height: 36px; }
.relation-inspector-card { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.relation-inspector-node { display: grid; grid-template-columns: 25px minmax(0, 1fr); gap: 8px; align-items: center; }
.relation-node-badge { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 7px; color: white; background: var(--primary); font-family: Consolas, monospace; font-size: 10px; font-weight: 700; }
.relation-node-badge--child { background: var(--purple); }
.relation-inspector-node div { display: grid; min-width: 0; gap: 2px; }
.relation-inspector-node small { color: var(--muted); font-size: 10px; }
.relation-inspector-node b, .relation-inspector-node span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relation-inspector-node b { font-size: 12px; }
.relation-inspector-node span { color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.relation-inspector-arrow { color: var(--purple); font-family: Consolas, monospace; font-size: 13px; text-align: center; }
.relation-explanation { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.inspector-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.back-to-table { width: 100%; color: var(--primary); background: transparent; }
.back-to-table:hover { background: var(--surface-blue); }

/* Dialogs */
.dialog { width: min(610px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow-md); }
.dialog::backdrop { background: rgb(15 23 42 / 38%); backdrop-filter: blur(3px); }
.dialog form { margin: 0; }
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 14px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 6px 0 0; font-size: 21px; letter-spacing: -.04em; }
.dialog-close { font-size: 22px; line-height: 1; }
.dialog-intro { margin: 15px 20px 0; color: var(--muted); font-size: 11px; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; padding: 14px 20px 18px; border-top: 1px solid var(--line); }
.dialog-hint { margin: 13px 20px 0; padding: 9px 10px; border: 1px solid #fde68a; border-radius: 7px; color: var(--warning); background: var(--gold-soft); font-size: 10px; line-height: 1.5; }
.relation-form-grid { display: grid; grid-template-columns: 1fr 32px 1fr; align-items: center; gap: 8px; margin: 16px 20px 0; }
.relation-side { display: grid; gap: 9px; padding: 12px; border: 1px solid var(--line); border-top: 3px solid var(--primary); border-radius: 9px; background: var(--surface-soft); }
.relation-side--child { border-top-color: var(--purple); background: #f3f1ff; }
.relation-side label, .form-row label, .element-form-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 500; }
.relation-side-label { display: flex; align-items: center; justify-content: space-between; color: var(--primary); font-size: 11px; font-weight: 700; }
.relation-side--child .relation-side-label { color: var(--purple); }
.relation-side-label b { display: grid; width: 21px; height: 21px; place-items: center; border-radius: 50%; color: white; background: var(--primary); font-family: Consolas, monospace; font-size: 9px; }
.relation-side--child .relation-side-label b { background: var(--purple); }
.relation-arrow { color: var(--muted); font-family: Consolas, monospace; font-size: 18px; text-align: center; }
.form-row { display: grid; gap: 9px; margin: 13px 20px 0; }
.form-row--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-group input, .field-group textarea, .form-row input, .form-row select, .relation-side select, .column-description, .element-form-grid input, .element-form-grid select, .element-form-grid textarea { width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); outline: 0; background: var(--surface); font-size: 11px; }
.field-group input:focus, .field-group textarea:focus, .form-row input:focus, .form-row select:focus, .relation-side select:focus, .column-description:focus, .element-form-grid input:focus, .element-form-grid select:focus, .element-form-grid textarea:focus { border-color: var(--primary); background: var(--surface-blue); }
.element-dialog { width: min(540px, calc(100vw - 28px)); }
.element-form-grid { display: grid; gap: 12px; margin: 17px 20px 0; }
.element-form-grid textarea { min-height: 78px; resize: vertical; }
.element-check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 13px 20px 0; }
.element-check-grid label { display: flex; min-height: 35px; align-items: center; gap: 6px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--surface-soft); font-size: 10px; }
.element-check-grid label:has(input:checked) { border-color: #bfdbfe; color: var(--primary-strong); background: var(--surface-blue); }
.element-check-grid input { width: auto; }
.lesson-content, .validation-content { padding: 17px 20px 20px; }
.lesson-focus { display: flex; align-items: start; gap: 9px; padding: 11px; border: 1px solid #bfdbfe; border-radius: 8px; color: var(--primary-strong); background: var(--surface-blue); }
.lesson-focus > span { display: grid; flex: none; }
.lesson-focus svg { width: 17px; height: 17px; }
.lesson-focus small, .lesson-focus strong { display: block; }
.lesson-focus small { font-size: 9px; }
.lesson-focus strong { margin-top: 3px; font-size: 12px; }
.lesson-cards { display: grid; gap: 8px; margin-top: 13px; }
.lesson-cards article { display: grid; grid-template-columns: 34px 1fr; gap: 9px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.lesson-number { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 7px; color: var(--primary); background: var(--surface-blue); font-family: Consolas, monospace; font-size: 10px; font-weight: 700; }
.lesson-number--gold { color: var(--warning); background: var(--gold-soft); }
.lesson-number--green { color: var(--success); background: var(--green-soft); }
.lesson-cards b { font-size: 11px; }
.lesson-cards p { margin: 3px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.lesson-points { margin-top: 13px; padding: 10px; border-radius: 8px; color: var(--muted); background: var(--surface-soft); font-size: 10px; }
.lesson-points b { color: var(--ink); }
.lesson-points ul { display: grid; gap: 4px; margin: 7px 0 0; padding-left: 17px; }
.validation-content { display: grid; gap: 8px; }
.validation-item { display: grid; grid-template-columns: 23px 1fr; gap: 8px; align-items: start; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.validation-item > span { display: grid; width: 21px; height: 21px; place-items: center; border-radius: 6px; color: var(--primary); background: var(--surface-blue); font-family: Consolas, monospace; font-size: 11px; font-weight: 700; }
.validation-item--error > span { color: var(--danger); background: var(--coral-soft); }
.validation-item--warning > span { color: var(--warning); background: var(--gold-soft); }
.validation-item p { margin: 1px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.validation-success { display: grid; justify-items: center; padding: 18px; color: var(--success); text-align: center; background: var(--green-soft); }
.validation-success svg { width: 28px; height: 28px; }
.validation-success strong { margin-top: 7px; color: var(--ink); font-size: 13px; }
.validation-success p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 7px; pointer-events: none; }
.toast { padding: 10px 13px; border-radius: 8px; color: white; background: var(--ink); box-shadow: var(--shadow-md); font-size: 11px; }
.toast--error { background: var(--danger); }

@media (max-width: 1180px) {
  .home-shell { width: min(100% - 34px, 1040px); }
  .home-hero { grid-template-columns: 1fr .9fr; gap: 32px; }
  .template-grid, .recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-main { grid-template-columns: 230px minmax(0, 1fr) 290px; }
  .editor-brand { display: none; }
  .editor-actions .outline-button span, .editor-actions .tool-button span { display: none; }
  .editor-actions .outline-button { width: 36px; padding: 0; }
  .canvas-title strong { max-width: 220px; }
}

@media (max-width: 820px) {
  .integration-panel { top: 56px; padding: 10px 12px; }
  .editor-shell--personal { --integration-offset: 114px; }
  .editor-shell--classroom-teacher { --integration-offset: 292px; }
  .editor-shell--classroom-student { --integration-offset: 205px; }
  .editor-shell--classroom-review { --integration-offset: 170px; }
  .editor-shell--personal .editor-main, .editor-shell--classroom-teacher .editor-main, .editor-shell--classroom-student .editor-main, .editor-shell--classroom-review .editor-main { height: auto; margin-top: var(--integration-offset); }
  .integration-panel__heading, .integration-panel--student, .integration-panel--review { align-items: flex-start; flex-direction: column; }
  .integration-panel__fields { grid-template-columns: 1fr 1fr; }
  .integration-panel__fields label:first-child { grid-column: 1 / -1; }
  .integration-panel__save { width: 100%; }
  .integration-panel__student-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .integration-panel--personal { flex-wrap: wrap; }
  .integration-panel--personal .integration-status { margin-left: 0; }
  .home-shell { width: calc(100% - 28px); }
  .home-nav { min-height: 62px; }
  .home-nav-right { gap: 10px; }
  .local-status { display: none; }
  .home-hero { display: block; padding: 45px 0 42px; }
  .hero-copy h1 { font-size: clamp(42px, 12vw, 64px); }
  .hero-diagram { height: 310px; margin-top: 30px; }
  .learning-strip { grid-template-columns: 1fr; gap: 20px; padding: 21px; }
  .editor-shell { height: auto; min-height: 100dvh; overflow: visible; padding-top: 56px; }
  .editor-header { height: 56px; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px; padding: 0 8px; }
  .editor-title-wrap input { width: 100%; font-size: 14px; }
  .editor-title-wrap span { display: none; }
  .editor-actions { max-width: none; overflow: visible; gap: 3px; }
  .editor-actions .compact-select { max-width: 86px; }
  .editor-main { position: relative; display: flex; height: auto; margin-top: 0; flex-direction: column; }
  .canvas-panel { order: 1; height: 66vh; min-height: 480px; }
  .structure-panel { position: fixed; top: auto; right: 0; bottom: 0; left: 0; z-index: 80; order: 2; width: auto; height: min(72dvh, 520px); max-height: none; padding: 18px 16px 25px; border-top: 1px solid var(--line); border-right: 0; border-radius: 22px 22px 0 0; box-shadow: 0 -15px 50px rgb(15 23 42 / 14%); transform: translateY(105%); transition: transform 220ms ease; }
  .structure-panel.is-open { transform: translateY(0); }
  .inspector-panel { order: 3; min-height: 500px; border-top: 1px solid var(--line); border-left: 0; }
  .inspector-panel.is-collapsed { min-height: 0; }
  .inspector-panel.is-collapsed .inspector-scroll { display: none; }
  .inspector-collapse-button { display: inline-flex; align-items: center; justify-content: center; }
  .mobile-structure-toggle { display: inline-grid; }
  .editor-actions #redo-button { display: none; }
  .canvas-toolbar { top: 12px; left: 12px; min-height: 36px; }
  .canvas-title { max-width: 170px; }
  .canvas-title .panel-eyebrow { display: none; }
  .canvas-title strong { max-width: 120px; font-size: 11px; }
  .canvas-title .model-status { display: none; }
  .canvas-tools { gap: 2px; }
  .canvas-tools .tool-button { width: 32px; padding: 0; }
  .canvas-tools .tool-button span { display: none; }
  .detail-select { width: 88px; padding-inline: 5px; }
  .canvas-hint { bottom: 72px; max-width: calc(100% - 150px); }
  .zoom-control { right: 12px; bottom: 12px; }
  .relation-form-grid, .form-row--two { grid-template-columns: 1fr; }
  .relation-arrow { transform: rotate(90deg); }
  .editor-shell--classroom-teacher { padding-top: 56px; }
  .editor-shell--classroom-teacher .integration-panel { width: calc(100% - 24px); margin-top: 12px; padding: 16px; }
  .editor-shell--classroom-teacher .editor-main { height: auto; min-height: 0; margin-top: 12px; }
  .editor-shell--classroom-teacher .integration-panel__meta { grid-template-columns: 1fr 1fr; }
  .editor-shell--classroom-teacher .integration-panel__template-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
}

@media (max-width: 560px) {
  .brand-mark { width: 35px; height: 35px; border-radius: 10px; }
  .brand-name { font-size: 18px; }
  .brand-tagline { display: none; }
  .home-nav-right .text-button { font-size: 10px; }
  .hero-actions { display: grid; }
  .hero-actions button { width: 100%; }
  .hero-diagram { height: 285px; }
  .template-grid, .recent-grid { grid-template-columns: 1fr; }
  .learning-steps { grid-template-columns: 1fr; }
  .editor-actions .compact-select { max-width: 76px; }
  .editor-actions .outline-button { width: 34px; }
  .canvas-title { max-width: 132px; }
  .canvas-title strong { max-width: 80px; }
  .detail-select { width: 78px; }
  .element-check-grid { grid-template-columns: 1fr; }
  .dialog { width: calc(100vw - 18px); border-radius: 11px; }
  .dialog-header, .dialog-actions { padding-inline: 15px; }
  .dialog-intro, .dialog-hint, .relation-form-grid, .form-row, .element-form-grid, .element-check-grid { margin-left: 15px; margin-right: 15px; }
}

@media (max-width: 360px) {
  .canvas-title { max-width: 28%; }
  .canvas-title strong { max-width: 68px; }
  .detail-select { width: 70px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 1180px) {
  .editor-actions .workspace-menu .outline-button { width: auto; padding-inline: 9px; }
  .editor-actions .workspace-menu .outline-button span { display: inline; }
}

@media (max-width: 820px) {
  .back-button span { display: none; }
  .editor-actions .workspace-menu .outline-button { width: auto; min-width: 36px; padding-inline: 8px; }
  .workspace-menu__panel { right: -5px; width: min(250px, calc(100vw - 20px)); }
}
