/* ════════════════════════════════════════════════
   ERStudio — style.css
   Design system, layout, components
   ════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ─────────────────────────────── */
:root {
  /* Surfaces */
  --bg:          #13131f;
  --surface:     #1e1e2e;
  --surface-2:   #181825;
  --surface-3:   #11111b;
  /* Borders */
  --border:      #2a2a3e;
  --border-2:    #313244;
  /* Text */
  --text:        #cdd6f4;
  --subtext:     #a6adc8;
  --muted:       #585b70;
  /* Accent */
  --accent:      #89b4fa;
  --accent-2:    #cba6f7;
  /* Semantic */
  --green:       #a6e3a1;
  --yellow:      #f9e2af;
  --red:         #f38ba8;
  --teal:        #94e2d5;
  --sky:         #89dceb;
  --peach:       #fab387;
  /* Canvas */
  --canvas-bg:   #0c0c1a;
  --dot-color:   rgba(255, 255, 255, 0.04);
  /* Elevation */
  --shadow:      0 8px 32px rgba(0, 0, 0, 0.55);
  --shadow-sm:   0 2px 10px rgba(0, 0, 0, 0.35);
  /* Radii & Fonts */
  --radius:      8px;
  --font-ui:     'Syne', sans-serif;
  --font-code:   'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg:          #f0f2f8;
  --surface:     #ffffff;
  --surface-2:   #f5f7fc;
  --surface-3:   #eaecf4;
  --border:      #dde1ee;
  --border-2:    #c8cedf;
  --text:        #2c3148;
  --subtext:     #5a6278;
  --muted:       #9099b0;
  --accent:      #4361ee;
  --accent-2:    #7048e8;
  --green:       #2d9d50;
  --yellow:      #c77a0a;
  --red:         #d63031;
  --teal:        #00b4a0;
  --sky:         #00a8cc;
  --peach:       #e07b3b;
  --canvas-bg:   #e2e6f2;
  --dot-color:   rgba(0, 0, 0, 0.065);
  --shadow:      0 8px 32px rgba(0, 0, 0, 0.13);
  --shadow-sm:   0 2px 10px rgba(0, 0, 0, 0.09);
}

/* ── RESET & BASE ───────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ── SCROLLBARS ─────────────────────────────────── */
::-webkit-scrollbar             { width: 5px; height: 5px; }
::-webkit-scrollbar-track       { background: transparent; }
::-webkit-scrollbar-thumb       { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ══════════════════════════════════════════════════
   TOOLBAR
══════════════════════════════════════════════════ */
#toolbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 8px;
  z-index: 100;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 4px;
  flex-shrink: 0;
}

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.logo-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text);
}

.logo-sub {
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
}

/* Separator */
.t-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}

/* Search */
.search-wrap {
  position: relative;
  flex: 0 1 210px;
}

.search-wrap svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 6px 10px 6px 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus   { border-color: var(--accent); }
#search-input::placeholder { color: var(--muted); }

/* Syntax pill */
#syn-pill {
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-size: 10px;
  font-family: var(--font-code);
  color: var(--muted);
  flex-shrink: 0;
  transition: color 0.2s;
}

/* Right cluster */
.t-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover { background: var(--border-2); }

.btn.accent {
  background: var(--accent);
  border-color: transparent;
  color: #11111b;
}

.btn.accent:hover { filter: brightness(1.1); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--border-2); }

/* ══════════════════════════════════════════════════
   MAIN LAYOUT
══════════════════════════════════════════════════ */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════
   EDITOR PANEL
══════════════════════════════════════════════════ */
#editor-panel {
  width: 340px;
  min-width: 180px;
  max-width: 650px;
  flex-shrink: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

#editor-head {
  padding: 8px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface-3);
}

#err-flag {
  color: var(--red);
  font-size: 10px;
  font-weight: 600;
  display: none;
}

#editor-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Mirrored textarea + highlight layer */
#code-hl,
#code-ed {
  position: absolute;
  inset: 0;
  font: 500 12.5px / 1.75 var(--font-code);
  padding: 14px 16px;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  word-wrap: normal;
}

#code-hl {
  color: var(--text);
  pointer-events: none;
  z-index: 1;
  background: transparent;
}

#code-ed {
  color: transparent;
  caret-color: var(--text);
  background: transparent;
  z-index: 2;
  resize: none;
  border: none;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

#code-ed::selection { background: rgba(137, 180, 250, 0.18); }

/* Resize handle */
#resize-handle {
  position: absolute;
  right: -3px;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 200;
  background: transparent;
  transition: background 0.15s;
}

#resize-handle:hover,
#resize-handle.active {
  background: var(--accent);
  opacity: 0.45;
}

/* ── SYNTAX HIGHLIGHT TOKENS ────────────────────── */
.hk   { color: var(--accent-2); font-weight: 600; }   /* keyword     */
.ht   { color: var(--teal); }                          /* type        */
.ho   { color: var(--yellow); }                        /* option      */
.hs   { color: var(--green); }                         /* string      */
.hc   { color: var(--muted); font-style: italic; }     /* comment     */
.hn   { color: var(--accent); font-weight: 600; }      /* name        */
.hnum { color: var(--peach); }                         /* number      */
.hop  { color: var(--red); }                           /* operator    */

