/* Variables */
:root {
  --fondo:   #f4f6fb;
  --panel:   #ffffff;
  --linea:   #d7dceb;
  --texto:   #1f2937;
  --muted:   #6b7280;
  --acento:  #2563eb;
  --peligro: #dc2626;
  --ok:      #059669;
  --lienzo:  #ffffff;
  --sombra:  0 10px 25px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  overflow: hidden;
}

/* App */
.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

/* sidebar */
.sidebar {
  width: 300px;
  background: #0d1117;
  color: #e8edf5;
  display: flex;
  flex-direction: column;
  padding: 0;
  border-right: 1px solid rgba(255,255,255,0.06);
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar       { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

/* Brand */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 13px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand-logo     { width:36px; height:36px; border-radius:9px; overflow:hidden; flex-shrink:0; }
.sidebar-brand-logo img { width:100%; height:100%; object-fit:cover; display:block; }
.sidebar-brand-text     { display:flex; flex-direction:column; gap:2px; min-width:0; }
.sidebar-brand h1       { margin:0; font-size:15px; font-weight:700; color:#ffffff; letter-spacing:0.2px; line-height:1; }
.sidebar-brand-sub      { font-size:10px; color:#8899aa; letter-spacing:0.4px; }

.sidebar-brand-badge {
  margin-left:auto; display:inline-flex; align-items:center; gap:5px;
  background:rgba(16,185,129,0.10); color:#34d399;
  border:1px solid rgba(52,211,153,0.18); border-radius:20px;
  padding:3px 8px; font-size:10px; font-weight:600; flex-shrink:0;
}
.badge-dot { width:5px; height:5px; border-radius:50%; background:#34d399; flex-shrink:0; }

/* Ícono SVG diagrama ER en brand */
.sidebar-brand-icon-wrap {
  width:56px; height:56px; border-radius:14px; flex-shrink:0;
  background: linear-gradient(135deg, rgba(124,58,237,0.28) 0%, rgba(91,33,182,0.14) 100%);
  border:1px solid rgba(124,58,237,0.35);
  display:flex; align-items:center; justify-content:center;
  position:relative; overflow:hidden;
  box-shadow:0 4px 16px rgba(124,58,237,0.2);
}
.sidebar-brand-icon-wrap::before {
  content:''; position:absolute;
  width:44px; height:44px; border-radius:50%;
  right:-12px; bottom:-12px;
  background:rgba(124,58,237,0.1); border:1px solid rgba(124,58,237,0.15);
}
.sidebar-brand-icon {
  width:38px; height:38px; position:relative; z-index:1;
  filter:drop-shadow(0 3px 6px rgba(0,0,0,0.35));
}

/* Secciones */
.section          { margin-bottom:0; padding:14px 14px 0; }
.section:last-of-type { padding-bottom:14px; }
.section h2 {
  font-size:10px; text-transform:uppercase; letter-spacing:1.2px;
  color:#7a8fa3; font-weight:700; margin:0 0 9px;
  display:flex; align-items:center; gap:7px;
}
.section h2::after { content:''; flex:1; height:1px; background:rgba(255,255,255,0.07); }

/* botones */
.btn {
  background: rgba(255,255,255,0.06); color: #dde5f0;
  border: 1px solid rgba(255,255,255,0.10);
  padding:9px 10px; border-radius:8px; font-size:12px;
  cursor:pointer; transition:background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  text-align:center;
}
.btn:hover   { background:rgba(255,255,255,0.11); border-color:rgba(255,255,255,0.18); color:#ffffff; transform:translateY(-1px); }
.btn.active  { background:rgba(37,99,235,0.28); border-color:rgba(59,130,246,0.55); color:#93c5fd; font-weight:700; box-shadow:0 0 0 2px rgba(37,99,235,0.15); }
.btn.danger  { background:rgba(220,38,38,0.14); color:#fca5a5; border-color:rgba(248,113,113,0.25); }
.btn.danger:hover  { background:rgba(220,38,38,0.26); border-color:rgba(248,113,113,0.45); color:#fecaca; }
.btn.primary { background:rgba(37,99,235,0.22); color:#93c5fd; border-color:rgba(59,130,246,0.35); font-weight:600; }
.btn.primary:hover { background:rgba(37,99,235,0.35); border-color:rgba(59,130,246,0.55); color:#bfdbfe; }
.btn.success { background:rgba(5,150,105,0.18); color:#6ee7b7; border-color:rgba(52,211,153,0.3); font-weight:600; }

.btn-grid { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.btn.full { width:100%; margin-top:10px; }
.row      { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-top:8px; }

/* Panel box */
.panel-box { background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.07); border-radius:10px; padding:11px; }

/* Inputs */
button, select, input, textarea { font: inherit; }

.sidebar input:not([type="checkbox"]),
.sidebar select,
.sidebar textarea {
  width:100%; margin-top:4px; margin-bottom:9px;
  padding:8px 10px; border-radius:7px;
  border:1px solid rgba(255,255,255,0.11);
  background:rgba(255,255,255,0.05); color:#e8edf5;
  font-size:12px; transition:border-color 0.15s, box-shadow 0.15s;
}
.sidebar select option { background:#1a2233; color:#e8edf5; }
.sidebar input:not([type="checkbox"]):focus,
.sidebar select:focus,
.sidebar textarea:focus {
  outline:none; border-color:rgba(59,130,246,0.55);
  box-shadow:0 0 0 2px rgba(37,99,235,0.18);
}
.sidebar input::placeholder { color:#4a5a6e; }
.sidebar label { display:block; font-size:11px; color:#8899aa; margin-bottom:2px; letter-spacing:0.2px; }
.label-checkbox { display:flex !important; align-items:center; gap:6px; font-size:12px !important; color:#aab8c8 !important; margin-bottom:4px !important; cursor:pointer; }
.sidebar input[type="checkbox"] { width:auto; margin:0; accent-color:#3b82f6; cursor:pointer; }

.small { font-size:11px; color:#7a8fa3; line-height:1.6; }
.hint  { font-size:11px; color:#7a8fa3; margin-top:6px; line-height:1.7; }

/* Créditos */
.creditos { margin-top:auto; padding:12px 14px 14px; border-top:1px solid rgba(255,255,255,0.05); }
.tarjeta-creditos { background:rgba(255,255,255,0.02); border:1px solid rgba(255,255,255,0.05); border-radius:12px; padding:11px 10px; text-align:center; }
.tarjeta-creditos .titulo  { font-size:10px; color:#3d4d5e; font-weight:500; }
.tarjeta-creditos .version { font-size:10px; color:#2e3d4e; letter-spacing:0.3px; margin-top:1px; }
.tarjeta-creditos .autor   { font-size:12px; font-weight:600; color:#8a9bb0; margin-top:6px; }
.tarjeta-creditos .correo  { font-size:10px; color:#2e3d4e; margin-top:1px; }

/* Logo JC dentro del card de créditos */
.creditos-logo { display:flex; justify-content:center; margin-bottom:9px; }
.creditos-logo img {
  width:44px; height:44px; border-radius:11px; object-fit:cover;
  border:1px solid rgba(255,255,255,0.10);
  box-shadow:0 2px 8px rgba(0,0,0,0.35);
}

/* canvas */
.canvas-wrap {
  position: relative;
  overflow: auto;
  background:
    linear-gradient(to right,  rgba(37,99,235,.06) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(to bottom, rgba(37,99,235,.06) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--lienzo);
}

/* el topbar */
.topbar {
  position: sticky; left: 12px; top: 12px; z-index: 30;
  width: max-content; margin: 12px;
  background: rgba(255,255,255,.95);
  border: 1px solid var(--linea); border-radius: 14px;
  padding: 8px; box-shadow: var(--sombra);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.toolbar-group { display:flex; align-items:center; gap:6px; padding-right:8px; margin-right:4px; border-right:1px solid var(--linea); }
.toolbar-group:last-child { border-right:0; padding-right:0; margin-right:0; }
.icon-btn { width:38px; height:38px; border-radius:10px; border:1px solid var(--linea); background:white; cursor:pointer; font-size:18px; display:inline-flex; align-items:center; justify-content:center; transition:.15s ease; }
.icon-btn:hover  { border-color:var(--acento); background:#eff6ff; }
.icon-btn.active { border-color:var(--acento); background:#eff6ff; color:var(--acento); font-weight:bold; }
.status     { font-size:13px; color:var(--muted); margin-left:4px; }
.zoom-label { min-width:54px; text-align:center; font-size:13px; color:var(--muted); font-weight:bold; }

/* SVG */
.svg-space { position:relative; width:5200px; height:3600px; }
svg { width:100%; height:100%; display:block; user-select:none; -webkit-user-select:none; overflow:visible; }

/* figuras─ */
.grupo-figura { cursor: move; }

.grupo-figura.selected .main-shape,
.grupo-figura.selected .shape-body,
.grupo-figura.multi-selected .main-shape,
.grupo-figura.multi-selected .shape-body,
.connection.selected .conn-line,
.connection.selected .conn-hit { stroke: var(--acento) !important; stroke-width: 2.8; }

.entity .shape-body        { fill:#e0f2fe; stroke:#111827; stroke-width:2; }
.entity-hija .shape-body   { fill:#a8e3ba; stroke:#111827; stroke-width:2; }
.relationship .shape-body  { fill:#fffef2; stroke:#92400e; stroke-width:2; }
.specialization .shape-body{ fill:#f5f3ff; stroke:#5b21b6; stroke-width:2; }
.text-block .shape-body    { fill:#ffffff; stroke:#9ca3af; stroke-width:1.2; }

.title-text   { font-weight:bold; font-size:16px; }
.attr-text    { font-size:14px; }
.text-content { font-size:24px; fill:#111827; dominant-baseline:hanging; white-space:pre; user-select:none; -webkit-user-select:none; }

/* conecciones */
.conn-line  { stroke:#111827; stroke-width:2; fill:none; }
.conn-hit   { stroke:transparent; stroke-width:16; fill:none; cursor:pointer; }
.conn-label { font-size:13px; fill:#111827; paint-order:stroke; stroke:white; stroke-width:3px; stroke-linejoin:round; }

/* manijas de conexión (círculos para mover extremos y vértices) */
.conn-handle {
  cursor: grab;
  transition: r 0.1s ease, fill 0.1s ease;
}
.conn-handle:active { cursor: grabbing; }

/* Extremos: círculos rellenos en color acento, deslizan por el borde */
.conn-handle-endpoint-from,
.conn-handle-endpoint-to {
  fill: var(--acento);
  stroke: #ffffff;
  stroke-width: 2;
}
.conn-handle-endpoint-from:hover,
.conn-handle-endpoint-to:hover {
  fill: #1d4ed8;
}

/* Vértices intermedios: blanco con borde acento */
.conn-handle-vertex {
  fill: #ffffff;
  stroke: var(--acento);
  stroke-width: 2;
}
.conn-handle-vertex:hover {
  fill: #dbeafe;
}

/* Puntos medios de inserción: más sutiles, semi-transparentes */
.conn-handle-midpoint {
  fill: var(--acento);
  fill-opacity: 0.35;
  stroke: var(--acento);
  stroke-opacity: 0.55;
  stroke-width: 1.5;
}
.conn-handle-midpoint:hover {
  fill-opacity: 0.85;
  stroke-opacity: 1;
}

/* atributos externos */
.ovalo-atributo-externo  { fill:#ffffff; stroke:#374151; stroke-width:1.8; }
.linea-atributo-externo  { stroke:#374151; stroke-width:1.5; fill:none; }
.grupo-atributo-externo.selected .ovalo-atributo-externo { stroke:var(--acento) !important; stroke-width:2.8 !important; }
.grupo-atributo-externo.selected .attr-text { fill:var(--acento) !important; font-weight:bold; }

/* ── paneles sidebar*/
.panel-box label { display:block; font-size:13px; margin-bottom:6px; color:var(--muted); }
.panel-box input, .panel-box textarea, .panel-box select {
  width:100%; border:1px solid var(--linea); border-radius:8px;
  padding:8px; margin-bottom:8px; background:#111827;
}

/* lista */
.list { max-height:160px; overflow:auto; border:1px solid rgba(255,255,255,0.08); background:rgba(255,255,255,0.04); border-radius:8px; padding:6px; }
.list-item { padding:6px 8px; border-radius:8px; cursor:pointer; font-size:14px; color:#c8d8e8; }
.list-item:hover, .list-item.active { background:rgba(37,99,235,0.25); color:#93c5fd; }

/* subcard */
.subcard       { border:1px solid rgba(255,255,255,0.1); border-radius:10px; padding:8px; margin-bottom:8px; background:rgba(255,255,255,0.05); }
.subcard-title { font-size:13px; font-weight:bold; margin-bottom:6px; color:#93c5fd; }
.mini-grid     { display:grid; grid-template-columns:1fr 1fr; gap:8px; }

/* atributos */
.attr-header   { display:flex; justify-content:space-between; align-items:center; margin:8px 0; }
.attr-card     { background:#f8fafc; border:1px solid #cbd5e1; border-radius:10px; padding:8px; margin-bottom:8px; }
.attr-row-top  { display:grid; grid-template-columns:1fr 130px; gap:6px; margin-bottom:6px; }
.attr-row-bottom{ display:flex; justify-content:space-between; align-items:center; }
.attr-input    { width:100%; padding:4px 6px; border-radius:6px; border:1px solid rgba(255,255,255,0.15); background:#1a2233; color:#e8edf5; }
.attr-select   { width:100%; border-radius:6px; background:#1a2233; color:#e8edf5; border:1px solid rgba(255,255,255,0.15); }
.attr-select option { background:#1a2233; color:#e8edf5; }
.attr-meta     { font-size:11px; color:#64748b; }
.attr-actions  { display:flex; align-items:center; gap:4px; }
.attr-pk       { display:flex; align-items:center; gap:3px; font-size:12px; }
.btn.icon      { min-width:28px; padding:2px 4px; }
.btn.small     { padding:2px 6px; }

/* rename */
.inline-rename-editor { position:fixed; z-index:2000; pointer-events:auto; }
.inline-rename-input  {
  width:100%; min-height:42px; padding:10px 12px; border-radius:12px;
  border:2px solid var(--acento); background:rgba(255,255,255,.98);
  box-shadow:0 12px 28px rgba(37,99,235,.18); color:var(--texto); outline:none; resize:both;
}
textarea.inline-rename-input { min-height:88px; line-height:1.35; resize:both; }

/* rename modal */
.rename-modal-overlay {
  position:fixed; inset:0; z-index:3000; background:rgba(15,23,42,0.18);
  display:flex; align-items:center; justify-content:center; padding:20px; backdrop-filter:blur(2px);
}
.rename-modal-dialog { width:min(460px,calc(100vw - 32px)); background:#ffffff; border:1px solid #dbe4f0; border-radius:18px; box-shadow:0 24px 60px rgba(15,23,42,0.22); overflow:hidden; }
.rename-modal-header, .rename-modal-footer { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 16px; }
.rename-modal-header  { border-bottom:1px solid #e5e7eb; }
.rename-modal-footer  { justify-content:flex-end; border-top:1px solid #e5e7eb; }
.rename-modal-title   { font-size:18px; font-weight:700; color:var(--texto); }
.rename-modal-close   { width:34px; height:34px; border-radius:10px; border:1px solid #d1d5db; background:#fff; cursor:pointer; font-size:16px; }
.rename-modal-close:hover { background:#f8fafc; }
.rename-modal-body    { padding:16px; }
.rename-modal-hint    { margin-bottom:10px; font-size:13px; color:var(--muted); line-height:1.4; }
.rename-modal-input   { width:100%; min-height:46px; padding:12px 14px; border-radius:12px; border:2px solid #bfdbfe; background:#fff; color:var(--texto); outline:none; font-size:15px; box-sizing:border-box; }
.rename-modal-input:focus { border-color:var(--acento); box-shadow:0 0 0 4px rgba(37,99,235,0.12); }
textarea.rename-modal-input { min-height:120px; resize:vertical; line-height:1.4; }

/* help modal*/
.help-modal.hidden  { display:none; }
.help-modal         { position:fixed; inset:0; z-index:3000; }
.help-modal-backdrop{ position:absolute; inset:0; background:rgba(0,0,0,0.45); }
.help-modal-dialog  { position:relative; width:min(760px,calc(100vw - 32px)); max-height:calc(100vh - 40px); margin:20px auto; background:#fff; border-radius:14px; box-shadow:0 20px 60px rgba(0,0,0,.25); display:flex; flex-direction:column; overflow:hidden; }
.help-modal-header  { display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid #e5e7eb; background:#f8fafc; }
.help-modal-header h2{ margin:0; font-size:20px; color:#111827; }
.help-modal-close   { border:none; background:transparent; cursor:pointer; font-size:18px; color:#374151; padding:6px; border-radius:8px; }
.help-modal-close:hover { background:#e5e7eb; }
.help-modal-body    { padding:20px; overflow:auto; color:#111827; line-height:1.55; }
.help-modal-body p  { margin:0 0 14px; }
.help-modal-body ul { margin:0 0 14px 20px; padding:0; }
.help-modal-body li { margin-bottom:6px; }
.help-modal-footer  { display:flex; justify-content:flex-end; gap:10px; padding:14px 20px; border-top:1px solid #e5e7eb; background:#f8fafc; }
.hidden { display:none !important; }

/* modal  */
.modal-overlay { position:fixed; inset:0; z-index:3000; background:rgba(15,23,42,0.4); display:flex; align-items:center; justify-content:center; }
.modal-dialog { width:min(460px,calc(100vw - 32px)); background:#fff; border:1px solid #dbe4f0; border-radius:16px; box-shadow:0 20px 60px rgba(15,23,42,.22); overflow:hidden; }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:14px 16px; border-bottom:1px solid #e5e7eb; }
.modal-title  { font-size:16px; font-weight:700; color:var(--texto); }
.modal-close  { width:32px; height:32px; border-radius:8px; border:1px solid #d1d5db; background:#fff; cursor:pointer; font-size:15px; }
.modal-close:hover { background:#f8fafc; }
.modal-body   { padding:16px; }
.modal-label  { display:block; font-size:12px; color:var(--muted); margin-bottom:4px; }
.modal-input, .modal-select { width:100%; padding:8px 10px; border-radius:8px; border:1.5px solid #bfdbfe; font-size:13px; outline:none; color:var(--texto); margin-bottom:10px; background:#fff; }
.modal-input:focus, .modal-select:focus { border-color:var(--acento); box-shadow:0 0 0 3px rgba(37,99,235,.1); }
.modal-checks { display:flex; gap:16px; margin-bottom:4px; }
.modal-check  { display:flex; align-items:center; gap:5px; font-size:12px; color:#555; cursor:pointer; }
.modal-check input { accent-color:var(--acento); }
.modal-footer { display:flex; justify-content:flex-end; gap:8px; padding:12px 16px; border-top:1px solid #e5e7eb; }
.modal-btn         { padding:7px 18px; border-radius:8px; font-size:12px; font-weight:600; cursor:pointer; border:1px solid transparent; }
.modal-btn.cancel  { background:transparent; border-color:#d1d5db; color:#555; }
.modal-btn.cancel:hover { background:#f5f5f5; }
.modal-btn.ok      { background:var(--acento); color:white; border-color:var(--acento); }
.modal-btn.ok:hover{ background:#1d4ed8; }