:root {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  color-scheme: light;
  --surface: #ffffff;
  --bar: #fafbfc;
  --hover: #f1f3f6;
  --line: #e6e8ec;
  --text: #1f2933;
  --muted: #6b7480;
  --accent: #3a6fd8;
  --accent-soft: #eef3fd;
  --attention: #d9822b;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(31, 41, 51, .12), 0 1px 3px rgba(31, 41, 51, .08);
  color: var(--text);
  background: var(--surface);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--surface); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { width: 16px; height: 16px; flex-shrink: 0; }

#app {
  position: relative;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  container-type: size;
  container-name: shell;
}

/* Barra única: pestañas y menú */
.bar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: 40px;
  padding: 0 4px 0 6px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.tabs { display: flex; flex: 1; min-width: 0; gap: 2px; }
.tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 220px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  transition: color .15s, background-color .15s;
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab[aria-selected=true] { color: var(--accent); background: var(--surface); font-weight: 600; }
.tab[aria-selected=true]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}
.tab-icon { display: grid; place-items: center; }
.tab-icon svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab-attention {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--attention);
  box-shadow: 0 0 0 2px var(--bar);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { background: var(--hover); color: var(--text); }
.icon-button svg { fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

/* Menú ⋯ */
.menu { position: relative; display: flex; align-items: center; }
.menu-list {
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  z-index: 20;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu-list [role=menuitem] {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-size: 13px;
}
.menu-list [role=menuitem]:hover, .menu-list [role=menuitem]:focus-visible { background: var(--hover); outline: none; }
.menu-meta { margin: 4px 0 0; padding: 8px 10px 4px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }

/* Aplicaciones: los iframes nunca se desmontan */
.workspace { position: relative; flex: 1; min-height: 0; }
.app-panel { position: absolute; inset: 0; visibility: inherit; pointer-events: auto; z-index: 1; }
.app-panel[data-active=false] { visibility: hidden; pointer-events: none; z-index: 0; }
.app-frame { position: relative; display: block; width: 100%; height: 100%; border: 0; background: transparent; }
.app-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.app-loading::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.app-panel[data-loaded=true] .app-loading { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Diagnóstico: panel superpuesto bajo la barra */
.diagnostics {
  position: absolute;
  top: 40px;
  inset-inline: 0;
  bottom: 0;
  z-index: 10;
  overflow: auto;
  padding: 14px 16px 20px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.diagnostics-head { display: flex; align-items: center; gap: 8px; }
.diagnostics-head h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 600; }
.diagnostics-head > button:not(.icon-button) {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
}
.diagnostics-head > button:not(.icon-button):hover { background: var(--hover); }
.diagnostics h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; }
.muted, .disclaimer { font-size: 12px; line-height: 1.55; color: var(--muted); }
.disclaimer { margin-bottom: 0; }
.configuration { display: grid; grid-template-columns: minmax(96px, 140px) 1fr; gap: 6px 10px; margin: 14px 0; font-size: 12px; }
.configuration dt { color: var(--muted); }
.configuration dd { margin: 0; overflow-wrap: anywhere; }
.frame-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.frame-stat { padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.65; }
.frame-stat strong { display: block; font-weight: 600; }
.frame-stat span { display: block; }
.event-log { max-height: 280px; margin: 0; padding: 0; overflow: auto; list-style: none; font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; }
.event-log li { padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.event-log time { margin-right: 10px; color: var(--muted); }

.error-message {
  position: absolute;
  inset: 40px 0 auto;
  z-index: 15;
  margin: 12px;
  padding: 10px 12px;
  border: 1px solid #f3c7c2;
  border-radius: 8px;
  background: #fdf3f2;
  color: var(--danger);
  font-size: 13px;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Panel estrecho: sólo iconos en las pestañas */
@container shell (max-width: 300px) {
  .tab { padding: 0 10px; }
  .tab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tab-attention { position: absolute; top: 8px; right: 5px; }
}

/* Panel minimizado (estrecho o bajo): sólo la barra, apps vivas pero ocultas */
@container shell (max-width: 120px) {
  .bar { flex-direction: column; align-items: center; height: auto; padding: 6px 0; border-bottom: 0; }
  .tabs { flex-direction: column; flex: 0 0 auto; }
  .tab { justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: 8px; }
  .tab[aria-selected=true] { background: var(--accent-soft); }
  .tab[aria-selected=true]::after { left: -3px; right: auto; top: 8px; bottom: 8px; width: 2px; height: auto; }
  .menu { display: none; }
  .workspace, .diagnostics { visibility: hidden; }
}
@container shell (max-height: 120px) {
  .workspace, .diagnostics { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .tab { transition: none; }
  .app-loading::before { animation: none; }
}
