/*
 * Notas: hoja de estilos.
 * Tokens en :root. Oscuro por defecto; claro con [data-theme="light"].
 */

:root {
  color-scheme: dark;
  --bg: #0e1115;
  --surface: #161b21;
  --surface-raised: #1d242c;
  --border: #29313b;
  --text: #d5dbe3;
  --text-muted: #8893a1;
  --accent: #6ea8dc;
  --accent-ink: #0b1420;
  --danger: #e07a7a;
  --ok: #7fc096;
  --warn: #dcb062;
  --mark-bg: #5a4a10;
  --mark-current-bg: #a07c12;
  --focus: #9cc8f0;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 6px;
  --space: 0.75rem;
  --topbar-h: 3.5rem;
  --sidebar-w: 17rem;
  --ease: 120ms ease-out;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-raised: #eceff3;
  --border: #d3d9e1;
  --text: #1d232b;
  --text-muted: #5b6573;
  --accent: #2b6cb0;
  --accent-ink: #ffffff;
  --danger: #b03a3a;
  --ok: #2e7d4f;
  --warn: #94600a;
  --mark-bg: #ffe98a;
  --mark-current-bg: #ffb547;
  --focus: #1d5fa8;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font-ui);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--space);
  top: -3rem;
  z-index: 10;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: var(--space);
}

/* Barra superior */

.topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  padding: 0 var(--space) 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.connection {
  font-size: 0.8rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  white-space: nowrap;
}

.connection[data-state="connected"] { color: var(--ok); }
.connection[data-state="retrying"] { color: var(--warn); }
.connection[data-state="offline"] { color: var(--danger); }

/* Botones y campos */

.btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--danger);
}

input[type="password"],
input[type="search"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
}

.empty {
  margin: 0;
  padding: var(--space);
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Puerta de acceso */

.gate {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.gate-card {
  width: min(24rem, 100%);
  display: grid;
  gap: 0.6rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.gate-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.gate-card label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.message {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.85rem;
  color: var(--danger);
}

/* Estructura principal */

.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar h2 {
  margin: 0;
  padding: 0.9rem var(--space) 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.device-list {
  flex: 1;
  margin: 0;
  padding: 0 0.4rem 0.6rem;
  list-style: none;
  overflow-y: auto;
}

.device {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.device:hover {
  background: var(--surface-raised);
}

.device[aria-current="true"] {
  background: var(--surface-raised);
  box-shadow: inset 2px 0 0 var(--accent);
}

.device-name {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.device-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Área de trabajo */

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem var(--space);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.menu-toggle {
  display: none;
}

.viewer-title {
  max-width: 22ch;
  margin: 0 0.25rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search {
  flex: 1 1 12rem;
  min-width: 10rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search input {
  max-width: 22rem;
}

.match-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.viewer-wrap {
  position: relative;
  min-height: 0;
}

.viewer {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font: 0.85rem/1.55 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
  color: var(--text);
  background: var(--surface);
}

.viewer mark {
  color: inherit;
  background: var(--mark-bg);
  border-radius: 2px;
}

.viewer mark.current {
  background: var(--mark-current-bg);
}

.viewer-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.resume {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.25rem;
  padding: 0.45rem var(--space);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.st-msg {
  margin-left: auto;
  color: var(--warn);
}

/* Responsive: la barra lateral pasa a desplegable en móvil */

@media (max-width: 720px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 5;
    width: min(80vw, 18rem);
    transform: translateX(-102%);
    transition: transform 160ms ease-out;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: none;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .subtitle {
    display: none;
  }

  .viewer-title {
    max-width: 14ch;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
