/* Shell: menú colapsable, scroll propio, barra superior */
body.has-shell {
    grid-template-columns: 260px 1fr;
    transition: grid-template-columns 0.18s ease;
}
.sidebar {
    height: 100vh;
    max-height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    padding: 16px 12px 12px;
    position: sticky;
    top: 0;
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    margin-bottom: 4px;
}
.brand {
    display: flex;
    align-items: baseline;
    gap: 0;
    min-width: 0;
}
.brand-mark { font-weight: 800; letter-spacing: 0.04em; }
.brand-text { font-weight: 600; opacity: 0.85; }
.sidebar-collapse {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(243, 239, 228, 0.2);
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.sidebar-collapse svg { width: 16px; height: 16px; }
.sidebar-collapse:hover { background: rgba(255,255,255,0.08); }
.sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    margin-right: -4px;
    scrollbar-width: thin;
    scrollbar-color: #3d5248 transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: #3d5248;
    border-radius: 8px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}
.nav-ico {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nav-ico svg { width: 20px; height: 20px; display: block; }
.sidebar-out button {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}
.shell-main {
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.shell-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 36px 0;
    color: var(--muted);
    font-size: 0.82rem;
}
.shell-top-emp {
    margin: 0;
    font-weight: 600;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 10px;
}
.emp-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    border: 1px solid var(--line);
    flex: 0 0 auto;
}
.emp-logo.is-lg { width: 72px; height: 72px; border-radius: 10px; }
.emp-logo.is-sm { width: 36px; height: 36px; }
.logo-pick {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.logo-pick input[type="file"] { width: auto; max-width: 100%; }
.shell-top-hint { margin: 0; }
.shell-top kbd {
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 0 5px;
    background: #fff;
}

html.sidebar-collapsed body.has-shell { grid-template-columns: 76px 1fr; }
html.sidebar-collapsed .brand-text,
html.sidebar-collapsed .sidebar-user,
html.sidebar-collapsed .sidebar-note,
html.sidebar-collapsed .nav-group,
html.sidebar-collapsed .nav-label,
html.sidebar-collapsed .shell-top-hint { display: none; }
html.sidebar-collapsed .empresa-switch-label {
    font-size: 0;
    letter-spacing: 0;
}
html.sidebar-collapsed .empresa-switch select {
    padding: 8px 4px;
    font-size: 0.7rem;
}
html.sidebar-collapsed .sidebar { padding: 12px 8px; }
html.sidebar-collapsed .sidebar-head { justify-content: center; flex-direction: column; }
html.sidebar-collapsed .brand-text { display: none; }
html.sidebar-collapsed .brand { justify-content: center; width: 100%; }
html.sidebar-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
html.sidebar-collapsed .nav-item,
html.sidebar-collapsed .sidebar-out button {
    justify-content: center;
    padding-left: 8px;
    padding-right: 8px;
}
html.sidebar-collapsed .nav-item { position: relative; }
html.sidebar-collapsed .nav-item:hover::after,
html.sidebar-collapsed .sidebar-out button:hover::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #111;
    color: #fff;
    font-size: 0.78rem;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    z-index: 50;
}

@media (max-width: 880px) {
    html.sidebar-collapsed body.has-shell,
    body.has-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }
    html.sidebar-collapsed .brand-text,
    html.sidebar-collapsed .sidebar-user,
    html.sidebar-collapsed .nav-label,
    html.sidebar-collapsed .nav-group,
    html.sidebar-collapsed .empresa-switch-label { display: unset; }
    html.sidebar-collapsed .nav-item { justify-content: flex-start; }
    .sidebar-collapse { display: none; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 260px;
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        z-index: 30;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
    }
    body.nav-open .sidebar {
        transform: none;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
    }
    .shell-top {
        padding: 12px 16px 0 88px;
    }
    .shell-top-hint { display: none; }
    .shell-main { min-height: 0; }
}

/* Tablas y fichas */
.wide { max-width: 1280px; }
.page-head .lede { margin: 0; }
.filters {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    align-items: center;
}
.filters input,
.filters select {
    min-width: 160px;
    max-width: 100%;
}
.filters input[type="search"] { min-width: 220px; flex: 1; }
.table-wrap table { min-width: 640px; }
.table-wrap td { vertical-align: middle; }
.table-wrap td strong { font-weight: 650; }
.table-wrap form { margin: 0; }
.table-wrap button {
    width: auto;
    margin: 0;
    padding: 6px 12px;
    font-size: 0.82rem;
}

