:root {
  --bg: #12161b;
  --bg-alt: #1a2029;
  --panel: #1e2530;
  --border: #2c3540;
  --text: #e6e9ed;
  --text-dim: #9aa5b1;
  --accent: #3d7a4f;
  --accent-bright: #4f9c66;
  --danger: #c14545;
  --warning: #c19a45;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1a2029, #0d1013);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.login-card h1 { margin: 0; text-align: center; }
.login-card .subtitle { margin: 0 0 1rem; text-align: center; color: var(--text-dim); font-size: 0.9rem; }

.login-card label { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.5rem; }
.login-card input {
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
}

.login-card button, button.primary {
  margin-top: 1.2rem;
  padding: 0.7rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover, button.primary:hover { background: var(--accent-bright); }

.alert { padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.9rem; }
.alert-error { background: rgba(193, 69, 69, 0.15); color: #e08a8a; border: 1px solid var(--danger); }

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar-brand { font-weight: bold; padding: 0 1.2rem 1rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }

.sidebar a {
  padding: 0.6rem 1.2rem;
  color: var(--text-dim);
  border-left: 3px solid transparent;
}
.sidebar a:hover { color: var(--text); text-decoration: none; background: rgba(255,255,255,0.03); }
.sidebar a.active { color: var(--text); border-left-color: var(--accent-bright); background: rgba(79,156,102,0.08); }

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.2rem 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: underline;
  padding: 0;
}
.link-button:hover { color: var(--text); }

.content { flex: 1; padding: 2rem; max-width: 1200px; }

.error-page { padding: 3rem; text-align: center; }

/* ---- Common components ---- */
h1, h2, h3 { margin-top: 0; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

th { background: var(--bg-alt); color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.03em; }

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-activo { background: rgba(79,156,102,0.2); color: var(--accent-bright); }
.badge-inactivo { background: rgba(154,165,177,0.2); color: var(--text-dim); }
.badge-suspendido { background: rgba(193,69,69,0.2); color: #e08a8a; }
.badge-semana { background: rgba(193,154,69,0.2); color: var(--warning); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

form.inline { display: inline; }

select, input[type=text], input[type=date], input[type=datetime-local], input[type=number], input[type=password], textarea, input[type=url], input[type=file] {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--text-dim); }

.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 0.88rem;
}
.btn:hover { background: var(--panel); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-bright); }
.btn-danger { background: rgba(193,69,69,0.15); border-color: var(--danger); color: #e08a8a; }

/* ---- Board / pizarra de investigación ---- */
.board-toolbar { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.board-toolbar .btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 0.4rem; }

.board-viewport {
  position: relative;
  overflow: hidden;
  height: calc(100vh - 260px);
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: #0d1013;
  background-image: radial-gradient(circle, #232b35 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}
.board-viewport.panning { cursor: grabbing; }

.board-world { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; transform-origin: 0 0; }

#edges-layer { position: absolute; top: 0; left: 0; pointer-events: none; }
#edges-layer .edge-hit { pointer-events: stroke; cursor: pointer; }
#edges-layer .edge-delete { cursor: pointer; pointer-events: all; }

.board-node {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: move;
  user-select: none;
}
.board-node.selected { outline: 2px solid var(--accent-bright); }
.board-node.tipo-nota { background: #3a3220; border-color: #5c4f2e; padding: 0 0.5rem 0.5rem; width: 180px; }
.board-node.tipo-nota .node-handle {
  margin: 0 -0.5rem 0.4rem; padding: 0.3rem 0.5rem; cursor: move; font-size: 0.7rem;
  color: #d8c896; background: rgba(255,255,255,0.04); border-bottom: 1px solid #5c4f2e;
  border-radius: 6px 6px 0 0;
}
.board-node.tipo-nota textarea {
  width: 100%; height: 92px; background: transparent; border: none; color: #f0e6c8;
  resize: both; font-family: inherit; font-size: 0.85rem; cursor: text;
}
.board-node.tipo-foto { padding: 4px; }
.board-node.tipo-foto img { display: block; pointer-events: none; border-radius: 4px; max-width: none; }

.board-node .node-delete {
  position: absolute; top: -10px; right: -10px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: white; text-align: center; line-height: 20px; cursor: pointer;
  font-size: 13px; border: 2px solid var(--bg); z-index: 2;
}
