:root {
  --bg: #f5f6f4; --card: #ffffff; --fg: #1c1f22; --muted: #687076; --line: #e2e4e0;
  --acc: #128c7e; --acc-fg: #ffffff; --acc-soft: #e3f3f0;
  --ok: #1f8a4c; --ok-bg: #e5f5ea; --warn: #9a6700; --warn-bg: #fdf3d8; --bad: #c4302b; --bad-bg: #fde8e7;
  --code: #f0f1ee; --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121416; --card: #1b1e21; --fg: #e5e7e6; --muted: #98a0a6; --line: #2b3034;
    --acc: #25b39f; --acc-fg: #0d1f1c; --acc-soft: #173431;
    --ok: #4cc47e; --ok-bg: #173022; --warn: #e3b341; --warn-bg: #33290f; --bad: #f07067; --bad-bg: #3a1c1a;
    --code: #24282c; --shadow: none; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--acc); text-decoration: none; } a:hover { text-decoration: underline; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
pre { background: var(--code); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; white-space: pre-wrap; word-break: break-all; }

.app { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 17px; padding: 0 10px 14px; display: flex; align-items: center; gap: 8px; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--acc); }
.side a.nav { color: var(--fg); padding: 7px 10px; border-radius: 6px; }
.side a.nav:hover { background: var(--bg); text-decoration: none; }
.side a.nav.active { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.side .grow { flex: 1; }
.side .navsep { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 12px 10px 4px; }
.side .foot { color: var(--muted); font-size: 12px; padding: 8px 10px; }
main { padding: 24px 28px 60px; max-width: 1180px; width: 100%; }
h1 { font-size: 22px; margin: 0 0 18px; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 16px 0 8px; }
.sub { color: var(--muted); margin: -12px 0 18px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 18px; }
.grid2 { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12.5px; } .stat .v { font-size: 24px; font-weight: 650; margin-top: 2px; }
.stat .d { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-bg); } .badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); } .badge.muted { color: var(--muted); background: var(--code); }

form.stack { display: grid; gap: 12px; max-width: 560px; }
label { display: grid; gap: 4px; font-weight: 550; font-size: 13px; }
label.check { display: flex; gap: 6px; align-items: center; font-weight: 450; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=tel], select, textarea {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
textarea { min-height: 80px; resize: vertical; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.inline { display: inline; }

button, .btn { font: inherit; font-weight: 600; font-size: 13px; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-fg); }
button.danger { color: var(--bad); } button.danger:hover { border-color: var(--bad); }
button.sm { padding: 3px 8px; font-size: 12px; white-space: nowrap; }
button:disabled { opacity: .55; cursor: default; }

.alert { padding: 9px 12px; border-radius: 6px; margin: 8px 0; font-size: 13.5px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); } .alert.bad { background: var(--bad-bg); color: var(--bad); }
.keybox { background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.keybox code { font-size: 14px; background: transparent; }

.qr { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.qr img { width: 260px; height: 260px; border-radius: 8px; background: #fff; padding: 8px; border: 1px solid var(--line); }
.qr ol { margin: 0; padding-left: 18px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

.logs td { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 3px 6px; }
.lv-error { color: var(--bad); font-weight: 600; } .lv-warn { color: var(--warn); font-weight: 600; } .lv-debug { color: var(--muted); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.htmx-request .spin, .htmx-request.spin { opacity: .6; }
details summary { cursor: pointer; color: var(--acc); }



/* Modal de confirmación */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); color: var(--fg);
  width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.35); }
dialog.modal::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
dialog.modal form { padding: 20px 22px 18px; margin: 0; }
.modal-title { margin: 0 0 8px; font-size: 16px; }
.modal-msg { margin: 0 0 20px; color: var(--fg); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-actions button { min-width: 96px; justify-content: center; }
button.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger-solid:hover { filter: brightness(1.08); }

/* ---------- Navegación ---------- */
.navlinks { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; }
.menu-toggle { display: none; font-size: 20px; line-height: 1; padding: 6px 10px; }
.table-wrap { -webkit-overflow-scrolling: touch; }

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 190px minmax(0, 1fr); }
  main { padding: 20px 18px 48px; }
}

/* ---------- Móvil: barra superior + menú desplegable ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 20; height: auto; padding: 8px 12px; border-right: 0;
    border-bottom: 1px solid var(--line); flex-direction: column; gap: 0; }
  .topbar { display: flex; align-items: center; justify-content: space-between; }
  .brand { padding: 4px 0; }
  .menu-toggle { display: inline-flex; }
  .navlinks { display: none; padding: 8px 0 6px; max-height: calc(100vh - 56px); overflow-y: auto; }
  .side.open .navlinks { display: flex; }
  .side .grow { display: none; }
  .side a.nav { padding: 10px 10px; }
  .side .navlinks > button { margin-top: 6px; align-self: flex-start; }

  main { padding: 16px 12px 40px; }
  h1 { font-size: 20px; margin-bottom: 14px; }
  .sub { margin-top: -8px; }
  .card { padding: 14px; border-radius: 10px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; } .stat .v { font-size: 20px; }
  .grid2, .qr { grid-template-columns: 1fr; }
  .qr img { width: 100%; height: auto; max-width: 280px; justify-self: center; }
  .row.between { align-items: flex-start; }
  form.stack { max-width: none; }
  form.row > input, form.row > select { max-width: none !important; flex: 1 1 200px; }
  /* 16 px evita que iOS haga zoom al tocar un campo. */
  input[type=text], input[type=password], input[type=url], input[type=number], input[type=tel], select, textarea { font-size: 16px; }
  th, td { padding: 7px 6px; }
  table { font-size: 13.5px; }
  .kv { grid-template-columns: 1fr; gap: 0 0; } .kv dd { margin-bottom: 8px; }
  button, .btn { padding: 8px 12px; }
  button.sm { padding: 6px 10px; }
}

/* ---------- Celular angosto ---------- */
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
  .modal-actions button { flex: 1; }
}

/* ---------- Evitar desbordes horizontales ----------
   En grid/flex, los hijos tienen por defecto un ancho mínimo igual a su contenido más
   ancho (una tabla, un botón, un JID). min-width:0 deja que se ajusten a la pantalla
   y que solo las tablas hagan scroll dentro de su recuadro. */
main, .card, .grid > *, .grid2 > *, .row > *, .qr > *, .kv > * { min-width: 0; }
h1, h2, h3 { overflow-wrap: anywhere; }
.kv dd, .mono, td, .alert, .keybox { overflow-wrap: anywhere; }
.table-wrap { max-width: 100%; }
.table-wrap table { min-width: 100%; }
img, svg, video { max-width: 100%; }
@media (max-width: 820px) {
  /* Encabezados con acciones: título arriba, botones debajo y a todo el ancho disponible. */
  .row.between > .row { flex-wrap: wrap; }
  .row.between > .btn, .row.between > button, .row.between > form { flex: 0 1 auto; }
  /* En tablas anchas, las celdas no se parten letra a letra: se usa el scroll del recuadro. */
  .table-wrap td { overflow-wrap: normal; word-break: normal; }
  .table-wrap td.mono, .table-wrap td code { word-break: break-all; }
  .table-wrap table { min-width: 560px; }
  .logs { min-width: 0 !important; }
}
