:root {
    --sidebar-w: 240px;
    --sidebar-w-collapsed: 64px;
    --sidebar-bg: #1f2937;
    --sidebar-fg: #d1d5db;
    --sidebar-fg-hover: #ffffff;
    --sidebar-active: #2563eb;
    --topbar-h: 56px;
    --topbar-bg: #ffffff;
    --topbar-border: #e5e7eb;
    --content-bg: #f3f4f6;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--content-bg); }

/* Cross-document view transitions (Chrome 126+, Safari 18+): navegación
   suave sin flash del layout. Explícitamente NO transicionamos el sidebar
   (view-transition-name arriba lo excluye del cross-fade). */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: .18s;
    animation-timing-function: ease-out;
}

.app-shell { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    transition: width .2s ease;
    overflow: hidden;
    /* View Transitions (Chrome/Edge 126+, Safari 18+): al navegar entre páginas
       del mismo origen, el navegador reutiliza la posición/píxeles del sidebar
       en vez de repintarlo — elimina el flash de re-render. */
    view-transition-name: sidebar;
}
.app-shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app-shell.collapsed .brand-text,
.app-shell.collapsed .brand-logo,
.app-shell.collapsed .sidebar-brand > i,
.app-shell.collapsed .side-text,
.app-shell.collapsed .side-caret,
.app-shell.collapsed .side-caret-btn { display: none; }
/* Colapsado: resetear indentaciones y compactar iconos */
.app-shell.collapsed .sidebar-nav .side-link,
.app-shell.collapsed .sidebar-nav .side-toggle,
.app-shell.collapsed .sidebar-nav .side-link-row,
.app-shell.collapsed .sidebar-nav .side-link-main {
    padding-left: 0 !important;
    padding-right: 0 !important;
    justify-content: center;
}
.app-shell.collapsed .sidebar-nav .side-link i,
.app-shell.collapsed .sidebar-nav .side-link-main i { margin: 0; }
.app-shell.collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }

