/* ===== App Shell – Kufferath UI v2 (refactor, UNIFICADO) ===== */
:root {
  /* Paleta base (oscura con acento amarillo) */
  --bg-0: #0c1117; /* fondo app */
  --bg-1: #121821; /* sidebar */
  --bg-2: #161d28; /* tarjetas / topbar */
  --bg-3: #1b2430; /* hover / elevación */
  --line: #223044; /* bordes sutiles */
  --fg-1: #e9eef7; /* texto principal */
  --fg-2: #9fb1c7; /* texto secundario */
  --accent: #f5c518; /* amarillo Kufferath */

  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --trans: .18s ease;

  /* Layout */
  --h-top: 56px; /* altura topbar (single source of truth) */
  --w-side: 264px; /* ancho sidebar normal */
  --w-side-col: 78px; /* ancho rail colapsado */

  /* Estado actual del rail (desktop) */
  --sideW: var(--w-side);

  /* Sidebar hover/active */
  --side-hover: #242f44;              /* hover sólido */
  --side-hover-ring: #2e3c56;         /* borde interno sutil */
  --side-active-from: #1e2a3a;        /* gradiente activo */
  --side-active-to: #152133;
  --side-rail: var(--accent);         /* barrita izquierda */
  --side-ring-focus: rgba(245,197,24,.35); /* focus a11y */
  --fg-1-strong: #f3f7fe;             /* texto fuerte */
}

* { box-sizing: border-box }
html, body { height: 100%; margin: 0 }

body {
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--fg-1);
  background: radial-gradient(1200px 900px at 0% -10%, #283c5c 0%, var(--bg-0) 55%) fixed;
}

/* ===== App grid ===== */
.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--sideW) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas:
    "side top"
    "side main";
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--h-top) 1fr;
    grid-template-areas:
      "top"
      "main";
  }
}

/* estado colapsado (desktop) */
.app-shell.is-collapsed { --sideW: var(--w-side-col); }

/* ===== Sidebar ===== */
.side {
  grid-area: side;
  width: var(--w-side);
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  transition: width var(--trans);
  position: relative;
}
.app-shell.is-collapsed .side { width: var(--w-side-col); }

.side-top { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); }

.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--fg-1);
  padding: 6px 8px; border-radius: 10px;
  font-weight: 900; letter-spacing: .2px;
}
.brand img { display: block; height: auto; max-width: 225px; }
.brand .logo-full { display: block; max-width: 180px; }
.brand .logo-compact { display: none; width: 28px; }
.app-shell.is-collapsed .brand .logo-full { display: none; }
.app-shell.is-collapsed .brand .logo-compact { display: block; }

.me {
  display: flex; gap: 10px; align-items: center;
  margin-top: 10px; padding: 8px;
  background: color-mix(in srgb, var(--bg-2) 88%, black);
  border: 1px solid var(--side-hover-ring);
  border-radius: 12px; cursor: pointer;
}
.me:hover {
  background: color-mix(in srgb, var(--bg-2) 95%, var(--side-hover));
  box-shadow: inset 0 0 0 1px var(--side-hover-ring);
}
.me .avatar {
  width: 34px; height: 34px; border-radius: 12px;
  display: grid; place-items: center;
  background: #0e141f; border: 1px solid #223148;
}
.me-meta { min-width: 0 }
.me-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.me-role { color: var(--fg-2); font-size: 12px }

/* Nav */
.side-nav, .side-bottom { padding: 8px }
.side-bottom { margin-top: auto }

.side .item {
  --pad-x: 12px;
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--fg-2);
  padding: 10px var(--pad-x); margin: 4px 0;
  border-radius: 12px; position: relative;
  transition: background var(--trans), color var(--trans), box-shadow var(--trans);
}
.side .item .ico { width: 22px; height: 22px; display: grid; place-items: center; opacity: .9 }

/* Hover: fondo notorio + borde interno + texto fuerte + barrita */
.side .item:hover {
  background: var(--side-hover);
  color: var(--fg-1-strong);
  box-shadow: inset 0 0 0 1px var(--side-hover-ring);
}
.side .item:hover::before {
  content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 99px;
  background: color-mix(in srgb, var(--side-rail) 65%, transparent);
}

