:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #1d2330;
  --muted: #6b7280;
  --accent: #2563eb;
  --danger: #c62828;
  --side: #1f2430;
  --side-text: #c9cfdb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: grid; grid-template-columns: 260px 1fr; background: var(--bg); }

/* ---------- sidebar ---------- */
#sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; color: #fff; padding: 16px 16px 10px; }
.brand .logo { color: #7aa2ff; }
#side-search { margin: 0 12px 8px; padding: 7px 10px; border-radius: 6px; border: 1px solid #3a4254; background: #2a303d; color: #fff; }
#side-lists { flex: 1; overflow: auto; padding-bottom: 12px; }
.side-sec { margin-top: 10px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px 4px 16px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8b93a5; }
.side-head button, .side-head summary { background: #2f3646; border: 0; color: #dfe5f1; border-radius: 4px; width: 22px; height: 20px; cursor: pointer; font-size: 14px; line-height: 20px; text-align: center; list-style: none; padding: 0; }
.side-head summary::-webkit-details-marker { display: none; }
.side-head button:hover, .side-head summary:hover { background: #3d465b; }
details.menu { position: relative; }
details.menu > div { position: absolute; right: 0; top: 24px; z-index: 20; background: #fff; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 4px; min-width: 230px; }
details.menu > div button { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 4px; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 13px; cursor: pointer; }
details.menu > div button:hover { background: #eef2ff; }
.side-item { display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 18px; color: var(--side-text); text-decoration: none; font-size: 13px; }
.side-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item:hover { background: #2a303d; color: #fff; }
.side-item.active { background: #34405a; color: #fff; }
.side-empty { padding: 3px 18px; font-size: 12px; color: #6f778a; font-style: italic; }
.side-footer { border-top: 1px solid #333b4c; padding: 10px 16px; display: flex; justify-content: space-between; }
.side-footer a { color: #9fb3d9; text-decoration: none; font-size: 12px; }
.ico { flex: none; vertical-align: -2px; }
.side-item .ico.conceptual { color: #9aa6ff; }
.side-item .ico.physical { color: #6fd39b; }
.side-item .ico.app { color: #ffb35c; }
.side-item .ico.flow { color: #e0a7ff; }

/* ---------- main / pages ---------- */
#main { min-width: 0; height: 100vh; overflow: auto; }
.page { max-width: 1100px; padding: 22px 28px 60px; }
.page h1 { margin: 0 0 6px; font-size: 22px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.title-input { font-size: 20px; font-weight: 650; border: 1px solid transparent; background: transparent; padding: 4px 8px; border-radius: 6px; flex: 1; min-width: 200px; color: var(--text); }
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--accent); background: #fff; outline: none; }
.title-input.sm { font-size: 15px; flex: 0 1 220px; min-width: 120px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols > .card { margin-bottom: 14px; }
textarea { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 8px; resize: vertical; }
input, select, button { font: inherit; }
input[type=text], input:not([type]), select { border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; background: #fff; }
input[type=color] { width: 40px; height: 26px; padding: 0 2px; border: 1px solid var(--line); border-radius: 4px; background: #fff; vertical-align: middle; }
button, .btn { border: 1px solid #cfd5df; background: #fff; border-radius: 6px; padding: 5px 11px; cursor: pointer; color: var(--text); text-decoration: none; display: inline-block; font-size: 13px; }
button:hover, .btn:hover { background: #f0f3f8; }
button:disabled { opacity: .35; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #1d4fd0; }
button.danger { color: var(--danger); border-color: #efc2c2; }
button.danger:hover { background: #fdeeee; }
button.on { background: #e1e9ff; border-color: var(--accent); color: var(--accent); }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--accent); }
.kind-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 4px; border: 1.5px solid; white-space: nowrap; }
.kind-chip.conceptual { border-style: dashed; }
.kind-chip.app { border-radius: 10px; }
.elink { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.elink:hover { text-decoration: underline; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 4px 6px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.tbl td.c, .tbl th.c { text-align: center; }
.tbl input:not([type=checkbox]), .tbl select { width: 100%; }
.tbl td.actions { white-space: nowrap; text-align: right; width: 1%; }
.tbl td.actions button { padding: 2px 7px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 3px; background: #eef2ff; color: #3949ab; white-space: nowrap; }
.tag.pk { background: #fff3cd; color: #8a6100; }

ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 3px 0; display: flex; align-items: center; gap: 6px; }
.diagram-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.dcard { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; text-decoration: none; color: var(--text); }
.dcard:hover { border-color: var(--accent); }
.dcard b { display: flex; align-items: center; gap: 6px; }
.help li { margin-bottom: 4px; }

/* ---------- diagram page ---------- */
.diagram-page { display: grid; grid-template-columns: 1fr 300px; grid-template-rows: auto 1fr; height: 100vh; }
.toolbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
#zoom-lbl { width: 44px; text-align: center; font-size: 12px; color: var(--muted); }
.canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; user-select: none; touch-action: none; cursor: grab; background: #fbfcfd; }
#canvas.connecting { cursor: crosshair; }
.hint { position: absolute; left: 12px; bottom: 12px; background: rgba(29,35,48,.88); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; pointer-events: none; }
.hint:empty { display: none; }
.inspector { border-left: 1px solid var(--line); background: #fff; overflow: auto; padding: 14px; }
.inspector h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.inspector label { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; }
.inspector label > input:not([type=color]), .inspector label > select { display: block; width: 100%; margin-top: 3px; color: var(--text); }
.inspector .btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.mini-fields li { font-size: 12px; justify-content: space-between; border-bottom: 1px dotted #eceff3; }
.mini-fields .t { color: var(--muted); }
.io-list { max-width: 460px; }
.io-list li { justify-content: space-between; }
.io-list li button { padding: 0 6px; }

/* svg */
#canvas text { font-family: inherit; }
.node { cursor: move; }
.node .title { font-weight: 650; font-size: 13px; fill: #1d2330; }
.node .fname { font-size: 12px; fill: #222; }
.node .fname.nullable { font-style: italic; fill: #555; }
.node .ftype { font-size: 11px; fill: #6b7280; font-family: ui-monospace, Menlo, Consolas, monospace; }
.node .fmark { font-size: 9px; font-weight: 700; fill: #3949ab; }
.node .fmark.pk { fill: #a86f00; }
.node .fempty { font-size: 11px; fill: #9aa1ad; font-style: italic; }
.sel-ring { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 3; }
.node.from .body { stroke: var(--accent) !important; stroke-width: 3 !important; }
.goto { cursor: pointer; font-size: 15px; fill: #2563eb; font-weight: 700; }
.goto:hover { fill: #0b3aa8; }
.rel { cursor: pointer; }
.rel .hit { stroke: transparent; stroke-width: 14; fill: none; }
.rel .line { fill: none; stroke-width: 1.6; }
.rel.sel .line { stroke: var(--accent) !important; stroke-width: 2.6; }
.rel text { font-size: 11px; paint-order: stroke; stroke: #fbfcfd; stroke-width: 4px; stroke-linejoin: round; }
.rel .card { font-weight: 700; fill: #333; }
.rel .rel-label { fill: #444; font-style: italic; }
.port { cursor: pointer; }
.port text { font-size: 11px; fill: #1d2330; }
.port:hover rect { filter: brightness(.95); }
.port.sel rect.pbody { stroke: var(--accent) !important; stroke-width: 2.5; }
.flow-link { fill: none; stroke: #8892a6; stroke-width: 1.6; }
.io-cap { font-size: 9px; fill: #9a7a52; text-transform: uppercase; letter-spacing: .05em; }
