:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --border: #2a3441;
  --fg: #e6edf3;
  --muted: #8b98a5;
  --accent: #4493f8;
  --danger: #f85149;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 1.4rem; }
header .sub { margin: .3rem 0 0; color: var(--muted); font-size: .9rem; }

main { flex: 1; padding: 1.5rem 2rem; }

.status { color: var(--muted); font-size: .85rem; margin-bottom: 1rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.card-head h2 { margin: 0; font-size: 1.1rem; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.card-head time { color: var(--muted); font-size: .75rem; white-space: nowrap; }

.metrics { display: flex; gap: .5rem; flex-wrap: wrap; }
.metric {
  background: #243041;
  color: #b8c4d0;
  border-radius: 6px;
  padding: .15rem .5rem;
  font-size: .78rem;
}
.metric.muted { background: transparent; color: var(--muted); padding-left: 0; }
.metric.fresh { background: #1a3326; color: #3fb950; }
.metric.stale { background: #3d1a1a; color: #f85149; }

.actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: auto; }
.btn {
  font-size: .8rem;
  padding: .35rem .7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #243041;
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { margin-left: auto; border-color: transparent; color: var(--danger); background: transparent; }
.btn.danger:hover { background: rgba(248, 81, 73, .12); border-color: var(--danger); }
.btn.disabled { opacity: .35; cursor: default; pointer-events: none; }

.empty { color: var(--muted); text-align: center; margin-top: 3rem; }

footer {
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .78rem;
}
footer code { color: #b8c4d0; }

.small { font-size: .75rem; }
.muted { color: var(--muted); }

/* ---- login + logout ---- */
header { position: relative; }
.logout-btn { position: absolute; top: 1.2rem; right: 2rem; }
.login-mode { align-items: center; justify-content: center; }
.login-box {
  margin: auto; display: flex; flex-direction: column; gap: .8rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 2rem; width: min(90vw, 340px);
}
.login-box h1 { margin: 0; font-size: 1.3rem; }
.login-box .sub { margin: 0 0 .5rem; color: var(--muted); font-size: .85rem; }
.login-box input {
  padding: .6rem .7rem; font-size: .95rem; border-radius: 8px;
  background: #243041; color: var(--fg); border: 1px solid var(--border);
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box .btn { text-align: center; padding: .6rem; }
.login-err { margin: 0; color: var(--danger); font-size: .82rem; }

/* ---- hub: header + pestañas ---- */
.hub-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; }
.tab {
  padding: .4rem .9rem;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  text-decoration: none;
  font-size: .88rem;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); background: var(--panel); border-color: var(--border); }
.tab-body h3 { margin: 1.5rem 0 .6rem; font-size: .95rem; color: #b8c4d0; }
.tab-body h3:first-child { margin-top: 0; }

/* ---- cambios (commits) ---- */
.commits { display: flex; flex-direction: column; gap: .6rem; }
.commit { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .7rem .9rem; }
.commit-subject { font-size: .92rem; }
.commit-meta { margin: .25rem 0 .4rem; font-family: ui-monospace, Menlo, monospace; }
.commit-files summary { cursor: pointer; color: var(--accent); font-size: .78rem; }
.commit-files ul { margin: .4rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .78rem; font-family: ui-monospace, Menlo, monospace; }

/* ---- módulos ---- */
.mod-table { border-collapse: collapse; width: 100%; font-size: .82rem; }
.mod-table td { border: 1px solid var(--border); padding: .4rem .6rem; vertical-align: top; }
.mod-table tr:first-child td { background: #243041; font-weight: 600; }
.mod-card { gap: .5rem; }
.mod-resp { margin: 0; font-size: .85rem; color: #cdd7e0; }
.mod-rows { display: flex; flex-direction: column; gap: .3rem; }
.mod-row { display: flex; gap: .5rem; font-size: .8rem; }
.mod-label { flex: 0 0 5.5rem; color: var(--muted); }
.mod-path { font-family: ui-monospace, Menlo, monospace; }

/* ---- control: enviar a display ---- */
.hub-head .spacer { flex: 1; }
.target-wrap { display: flex; align-items: center; gap: .4rem; }
.display-target {
  width: 8rem; padding: .3rem .5rem; font-size: .82rem; font-family: ui-monospace, Menlo, monospace;
  background: #243041; color: var(--fg); border: 1px solid var(--border); border-radius: 6px;
}
.display-target:focus { outline: none; border-color: var(--accent); }
.tab-toolbar { margin-bottom: 1rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.send-btn:disabled { opacity: .4; cursor: default; }
.frame-slot {
  padding: .3rem .4rem; font-size: .8rem; background: #243041; color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
}
#displays-live { margin-left: auto; }
.disp-link-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.disp-link {
  color: var(--accent); text-decoration: none; font-family: ui-monospace, Menlo, monospace;
  font-size: .82rem; word-break: break-all;
}
.disp-link:hover { text-decoration: underline; }

/* ---- frames (display multi-panel) ---- */
.frames { display: grid; gap: .8rem; }
.frames-1 { grid-template-columns: minmax(0, 1fr); }
.frames-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.frames-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.frame { border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 90vh; background: var(--bg); }
.frame-head {
  position: sticky; top: 0; z-index: 2;
  padding: .4rem .7rem; background: var(--panel); border-bottom: 1px solid var(--border);
  font-family: ui-monospace, Menlo, monospace; font-size: .78rem; color: var(--muted);
}
.frame-content { padding: .6rem .8rem; }
@media (max-width: 900px) { .frames-2, .frames-3 { grid-template-columns: 1fr; } }

/* ---- layouts no-cuadrados (presets; van después de frames-N para ganar) ---- */
.frames.layout-rows { grid-template-columns: minmax(0, 1fr); }               /* filas apiladas */
.frames.layout-main-side { grid-template-columns: 2fr minmax(0, 1fr); }      /* 1 grande izq */
.frames.layout-main-side.frames-3 .frame:first-child { grid-row: span 2; }   /* con 3: apila 2 a la der */
.frames.layout-focus { grid-template-columns: minmax(0, 1fr); }              /* solo el frame 1 */
.frames.layout-focus .frame:not(:first-child) { display: none; }
.frames.layout-focus .frame { max-height: 96vh; }
@media (max-width: 900px) { .frames.layout-main-side { grid-template-columns: 1fr; } .frames.layout-main-side.frames-3 .frame:first-child { grid-row: auto; } }
.grafo-frame { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* ---- página display (pasiva) ---- */
.display-mode header, .display-mode footer { display: none; }
.display-header {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1.2rem; border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.display-header .disp-name { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.display-header .disp-state { color: var(--muted); font-size: .85rem; }
.display-header .disp-dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); margin-left: auto; }
.display-header .disp-dot.live { background: #3fb950; box-shadow: 0 0 6px #3fb950; }
.display-view { padding: 1.2rem 1.5rem; }
/* Botón de pantalla completa: transparente por default, visible al hover. */
.fs-btn {
  position: fixed; bottom: .6rem; right: .6rem; z-index: 20;
  width: 2.2rem; height: 2.2rem; border-radius: 6px;
  background: rgba(255, 255, 255, .04); color: var(--fg); border: 1px solid transparent;
  font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: .08; transition: opacity .15s, background .15s;
}
.fs-btn:hover { opacity: 1; background: rgba(255, 255, 255, .14); border-color: var(--border); }

/* Overlay transparente: tocar cualquier parte entra en pantalla completa (la esquina ⛶ queda encima). */
.fs-overlay {
  position: fixed; inset: 0; z-index: 15; padding: 0;
  background: transparent; border: 0; cursor: pointer;
}
.fs-overlay:active { background: rgba(255, 255, 255, .03); }
.fs-hint {
  position: fixed; left: 50%; bottom: 2rem; transform: translateX(-50%);
  font-size: .95rem; color: var(--fg); background: rgba(0, 0, 0, .55);
  padding: .5rem 1rem; border-radius: 999px; white-space: nowrap; pointer-events: none;
  animation: fsHintFade 6s ease-out forwards;
}
@keyframes fsHintFade { 0%, 55% { opacity: .6; } 100% { opacity: 0; } }
.display-view .grafo-frame { height: 88vh; }

/* ---- diagramas ---- */
.diagrams { display: flex; flex-direction: column; gap: 1.5rem; }
.diagram { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; overflow-x: auto; }
.diagram .mermaid { background: #fff; border-radius: 6px; padding: .5rem; margin: .5rem 0; }
.md-raw { white-space: pre-wrap; font-size: .78rem; font-family: ui-monospace, Menlo, monospace; margin: .3rem 0; }

/* ---- artefacto push-html (iframe llena el frame; el wrapper trae su propio marco) ---- */
.frame-content:has(> .artifact-embed-frame) { padding: 0; }
.artifact-embed-frame { display: block; width: 100%; height: 88vh; border: 0; background: #0e1416; }
.frames-2 .artifact-embed-frame, .frames-3 .artifact-embed-frame { height: 80vh; }
.display-view .artifact-embed-frame { height: 92vh; }
.frames.layout-focus .artifact-embed-frame { height: 94vh; }

/* ---- rotación / orientación de pantalla (PUT /api/pantalla/:n/config) ---- */
body[data-rotate="180"] { transform: rotate(180deg); }
body[data-rotate="90"], body[data-rotate="270"] {
  position: absolute; top: 0; left: 0; width: 100vh; height: 100vw; overflow: hidden; transform-origin: top left;
}
body[data-rotate="90"] { transform: rotate(90deg) translateY(-100vh); }
body[data-rotate="270"] { transform: rotate(270deg) translateX(-100vw); }
