/* Estructura y controles compartidos; cada aplicación puede ampliar este tema. */
:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --bg: #0b1020;
  --surface: rgba(21, 29, 52, 0.78);
  --surface-strong: #151d34;
  --surface-soft: rgba(31, 43, 75, 0.5);
  --text: #f4f7ff;
  --muted: #9ca8c6;
  --line: rgba(195, 207, 255, 0.15);
  --accent: #b8f36d;
  --accent-ink: #172408;
  --warm: #ffb878;
  --danger: #ff8f9e;
  --radius: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
}

button, input, select { font: inherit; }
a { color: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--warm);
  outline-offset: 3px;
}

.shell {
  display: flex;
  flex-direction: column;
  width: min(1120px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 24px;
}

.topbar, .topbar-actions, .brand, .connection-status { display: flex; align-items: center; }
.topbar { justify-content: space-between; gap: 20px; }
.shell > .topbar { margin-bottom: 28px; }
.topbar-actions { gap: 18px; }
.brand {
  gap: 12px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-decoration: none;
}

.brand.brand-static { cursor: default; }
.brand::before {
  display: block;
  flex: 0 0 124px;
  width: 124px;
  height: 42px;
  content: "";
  background: url("../../../logo-burrotools.png") center / contain no-repeat;
}
.brand .brand-mark { display: none; }
.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 50%;
}
.topbar .topbar-actions .apps-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 34px;
  padding: 0 13px;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.topbar .topbar-actions .apps-home-link:hover {
  color: var(--text);
  background: var(--surface);
  border-color: rgba(195, 207, 255, 0.3);
  transform: translateY(-2px);
}
.menu-toggle { display: inline-flex; align-items: center; gap: 9px; min-height: 36px; padding: 0 11px; color: var(--text); font: inherit; font-size: .72rem; font-weight: 800; background: rgba(21,29,52,.72); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: background 160ms ease, border-color 160ms ease, transform 160ms ease; }
.menu-toggle:hover { background: var(--surface); border-color: rgba(195,207,255,.36); transform: translateY(-1px); }
.menu-toggle-icon { display: grid; gap: 3px; width: 15px; }
.menu-toggle-icon i { display: block; height: 1.5px; background: currentColor; border-radius: 99px; }
.sidebar-backdrop { position: fixed; z-index: 110; inset: 0; background: rgba(4,8,19,.66); backdrop-filter: blur(3px); opacity: 0; transition: opacity 180ms ease; }
.sidebar-backdrop.is-visible { opacity: 1; }
.app-sidebar { position: fixed; z-index: 111; top: 0; right: 0; bottom: 0; display: flex; flex-direction: column; width: min(320px, calc(100vw - 42px)); padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); background: #121a31; border-left: 1px solid var(--line); box-shadow: -18px 0 50px rgba(0,0,0,.3); transform: translateX(103%); transition: transform 180ms ease; }
.app-sidebar.is-open { transform: translateX(0); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 5px 20px; color: var(--text); font-size: .75rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; border-bottom: 1px solid var(--line); }
.sidebar-close { display: grid; width: 34px; height: 34px; padding: 0; place-items: center; color: var(--muted); font: inherit; font-size: 1.45rem; line-height: 1; background: transparent; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.sidebar-close:hover { color: var(--text); background: rgba(195,207,255,.1); }
.app-sidebar .app-nav { display: grid; gap: 5px; margin-top: 18px; }
.app-sidebar .app-nav a { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px; color: var(--muted); font-size: .86rem; font-weight: 800; text-decoration: none; border: 1px solid transparent; border-radius: 11px; }
.app-sidebar .app-nav a > span { display: grid; width: 21px; place-items: center; color: var(--warm); font-size: 1rem; }
.app-sidebar .app-nav a:hover, .app-sidebar .app-nav a[aria-current="page"] { color: var(--text); background: rgba(195,207,255,.1); border-color: var(--line); }
.app-sidebar .app-nav a[aria-current="page"] { box-shadow: inset 3px 0 var(--accent); }
.app-sidebar .app-nav.sidebar-footer { flex: 0 0 auto; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.app-sidebar .app-nav a > .status-dot { flex: 0 0 8px; width: 8px; margin: 0 6.5px; }
body.has-side-menu { overflow: hidden; }
.connection-status { gap: 9px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.status-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(184, 243, 109, 0.12);
}
.status-dot.offline { background: var(--warm); box-shadow: 0 0 0 4px rgba(255, 184, 120, 0.12); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-2px); }
.button-small { min-height: 34px; padding: 0 13px; font-size: 0.72rem; }
.button-primary { color: var(--accent-ink); background: var(--accent); }
.button-primary:hover:not(:disabled) { background: #c9ff88; }
.button-secondary { color: var(--text); background: transparent; border-color: var(--line); }
.button-secondary:hover:not(:disabled) { background: var(--surface); border-color: rgba(195, 207, 255, 0.3); }
.topbar .topbar-actions #install-button {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}
.topbar .topbar-actions #install-button:hover:not(:disabled) { background: #c9ff88; }
.button-danger { color: var(--danger-ink, #3a1019); background: var(--danger); }
.button-danger:hover:not(:disabled) { background: #ffabb6; }

.back-to-top {
  position: fixed;
  z-index: 20;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  color: var(--accent-ink);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  text-decoration: none;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.34);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}
.back-to-top:hover { background: #c9ff88; transform: translateY(-2px); }
.back-to-top > span { font-size: 1.1rem; line-height: 1; }

.image-preview {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 56px);
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  background: rgba(3, 7, 16, 0.84);
  transition: opacity 120ms ease, visibility 120ms ease;
}

.image-preview.is-visible { visibility: visible; opacity: 1; }
.image-preview.is-modal { pointer-events: auto; }
.image-preview__image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.image-preview.is-selected .image-preview__image { border: 6px solid var(--accent); }
.image-preview__close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: none;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--text);
  font: inherit;
  font-size: 2rem;
  line-height: 1;
  background: rgba(11, 16, 32, 0.82);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.image-preview.is-modal .image-preview__close { display: block; }
.image-preview-trigger { cursor: zoom-in; touch-action: manipulation; }
body.has-image-preview { overflow: hidden; }

.startup-loader {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 10, 24, 0.72);
  backdrop-filter: blur(10px);
}

.startup-loader__card {
  width: min(100%, 390px);
  padding: 24px;
  background: var(--surface-strong, #151d34);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.startup-loader__spinner {
  display: block;
  width: 26px;
  height: 26px;
  margin-bottom: 18px;
  border: 3px solid rgba(195, 207, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: startup-loader-spin 800ms linear infinite;
}

.startup-loader__heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.startup-loader__heading strong { font-size: 0.94rem; }
.startup-loader__value { color: var(--accent); font-size: 0.78rem; font-weight: 800; }

.startup-loader__progress {
  display: block;
  width: 100%;
  height: 9px;
  overflow: hidden;
  appearance: none;
  accent-color: var(--accent);
  background: rgba(195, 207, 255, 0.1);
  border: 0;
  border-radius: 999px;
}

.startup-loader__progress::-webkit-progress-bar {
  background: rgba(195, 207, 255, 0.1);
  border-radius: 999px;
}

.startup-loader__progress::-webkit-progress-value,
.startup-loader__progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.startup-loader__progress:not([value]) {
  background: linear-gradient(
    90deg,
    rgba(195, 207, 255, 0.1) 0%,
    rgba(195, 207, 255, 0.1) 35%,
    var(--accent) 45%,
    var(--accent) 55%,
    rgba(195, 207, 255, 0.1) 65%,
    rgba(195, 207, 255, 0.1) 100%
  );
  background-size: 200% 100%;
  animation: startup-loader-progress 1.2s ease-in-out infinite;
}

.startup-loader__message {
  min-height: 1.4em;
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

@keyframes startup-loader-spin {
  to { transform: rotate(360deg); }
}

@keyframes startup-loader-progress {
  to { background-position: -200% 0; }
}

.app-footer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  min-height: 42px;
  padding: 18px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
}
.app-footer img {
  display: block;
  width: 18px;
  height: 24px;
  object-fit: contain;
}
.app-footer #version::before {
  content: "— ";
}
.app-footer span:last-child { display: inline; margin-top: 0; }

@media (max-width: 720px) {
  .shell { width: min(100% - 28px, 1120px); padding-top: 18px; }
  .shell > .topbar { margin-bottom: 22px; }
  .topbar, .topbar-actions { align-items: flex-start; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
  .app-footer { flex-direction: row; }
}

@media (prefers-reduced-motion: reduce) {
  .startup-loader__spinner,
  .startup-loader__progress:not([value]) { animation: none; }
  .image-preview { transition: none; }
}
