/* ============================================================
   Panel Local — tema "Claro profesional (SaaS)" por defecto,
   con variante oscura refinada (botón 🌗). Acento azul.
   ============================================================ */

/* ----- Tema claro (por defecto) ----- */
:root, :root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #eaf0ff 0%, rgba(234,240,255,0) 60%), #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f3f5fa;
  --border: #e5e9f1;
  --border-strong: #d5dce8;
  --text: #1e293b;
  --heading: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-press: #1d4ed8;
  --accent-weak: #e7eefe;
  --accent-2: #059669;
  --accent-2-weak: #d6f5e6;
  --danger: #dc2626;
  --danger-weak: #fde4e4;
  --warn: #d97706;
  --warn-weak: #fdecd2;
  --ring: rgba(37, 99, 235, .25);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 6px 20px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .12);
  --radius: 14px;
  --radius-sm: 9px;
}

/* ----- Tema oscuro ----- */
:root[data-theme="dark"] {
  --bg: #0b0e14;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #16203a 0%, rgba(22,32,58,0) 55%), #0b0e14;
  --panel: #141923;
  --panel-2: #1b2230;
  --border: #273042;
  --border-strong: #36425a;
  --text: #e6e9ef;
  --heading: #f8fafc;
  --muted: #93a1b5;
  --accent: #5b8cff;
  --accent-press: #4f8cff;
  --accent-weak: rgba(91, 140, 255, .16);
  --accent-2: #34d399;
  --accent-2-weak: rgba(52, 211, 153, .16);
  --danger: #f87171;
  --danger-weak: rgba(248, 113, 113, .16);
  --warn: #fbbf24;
  --warn-weak: rgba(251, 191, 36, .16);
  --ring: rgba(91, 140, 255, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-press); }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; border: 1px solid var(--border); }
::selection { background: var(--accent-weak); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Layout con barra lateral ===== */
body.has-sidebar { display: flex; min-height: 100vh; }

.sidebar {
  width: 256px; flex: 0 0 256px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.08rem; color: var(--heading);
  padding: 20px 18px 16px;
  letter-spacing: -.01em;
}
.side-nav { display: flex; flex-direction: column; padding: 6px 12px; gap: 2px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.side-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 10px; color: var(--text);
  font-weight: 500; font-size: .92rem; transition: background .12s, color .12s;
}
.side-nav a:hover { background: var(--panel-2); color: var(--heading); }
.side-nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav-sep {
  margin: 16px 14px 6px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 700;
}
.side-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 12px; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 7px; border-radius: 10px; color: var(--text); }
.user-box:hover { background: var(--panel-2); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-press));
  color: #fff; display: grid; place-items: center; font-weight: 700; flex: none;
}
.user-box .meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-box .uname { font-weight: 600; color: var(--heading); }
.user-box .role { font-size: .76rem; color: var(--muted); }
.side-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-icon {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 10px; cursor: pointer; font-size: 1rem; flex: 1;
  transition: border-color .12s, background .12s;
}
.btn-icon:hover { border-color: var(--accent); background: var(--accent-weak); }

.app-main { flex: 1; min-width: 0; }
.container { max-width: 1060px; margin: 0 auto; padding: 34px 30px 70px; }

/* shell de login/registro */
body.auth { display: block; }
.auth-shell { width: 100%; }
.auth-wrap { max-width: 410px; margin: 9vh auto 0; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 1.25rem; color: var(--heading); margin-bottom: 18px; letter-spacing: -.01em; }
.auth-wrap .card { box-shadow: var(--shadow-lg); }

/* ===== Tipografía ===== */
h1 { font-size: 1.7rem; margin: 0 0 6px; color: var(--heading); letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 1.2rem; margin: 32px 0 14px; color: var(--heading); letter-spacing: -.01em; font-weight: 650; }
h3 { color: var(--heading); }
.sub { color: var(--muted); margin: 0 0 24px; font-size: .96rem; }
.muted { color: var(--muted); }

