:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1e293b;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-dark: #0d9488;
  --danger: #ef4444;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  width: 340px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

/* ---------- Layout con sidebar ---------- */
.app {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: #101828;
  color: #e2e8f0;
  padding: 20px 14px;
  flex-shrink: 0;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  padding: 0 8px 20px;
}
.sidebar .user {
  font-size: 12px;
  color: #94a3b8;
  padding: 0 8px 16px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 12px;
}
.menu-item { margin-bottom: 2px; }
.menu-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: #cbd5e1;
}
.menu-link:hover { background: #1e293b; color: #fff; }
.menu-group-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  font-size: 14px;
  color: #94a3b8;
  font-weight: 600;
}
.submenu { list-style: none; padding: 0 0 0 18px; margin: 0; }
.menu-link.activo { background: #1e293b; color: #fff; }
.menu-grupo > summary { list-style: none; cursor: pointer; font-weight: 600; }
.menu-grupo > summary::-webkit-details-marker { display: none; }
.menu-grupo > summary .chevron { margin-left: auto; transition: transform .15s; color: #64748b; font-size: 16px; }
.menu-grupo[open] > summary .chevron { transform: rotate(90deg); }
.logout-form { margin-top: 20px; padding-top: 14px; border-top: 1px solid #1f2937; }
.logout-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 13px;
  cursor: pointer;
  padding: 8px 10px;
}
.logout-btn:hover { color: #fff; }

.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1000px;
}
.main h1 { margin: 0 0 4px; font-size: 24px; }
.main .subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

/* ---------- Tarjetas / formularios ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card h2 { margin: 0 0 18px; font-size: 16px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.tree { border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 220px; overflow-y: auto; }
.tree label { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 0; }
.tree .nivel-1 { margin-left: 0; }
.tree .nivel-2 { margin-left: 20px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); }
.btn-secondary { background: #64748b; }
.btn-block { width: 100%; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.badge-admin { background: #dcfce7; color: #166534; }
.badge-normal { background: #e2e8f0; color: #475569; }
.mini-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
}
.alert {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
}
.hint { color: var(--muted); font-size: 13px; }