[data-theme="light"] .hk   { color: #8839ef; }
[data-theme="light"] .ht   { color: #179299; }
[data-theme="light"] .ho   { color: #df8e1d; }
[data-theme="light"] .hs   { color: #40a02b; }
[data-theme="light"] .hc   { color: #9ca0b0; }
[data-theme="light"] .hn   { color: #1e66f5; }
[data-theme="light"] .hnum { color: #fe640b; }
[data-theme="light"] .hop  { color: #d20f39; }

/* ══════════════════════════════════════════════════
   CANVAS
══════════════════════════════════════════════════ */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
  background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
  background-size: 24px 24px;
}

#canvas-wrap.panning { cursor: grabbing; }

#world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

#rel-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════
   TABLE CARDS
══════════════════════════════════════════════════ */
.table-card {
  position: absolute;
  width: 240px;
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  user-select: none;
  overflow: hidden;
  transition: box-shadow 0.18s, border-color 0.18s, opacity 0.18s;
  animation: card-in 0.18s ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.table-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--muted);
}

.table-card.highlighted {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.15), var(--shadow) !important;
}

.table-card.dimmed  { opacity: 0.14; }
.table-card.s-hide  { opacity: 0.1; }

/* Card header */
.card-head {
  padding: 0 11px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: grab;
}

.card-head:active { cursor: grabbing; }

.card-title {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  font-family: var(--font-code);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-alias {
  font-size: 9px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
  font-family: var(--font-code);
  flex-shrink: 0;
}

/* Column rows */
.col-row {
  display: flex;
  align-items: center;
  height: 27px;
  padding: 0 7px 0 5px;
  border-top: 1px solid var(--border);
  gap: 3px;
}

.col-row:hover { background: rgba(137, 180, 250, 0.05); }

.col-badges {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  width: 28px;
  justify-content: flex-end;
}

.badge {
  font-size: 7px;
  font-weight: 700;
  font-family: var(--font-code);
  padding: 1px 3px;
  border-radius: 2px;
}

.badge-pk { background: rgba(249,226,175,0.18); color: var(--yellow); border: 1px solid rgba(249,226,175,0.3); }
.badge-fk { background: rgba(137,220,235,0.18); color: var(--sky);    border: 1px solid rgba(137,220,235,0.3); }

.col-name {
  flex: 1;
  font-size: 11.5px;
  font-family: var(--font-code);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-right {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.col-type {
  font-size: 10px;
  font-family: var(--font-code);
  color: var(--subtext);
  white-space: nowrap;
}

.col-constraints {
  display: flex;
  gap: 2px;
}

.cn {
  font-size: 7px;
  font-weight: 700;
  padding: 1px 3px;
  border-radius: 2px;
  cursor: default;
  line-height: 1.5;
}

.cn-nn { color: var(--red);   background: rgba(243,139,168,0.1); border: 1px solid rgba(243,139,168,0.25); }
.cn-uq { color: var(--teal);  background: rgba(148,226,213,0.1); border: 1px solid rgba(148,226,213,0.25); }
.cn-df { color: var(--peach); background: rgba(250,179,135,0.1); border: 1px solid rgba(250,179,135,0.25); }
.cn-ai { color: var(--green); background: rgba(166,227,161,0.1); border: 1px solid rgba(166,227,161,0.25); }

/* Index section */
.idx-section { border-top: 1px solid var(--border); }

.idx-head {
  padding: 0 9px;
  height: 23px;
  display: flex;
  align-items: center;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  background: var(--surface-3);
}

.idx-row {
  display: flex;
  align-items: center;
  height: 21px;
  padding: 0 9px;
  border-top: 1px solid var(--border);
  gap: 6px;
}

.idx-cols {
  font-size: 10px;
  font-family: var(--font-code);
  color: var(--subtext);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.idx-opts {
  font-size: 8px;
  font-family: var(--font-code);
  color: var(--muted);
  white-space: nowrap;
}

/* ══════════════════════════════════════════════════
   RELATIONSHIP SVG
══════════════════════════════════════════════════ */
.rel-path {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: stroke 0.18s, stroke-width 0.18s;
}

.rel-path.highlighted { stroke: var(--accent); stroke-width: 2; }

.rel-label {
  font-family: var(--font-code);
  font-size: 10px;
  font-weight: 700;
  fill: var(--muted);
  transition: fill 0.18s;
}

.rel-label.highlighted { fill: var(--accent); }

.rel-dot { transition: fill 0.18s; }

/* ══════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════ */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  gap: 12px;
}

#empty-state svg { opacity: 0.12; }

#empty-state p {
  font-size: 14px;
  color: var(--subtext);
  opacity: 0.45;
  text-align: center;
}

#empty-state small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.6;
  text-align: center;
  line-height: 1.6;
}

/* ══════════════════════════════════════════════════
   ZOOM CONTROLS
══════════════════════════════════════════════════ */
#zoom-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 50;
}

.zoom-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 17px;
  color: var(--text);
  font-family: var(--font-ui);
  transition: all 0.15s;
  line-height: 1;
}

.zoom-btn:hover { background: var(--border-2); }

#zoom-label {
  padding: 3px 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 9px;
  font-family: var(--font-code);
  color: var(--subtext);
  text-align: center;
}

/* ══════════════════════════════════════════════════
   MINIMAP
══════════════════════════════════════════════════ */
#minimap {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

#minimap-head {
  padding: 4px 9px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#minimap-canvas { display: block; cursor: pointer; }

/* ══════════════════════════════════════════════════
   STATUS BAR
══════════════════════════════════════════════════ */
#statusbar {
  height: 24px;
  background: var(--surface-3);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 16px;
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-code);
  flex-shrink: 0;
}

#statusbar b    { color: var(--subtext); }
#st-mode        { margin-left: auto; color: var(--muted); }