/* ===== Tarjetas ===== */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.service-card {
  display: block; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; color: var(--text);
  box-shadow: var(--shadow); transition: transform .14s, box-shadow .14s, border-color .14s;
}
.service-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.service-card .icon {
  width: 52px; height: 52px; border-radius: 13px; background: var(--accent-weak);
  display: grid; place-items: center; font-size: 1.7rem; margin-bottom: 14px;
}
.service-card h3 { margin: 0 0 5px; font-size: 1.05rem; }
.service-card p { color: var(--muted); font-size: .9rem; margin: 0; }

.stat { text-align: center; }
.stat .num { font-size: 2rem; font-weight: 750; color: var(--accent); letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: .85rem; margin-top: 2px; }

/* ===== Formularios ===== */
form.stack { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
label { font-size: .84rem; color: var(--muted); display: block; margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--border-strong);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px 13px; font-size: .95rem;
  font-family: inherit; transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
textarea { resize: vertical; }

button, .btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--accent); color: #fff; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: .9rem; cursor: pointer; font-weight: 600; line-height: 1.1;
  box-shadow: var(--shadow-sm); transition: filter .12s, transform .05s, background .12s;
}
button:hover, .btn:hover { background: var(--accent-press); color: #fff; }
button:active, .btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 11px; font-size: .8rem; }
.btn-ghost { background: var(--panel); border-color: var(--border-strong); color: var(--text); box-shadow: none; }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--accent); color: var(--text); }
.btn-danger { background: var(--danger); } .btn-danger:hover { background: var(--danger); filter: brightness(.92); }
.btn-warn { background: var(--warn); color: #fff; } .btn-warn:hover { background: var(--warn); filter: brightness(.92); color: #fff; }
.btn-ok { background: var(--accent-2); color: #fff; } .btn-ok:hover { background: var(--accent-2); filter: brightness(.94); color: #fff; }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font: inherit; box-shadow: none; }
.btn-link:hover { color: var(--text); background: none; }

/* ===== Tablas ===== */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
thead th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child { border-top-right-radius: var(--radius); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-2); }

/* ===== Avisos ===== */
.flash, .err {
  position: relative;
  padding: 12px 38px 12px 15px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: .9rem;
  display: flex; align-items: center; gap: 8px;
}
.flash { background: var(--accent-2-weak); border: 1px solid var(--accent-2); color: var(--accent-2); }
.err { background: var(--danger-weak); border: 1px solid var(--danger); color: var(--danger); }

/* ===== Insignias, chips, utilidades ===== */
.badge { background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 8px; font-size: .72rem; font-weight: 700; letter-spacing: .01em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: 20px;
  padding: 4px 11px; font-size: .8rem; color: var(--text); transition: border-color .12s, background .12s;
  box-shadow: none;
}
.chip:hover { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.crumbs { color: var(--muted); margin-bottom: 16px; font-size: .9rem; }
.crumbs a { color: var(--accent); }
details.tool { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
details.tool summary { cursor: pointer; font-weight: 600; color: var(--heading); }
details.tool[open] summary { margin-bottom: 4px; }
.inline-form { display: inline; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; color: var(--muted); }

/* ===== Barras (monitor) ===== */
.bar { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; height: 18px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .5s ease; }
.bar.sm { height: 8px; }

/* ===== Código ===== */
pre.code {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px;
  padding: 15px; overflow-x: auto; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .85rem; white-space: pre; line-height: 1.5;
}

/* ===== Diff de la wiki ===== */
.diff { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .84rem; }
.diff .ln { display: flex; gap: 8px; padding: 1px 12px; white-space: pre-wrap; word-break: break-word; border-left: 3px solid transparent; }
.diff .ln .mark { width: 1ch; flex: none; opacity: .7; user-select: none; }
.diff .ln.eq { color: var(--muted); }
.diff .ln.add { background: var(--accent-2-weak); border-left-color: var(--accent-2); color: var(--text); }
.diff .ln.del { background: var(--danger-weak); border-left-color: var(--danger); color: var(--text); }

/* ===== Wiki (Markdown) ===== */
.markdown { line-height: 1.7; }
.markdown h2, .markdown h3, .markdown h4 { margin: 22px 0 10px; }
.markdown p { margin: 11px 0; }
.markdown ul, .markdown ol { margin: 11px 0; padding-left: 26px; }
.markdown li { margin: 3px 0; }
.markdown code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.markdown pre.code { margin: 14px 0; }
.markdown blockquote { margin: 14px 0; padding: 8px 16px; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 0 8px 8px 0; color: var(--muted); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.markdown a { text-decoration: underline; text-underline-offset: 2px; }

/* ===== Categorías plegables en la barra lateral (Fase 1) ===== */
.nav-group { margin: 0; }
.nav-group > summary {
  list-style: none; cursor: pointer; user-select: none;
  margin: 16px 14px 6px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after { content: '▾'; margin-left: auto; font-size: .8rem; opacity: .65; transition: transform .15s; }
.nav-group:not([open]) > summary::after { transform: rotate(-90deg); }
.nav-group > summary:hover { color: var(--text); }

/* ===== Botón de menú móvil + backdrop (ocultos en escritorio) ===== */
.nav-toggle { display: none; }
.nav-backdrop { display: none; }

/* ===== Aviso descartable (botón de cierre) ===== */
.aviso-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: 1.2rem; line-height: 1; padding: 0 2px; box-shadow: none; opacity: .6;
}
.aviso-close:hover { background: none; color: inherit; opacity: 1; }

/* ===== Estado vacío ===== */
.empty-state { text-align: center; padding: 40px 22px; }
.empty-state .ico { font-size: 2.6rem; display: block; margin-bottom: 10px; opacity: .7; }

/* ===== Chat ===== */
.chat-layout { display: flex; gap: 16px; align-items: flex-start; }
.chat-main { flex: 1; min-width: 0; }
.chat-side { flex: 0 0 220px; max-height: 62vh; overflow-y: auto; }
@media (max-width: 760px) { .chat-layout { flex-direction: column; } .chat-side { flex: none; width: 100%; } }
#chat-log { height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 14px; }
.chat-msg { padding: 7px 11px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); max-width: 80%; }
.chat-who { font-weight: 600; color: var(--accent); font-size: .88rem; }
.chat-when { font-size: .72rem; }
.chat-body { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.roster-user { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: .9rem; }
.roster-user .roster-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-user .roster-bell { opacity: .85; font-size: .85rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.on { background: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2-weak); }
.dot.off { background: var(--border-strong); }
/* Badge de no leídos en el enlace de Chat de la barra lateral */
.nav-badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: .68rem; font-weight: 700; padding: 1px 6px; margin-left: auto; }
/* Toasts flotantes de notificación de chat (abajo-derecha) */
.toast-stack { position: fixed; bottom: 16px; right: 16px; z-index: 95; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.chat-toast { display: block; background: var(--panel); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow-lg); color: var(--text); transition: opacity .4s; }
.chat-toast:hover { border-color: var(--accent); }
.chat-toast strong { color: var(--accent); font-size: .9rem; }
.chat-toast div { font-size: .85rem; color: var(--muted); margin-top: 2px; word-break: break-word; }

/* ===== Responsive ===== */
@media (max-width: 820px) {
  body.has-sidebar { flex-direction: column; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; left: 12px; z-index: 70;
    width: 44px; height: 44px; padding: 0; font-size: 1.25rem;
    background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  }
  .nav-toggle:hover { background: var(--panel-2); color: var(--text); }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 264px; flex: none;
    transform: translateX(-100%); transition: transform .2s ease; z-index: 90; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-toggle { display: none; } /* el drawer abierto taparía el ☰ */
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 80; }
  .app-main { width: 100%; }
  .container { padding: 66px 16px 52px; }
}

/* ===== Accesibilidad: respetar "reducir movimiento" ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