.dt-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin: 0 0 20px;
}
.dt-card .table-wrap {
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
}
.dt-top,
.dt-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px 16px;
    padding: 12px 16px;
    background: #faf7f0;
}
.dt-top { border-bottom: 1px solid var(--line); }
.dt-bottom { border-top: 1px solid var(--line); }
.dt-top label,
.dt-bottom label {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
}
.dt-search input { width: 220px; margin: 0; }
.dt-len select { width: auto; margin: 0; }
.dt-info { color: var(--muted); font-size: 0.88rem; }
.dt-pager { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.dt-pager button {
    width: auto;
    margin: 0;
    padding: 6px 12px;
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    font-size: 0.85rem;
}
.dt-pager button.is-on,
.dt-pager button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.dt-pager button:disabled { opacity: 0.4; cursor: default; background: #fff; color: var(--ink); border-color: var(--line); }

.dt-card thead th {
    position: static;
    background: #fff;
    color: var(--ink);
    font-size: 0.88rem;
    font-weight: 650;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    border-bottom: 2px solid var(--line);
    box-shadow: none;
}
.dt-card tbody tr.dt-odd { background: #fbf8f2; }
.dt-card tbody tr:hover { background: #f4ebe4; }
th.dt-sort { cursor: pointer; user-select: none; padding-right: 22px; position: relative; }
th.dt-sort:hover { color: var(--accent); }
th.dt-sort::after {
    content: "↕";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.28;
    font-size: 0.75rem;
}
th.dt-sort.asc::after,
th.dt-sort.desc::after { opacity: 1; color: var(--accent); }
th.dt-sort.asc::after { content: "▲"; }
th.dt-sort.desc::after { content: "▼"; }

.cell-title {
    color: var(--accent);
    font-weight: 650;
    text-decoration: none;
}
.cell-title:hover { text-decoration: underline; }
.cell-sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}
.cell-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-actions {
    text-align: right;
    white-space: nowrap;
}
.cell-actions .ghost-link {
    padding: 6px 12px;
    font-size: 0.82rem;
}
.cell-actions form { display: inline; margin: 0; }
.cell-actions button { width: auto; margin: 0; }
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 240px;
    padding: 3px 10px 3px 6px;
    border-radius: 999px;
    background: #ece6d8;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.82rem;
    line-height: 1.3;
}
.chip:hover { filter: brightness(0.97); }
.chip-tipo {
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}
.chip-emp { background: #d7e5dc; }
.chip-prov { background: #e7dcc4; }
.chip-cli { background: #f3e6c8; }
.chip-con { background: #f3d9d2; }

/* Formularios */
.form-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px 28px 20px;
    box-shadow: var(--shadow);
    max-width: 860px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 20px;
}
.form-grid .span-2,
.form-grid fieldset { grid-column: 1 / -1; }
.form-grid fieldset .form-grid { margin: 0; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; align-items: center; }
.preset-row button { width: auto; margin: 0; }
.preset-row .preset-manage { margin-left: 4px; }
.perm-table { margin-top: 8px; max-height: none; }
.alcance-opciones { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 12px; }
.page-head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-grid label { margin: 10px 0; }
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}
.form-actions button { width: auto; margin: 0; }
.form-actions form { margin: 0; }
.auth-card .form-actions { display: block; margin-top: 8px; }
.auth-card .form-actions button { width: 100%; }
.vinculo-grupos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 8px;
}
.vinculo-label { margin: 0 0 6px; font-size: 0.82rem; }
.vinculo-box {
    max-height: 180px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 10px;
    background: #fff;
}
.vinculo-box .check { margin: 6px 0; }
fieldset legend { font-weight: 650; padding: 0 6px; }
.props {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 10px 20px;
    margin: 0;
    padding: 20px 24px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}
.props dt {
    margin: 0;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding-top: 4px;
}
.props dd { margin: 0; }
.panel h2 { margin: 28px 0 12px; }

@media (max-width: 880px) {
    .form-grid { grid-template-columns: 1fr; }
    .filters input[type="search"] { min-width: 0; width: 100%; }
    .props { grid-template-columns: 1fr; gap: 4px; }
    .dt-search input { width: 100%; }
}

