/* ── 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 {
  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 Modelo Lógico en brand */
.sidebar-brand-icon-wrap {
  width:56px; height:56px; border-radius:14px; flex-shrink:0;
  background: linear-gradient(135deg, rgba(37,99,235,0.28) 0%, rgba(29,78,216,0.14) 100%);
  border:1px solid rgba(37,99,235,0.35);
  display:flex; align-items:center; justify-content:center;
  position:relative; overflow:hidden;
  box-shadow:0 4px 16px rgba(37,99,235,0.2);
}
.sidebar-brand-icon-wrap::before {
  content:''; position:absolute;
  width:44px; height:44px; border-radius:50%;
  right:-12px; bottom:-12px;
  background:rgba(37,99,235,0.1); border:1px solid rgba(37,99,235,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-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 */
.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; }
.hint b { color:#93c5fd; }

/* 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);
}

/*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; }
.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; margin-top:0; }
svg { width:100%; height:100%; display:block; user-select:none; overflow:visible; }

/* cards */
.tbl-outer {
  background:white; border-radius:8px; border:1.5px solid #bfdbfe;
  overflow:hidden; cursor:move; box-shadow:0 1px 5px rgba(37,99,235,.10);
}
.tbl-outer.selected       { border-color:#f59e0b; border-width:2.5px; box-shadow:0 0 0 3px rgba(245,158,11,.25); }
.tbl-outer.connecting-src { border-color:#059669; border-width:2px; box-shadow:0 0 0 3px rgba(5,150,105,.15); }

.tbl-head {
  padding:7px 11px 6px; font-size:12px; font-weight:700;
  color:#ffffff; background:#1d4ed8;
  cursor:move; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.tbl-outer.selected       .tbl-head { background:#b45309; }
.tbl-outer.connecting-src .tbl-head { background:#059669; }

.tbl-field { display:grid; grid-template-columns:32px 1fr; align-items:center; gap:0; padding:2px 8px; border-top:0.5px solid #e8f0fe; cursor:pointer; min-height:22px; }
.tbl-field:hover { background:#eff6ff; }
.tbl-field.pk-field { color:#1e3a8a; font-weight:700; }
.tbl-field-badge { display:flex; align-items:center; gap:2px; }
.tbl-field-name  { padding:0 4px; font-size:11px; color:#1e293b; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.tbl-field.pk-field .tbl-field-name { color:#1e3a8a; font-weight:700; }

.badge { font-size:8px; font-weight:700; padding:1px 3px; border-radius:2px; flex-shrink:0; font-family:ui-monospace, Menlo, monospace; letter-spacing:0.3px; }
.badge-pk { background:#fef3c7; color:#92400e; }
.badge-fk { background:#d1fae5; color:#065f46; }

.tbl-add-field { padding:5px 10px; font-size:11px; color:#93c5fd; border-top:0.5px solid #e8f0fe; cursor:pointer; }
.tbl-add-field:hover { background:#eff6ff; color:#2563eb; }

.field-action { color:#cbd5e1; font-size:11px; cursor:pointer; padding-left:4px; flex-shrink:0; }
.field-action:hover        { color:#2563eb; }
.field-action.danger:hover { color:#dc2626; }

/* inline editor */
.field-edit-row { display:flex; align-items:center; gap:4px; padding:3px 8px; border-top:0.5px solid #bfdbfe; background:#eff6ff; }
.field-edit-input { flex:1; font-size:11px; padding:2px 5px; border:1px solid #93c5fd; border-radius:4px; outline:none; min-width:0; }
.field-edit-lbl { display:flex; align-items:center; gap:2px; font-size:9px; color:#555; white-space:nowrap; cursor:pointer; }
.field-edit-check { accent-color:#2563eb; width:12px; height:12px; }
.field-edit-ok { background:#2563eb; color:white; border:none; border-radius:4px; font-size:10px; padding:2px 6px; cursor:pointer; }
.field-edit-cancel { background:transparent; color:#888; border:none; font-size:14px; cursor:pointer; padding:0 2px; }

/* modal del help */
.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(720px,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 del rename */
.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; }
.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; }

/* conexiones */
.conn-info { font-size:10px; padding:4px 10px; color:#6b7280; background:#f0f9ff; border-top:0.5px solid #bae6fd; font-style:italic; }

/* text */
.txt-selected .txt-bg { stroke: #2563eb !important; fill: rgba(239,246,255,0.3) !important; }

/* resize de tablas */
.tbl-resize { position:absolute; right:0; bottom:0; width:10px; height:10px; cursor:se-resize; background:transparent; }
.tbl-resize::after { content:''; position:absolute; right:2px; bottom:2px; width:6px; height:6px; border-right:2px solid #93c5fd; border-bottom:2px solid #93c5fd; border-radius:1px; }
.tbl-outer.selected .tbl-resize::after { border-color:#f59e0b; }