.sidebar-brand {
    padding: 16px; font-weight: 600; color: #fff; font-size: 15px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-footer { padding: 8px 0; border-top: 1px solid rgba(255,255,255,.08); }

.side-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; color: var(--sidebar-fg); text-decoration: none;
    font-size: 14px; border: 0; background: transparent; width: 100%;
    text-align: left; cursor: pointer;
}
.side-link:hover { color: var(--sidebar-fg-hover); background: rgba(255,255,255,.05); }
.side-link.active { color: #fff; background: var(--sidebar-active); }
.side-link i { min-width: 20px; text-align: center; font-size: 16px; }
.side-child { padding-left: 40px; font-size: 13px; }
.side-toggle .side-caret { margin-left: auto; transition: transform .2s; }
.side-toggle[aria-expanded="false"] .side-caret { transform: rotate(-90deg); }

/* Nodo con ruta propia + children: link + caret separados */
.side-link-row {
    display: flex; align-items: center;
    color: var(--sidebar-fg);
    font-size: 14px;
    padding-right: 4px;
}
.side-link-row:hover { background: rgba(255,255,255,.05); }
.side-link-row.active { background: var(--sidebar-active); color: #fff; }
.side-link-row.active .side-link-main { color: #fff; }
.side-link-main {
    flex: 1;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 8px 10px 0;
    color: inherit; text-decoration: none;
}
.side-link-main:hover { color: var(--sidebar-fg-hover); }
.side-link-main i { min-width: 20px; text-align: center; font-size: 16px; }
.side-caret-btn {
    background: transparent; border: 0; color: inherit;
    padding: 6px 8px; cursor: pointer;
    display: flex; align-items: center;
}
.side-caret-btn:hover { color: #fff; }
.side-caret-btn .side-caret { transition: transform .2s; }
.side-caret-btn[aria-expanded="false"] .side-caret { transform: rotate(-90deg); }

/* MAIN */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.content { padding: 20px; flex: 1; }

/* Botón toggle dentro del brand del sidebar — no ocupa ancho ni alto del contenido */
.sidebar-collapse-btn {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: var(--sidebar-fg);
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-collapse-btn:focus-visible { outline: 2px solid var(--sidebar-active); outline-offset: 2px; }
.app-shell.collapsed .sidebar-collapse-btn {
    /* En colapsado, el botón es el único elemento visible del brand */
    margin: 0 auto;
}

/* Bloque de usuario en el sidebar footer */
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-fg);
    border-bottom: 1px solid rgba(255,255,255,.05);
}
.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--sidebar-active);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
    user-select: none;
}
.sidebar-user-info { display: flex; flex-direction: column; overflow: hidden; }
.sidebar-user-name {
    font-size: 13px; font-weight: 600; color: #f9fafb;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-group {
    font-size: 11px; color: #d1d5db;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-login {
    font-size: 11px; color: #9ca3af;
    font-family: monospace;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-shell.collapsed .sidebar-user { justify-content: center; padding: 10px 0; }
.app-shell.collapsed .sidebar-user-info { display: none; }

.site-footer {
    padding: 8px 20px;
    background: #ffffff;
    border-top: 1px solid var(--topbar-border);
    color: #6b7280;
    font-size: 12px;
    text-align: center;
}

.brand-logo { max-height: 28px; max-width: 32px; object-fit: contain; }

.login-footer {
    position: fixed;
    bottom: 12px;
    left: 0; right: 0;
    text-align: center;
    color: #6b7280;
    font-size: 12px;
}

/* BOTÓN VOLVER — top-left en headers de formularios */
.btn-back {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    border: 0;
    text-decoration: none;
    font-size: 18px;
    margin-right: 4px;
    transition: background .15s, color .15s;
}
.btn-back:hover { background: #f3f4f6; color: #111827; }
.btn-back:focus-visible { outline: 2px solid var(--sidebar-active); outline-offset: 2px; }

/* DOCUMENTOS TREE VIEW */
.doc-tree { border-top: 1px solid #e5e7eb; }
.tree-row {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background .15s;
}
.tree-row:hover { background: #f9fafb; }
.tree-area-row { background: #f3f4f6; font-size: 14px; }
.tree-doc-row { padding-left: 40px; font-size: 13px; }
.tree-version { padding: 8px 16px 8px 72px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #f3f4f6; font-size: 12px; }
.tree-anexo { padding: 8px 16px 8px 40px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid #f3f4f6; font-size: 13px; background: #fafafa; }
.tree-anexo:hover { background: #f0f9ff; }
.tree-version:hover { background: #fafafa; }
.tree-caret { transition: transform .2s; width: 12px; }
.tree-caret.rotated { transform: rotate(90deg); }
.tree-empty { padding: 10px 40px; color: #9ca3af; font-size: 12px; font-style: italic; }
.tree-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 6px;
    background: transparent; border: 0; color: #6b7280;
    text-decoration: none;
    cursor: pointer; font-size: 14px;
    transition: background .15s, color .15s;
}
.tree-icon-btn:hover { background: #e5e7eb; color: #111827; }
.tree-icon-btn.text-danger:hover { background: #fee2e2; color: #b91c1c; }
.tree-icon-btn.text-success:hover { background: #dcfce7; color: #166534; }
.tree-icon-btn.text-primary:hover { background: #dbeafe; color: #1e40af; }

/* Botón "+ Versión" — outline compacto que convive con los tree-icon-btn */
.tree-btn-version {
    padding: 2px 8px;
    font-size: 12px;
    line-height: 1.2;
    height: 28px;
    display: inline-flex; align-items: center; gap: 4px;
}
.tree-btn-version i.bi { font-size: 12px; }

.tree-version-toggle { padding: 6px 16px 6px 72px; }
.tree-version-toggle button { padding: 0; font-size: 12px; text-decoration: none; }

/* MODAL 95% x 95% */
.modal-backdrop-view {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1050;
    display: flex; align-items: center; justify-content: center;
    padding: 2.5vh 2.5vw;
}
.modal-view {
    width: 95vw; height: 95vh;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,.2);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.modal-view-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}
.modal-view-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: #fff;
}

/* WELCOME TOAST */
.welcome-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    animation: slideInRight .5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.welcome-toast-inner {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--theme, #2563eb) 0%, var(--theme-hover, #1e40af) 100%);
    color: #ffffff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
    font-weight: 500;
    min-width: 280px;
    max-width: 420px;
}
.welcome-toast-inner i.bi { font-size: 22px; }
.welcome-toast .btn-close-toast {
    background: transparent; border: 0; color: #ffffff;
    font-size: 22px; line-height: 1; opacity: .7;
    margin-left: auto; cursor: pointer; padding: 0 4px;
}
.welcome-toast .btn-close-toast:hover { opacity: 1; }
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(120%); }
    to { opacity: 1; transform: translateX(0); }
}
.toast-leave { opacity: 0; transform: translateX(120%); transition: all .4s ease; }

/* THEME COLOR SWATCHES */
.theme-swatch {
    width: 28px; height: 28px;
    border-radius: 6px;
    border: 2px solid #e5e7eb;
    cursor: pointer;
    padding: 0;
    transition: transform .15s, border-color .15s;
}
.theme-swatch:hover { transform: scale(1.15); border-color: #6b7280; }

/* SORTABLE (drag & drop) */
.sortable-ghost { opacity: .3; background: #dbeafe !important; }
.sortable-chosen { background: #eff6ff; }
.drag-handle { user-select: none; }
.drag-handle:active { cursor: grabbing !important; }

/* Menú tree */
.menu-tree { list-style: none; padding: 0; margin: 0; }
.menu-tree .menu-node {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 8px 10px; margin: 4px 0; display: flex; align-items: center; gap: 8px;
}
.menu-tree .menu-node.padre { background: #f9fafb; }
.menu-tree .menu-children { list-style: none; padding-left: 24px; margin: 0; min-height: 8px; }
.menu-tree .menu-empty-hint {
    color: #9ca3af; font-size: 12px; padding: 4px 8px;
    border: 1px dashed #d1d5db; border-radius: 4px; margin: 4px 0;
}
.menu-tree .menu-drop-here {
    background: #dbeafe !important;
}

/* LOGIN */
.login-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f3f4f6; }
.login-card { background: #fff; padding: 32px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.08); width: 100%; max-width: 380px; }
.login-title { font-size: 20px; font-weight: 600; margin: 0 0 24px; text-align: center; }