/* Activo: gradiente + doble sombra + barrita sólida */
.side .item.active {
  background: linear-gradient(180deg, var(--side-active-from), var(--side-active-to));
  color: #fff;
  box-shadow: inset 0 0 0 1px #2c3c55, 0 8px 22px rgba(0, 0, 0, .28);
}
.side .item.active::before {
  content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px;
  width: 4px; border-radius: 99px; background: var(--side-rail);
}

/* Peligroso (Salir) */
.side .item.danger { color: #ffb4b4 }
.side .item.danger:hover {
  background: #3b1f26; color: #ffd4d4;
  box-shadow: inset 0 0 0 1px #5a2a34;
}

/* Rail colapsado (desktop): solo iconos + tooltip */
.app-shell.is-collapsed .me-meta,
.app-shell.is-collapsed .item .txt,
.app-shell.is-collapsed .brand span { display: none }

.app-shell.is-collapsed .item { justify-content: center; padding: 10px 0 }
.app-shell.is-collapsed .side-nav {
  display: flex; flex-direction: column; gap: 6px; padding: 6px 0;
}
.app-shell.is-collapsed .side-nav .item {
  width: 48px; height: 48px; margin: 0 auto; border-radius: 14px; border: 1px solid transparent;
}
.app-shell.is-collapsed .side-nav .item:hover {
  background: var(--side-hover); border-color: var(--side-hover-ring);
}
.app-shell.is-collapsed .side-nav .item.active {
  background: linear-gradient(180deg, var(--side-active-from), var(--side-active-to));
  border-color: #2c3c55; box-shadow: 0 0 0 3px rgba(245, 197, 24, .18);
}
.app-shell.is-collapsed .side-nav .item[data-tip]:hover::after {
  content: attr(data-tip);
  position: fixed;
  left: calc(var(--w-side-col) + 12px);
  transform: translateY(-50%);
  background: #0f172a; color: #e5e7eb;
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid #30415e;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.35));
  white-space: nowrap; z-index: 2000; pointer-events: none;
}

/* ===== Topbar ===== */
.topbar {
  grid-area: top;
  height: var(--h-top);
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px;
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  border-bottom: 1px solid var(--line);
}
.hamburger {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center; color: var(--fg-1);
}
.hamburger:hover { background: rgba(255, 255, 255, .06) }
.hamburger span { display: block; width: 16px; height: 2px; background: currentColor; margin: 2px 0; border-radius: 1px }
.crumbs {
  font-weight: 900; letter-spacing: .3px; padding: 6px 10px;
  border-radius: 10px; background: #101a27; border: 1px solid var(--line);
}

/* ===== Main / contenido ===== */
.main {
  grid-area: main;
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ===== Frame + loader ===== */
.frame-wrap { position: relative; height: calc(100dvh - var(--h-top)); }
.content-frame {
  display: block; width: 100%; height: 100%;
  border: 0 !important; background: transparent;
  opacity: 0; transition: opacity .25s ease;
}
.content-frame.is-ready { opacity: 1; }

.frame-loader {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(17, 24, 39, .55); opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.frame-loader.show { opacity: 1; pointer-events: auto; }

.loader-bar {
  position: absolute; left: 10%; right: 10%; top: 48%;
  height: 4px; background: rgba(255, 196, 0, .25);
  border-radius: 4px; overflow: hidden;
}
.loader-bar::after {
  content: ""; display: block; height: 100%; width: 30%;
  background: #ffc400; border-radius: 4px;
  animation: loaderSlide 1.2s ease-in-out infinite;
}
@keyframes loaderSlide {
  0% { transform: translateX(-100%) }
  50% { transform: translateX(60%) }
  100% { transform: translateX(220%) }
}

/* ===== Utilidades ===== */
.separator { height: 1px; background: var(--line); margin: 6px 8px }
::-webkit-scrollbar { width: 12px; height: 12px }
::-webkit-scrollbar-thumb { background: #1f2a3a; border: 2px solid #0e141f; border-radius: 999px }

/* Iconos outline */
.i, .side .ico .i {
  width: 22px; height: 22px; display: inline-block;
  stroke: currentColor; fill: none; stroke-width: 1.1;
  stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke;
}

/* ===== Accesibilidad de foco (desktop) ===== */
@media (min-width: 981px) {
  .topbar .hamburger, .topbar .crumbs, .side a.item, .brand, .side-dismiss { outline: none; }

  .topbar .hamburger:focus, .topbar .hamburger:focus-visible,
  .topbar .crumbs:focus, .topbar .crumbs:focus-visible,
  .side a.item:focus, .side a.item:focus-visible,
  .brand:focus, .brand:focus-visible,
  .side-dismiss:focus, .side-dismiss:focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 2px var(--side-ring-focus);
  }

  .topbar .crumbs {
    background: transparent; border: 0; padding: 0; font-weight: 700;
  }
}

/* ===== Drawer móvil (<=980px) ===== */
.side-dismiss { display: none !important; appearance: none; border: 0; background: transparent; }

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns:1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "top" "main";
  }
  .topbar { z-index: 9997; }
  .main { margin: 0; min-width: 0; min-height: 0; overflow: hidden; }

  /* Sidebar como overlay */
  .side {
    position: fixed; inset: 0 auto 0 0;
    width: min(var(--w-side), 88vw);
    transform: translateX(-100%); transition: transform var(--trans);
    z-index: 9999; box-shadow: var(--shadow);
  }
  .app-shell.is-open .side { transform: translateX(0) }

  /* Oscurecedor al abrir */
  .app-shell.is-open::after {
    content: ""; position: fixed; inset: 0;
    background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px);
    z-index: 9998;
  }

  /* Botón cerrar dentro del drawer */
  .side-top { display: flex; align-items: center; gap: 10px; }
  .side-dismiss {
    display: inline-grid !important; place-items: center;
    width: 44px; height: 44px; border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .06);
    color: var(--fg-1); cursor: pointer;
  }
  .side-dismiss:hover { background: rgba(255, 255, 255, .1) }
  .side-dismiss svg { width: 22px; height: 22px }

  /* Al abrir el drawer ocultamos controles molestos */
  .app-shell.is-open .topbar .hamburger,
  .app-shell.is-open .topbar .crumbs { display: none !important; }
}
.me:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(245,197,24,.35);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notif { margin-left:auto; position:relative; }
.notif-btn{ position:relative; display:grid; place-items:center; width:36px; height:36px; border-radius:10px; background:var(--panel,#111418); border:1px solid var(--line,#1e2329); box-shadow:var(--shadow,0 20px 40px #0008,inset 0 1px 0 #ffffff14); cursor:pointer; }
.notif-btn svg{ width:20px; height:20px; fill:var(--text,#e6e6e6); }
.notif-btn.ping{ outline:2px solid var(--acc,#ffc400); outline-offset:2px; }
.badge{ position:absolute; top:-4px; right:-4px; min-width:18px; height:18px; padding:0 5px; border-radius:999px; background:var(--acc,#ffc400); color:#111; font-size:11px; font-weight:700; display:inline-flex; align-items:center; justify-content:center; border:1px solid #0006; }
.notif-panel{ position:absolute; right:0; top:calc(100% + 8px); width:min(360px,92vw); background:var(--panel,#111418); border:1px solid var(--line,#1e2329); border-radius:14px; box-shadow:var(--shadow,0 20px 40px #0008,inset 0 1px 0 #ffffff14); overflow:hidden; z-index:50; }
.panel-head,.panel-foot{ display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid var(--line,#1e2329); }
.panel-foot{ border-top:1px solid var(--line,#1e2329); border-bottom:none; }
.panel-head .title{ font-weight:700; color:var(--text,#e6e6e6); }
.panel-list{ max-height:60vh; overflow:auto; }
.notif-item{ display:grid; gap:6px; padding:10px 12px; border-bottom:1px solid var(--line,#1e2329); }
.notif-item.unread{ background:rgba(255,196,0,.08); }
.notif-item:hover{ background:rgba(255,255,255,.04); }
.notif-item .title{ font-weight:600; color:var(--text,#e6e6e6); }
.notif-item .meta{ font-size:12px; color:var(--muted,#cfcfcfbb); }
.notif-item .actions{ display:flex; gap:8px; }
.btn-link,.link{ background:none; border:none; color:var(--acc,#ffc400); cursor:pointer; font-size:13px; padding:0; }
