/* ==========================================
   SAWZA Sidebar — same visual language as Dashboard
   Tokens: --dash-* from sawza-theme.css :root
   ========================================== */

.sidebar {
    --nav-accent: var(--dash-blue);
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100svh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    color: var(--text-primary);
    background:
        radial-gradient(420px 280px at 100% 0%, rgba(59, 130, 246, 0.16), transparent 62%),
        radial-gradient(320px 240px at 0% 100%, rgba(139, 92, 246, 0.1), transparent 58%),
        linear-gradient(180deg, #07101e 0%, var(--dash-navy-1) 46%, var(--dash-navy-0) 100%);
    border-left: 1px solid var(--dash-line);
    box-shadow:
        -18px 0 48px rgba(2, 6, 23, 0.45),
        inset 1px 0 0 rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    transition: width var(--dash-ease), transform var(--dash-ease);
}

.sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(180deg, #000 0%, transparent 78%);
    opacity: 0.7;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header,
.sidebar-menu,
.sidebar-footer {
    position: relative;
    z-index: 1;
}

/* ---------- Brand ---------- */

.sidebar-header {
    flex-shrink: 0;
    padding: 0.95rem 0.9rem 0.85rem;
    border-bottom: 1px solid var(--dash-line);
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.1), transparent 70%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
    text-decoration: none;
    color: #f8fafc;
    border-radius: 16px;
    padding: 0.15rem;
    position: relative;
    transition: background var(--dash-ease), transform var(--dash-ease);
}

.sidebar-brand:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.85);
    outline-offset: 2px;
}

.sidebar-brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #dbeafe;
    background: linear-gradient(160deg, rgba(59, 130, 246, 0.38), rgba(15, 23, 42, 0.45) 62%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        0 8px 22px rgba(37, 99, 235, 0.18);
}

.sidebar-brand-mark svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.sidebar-brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sidebar-brand-copy strong {
    display: block;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: 0;
    background: linear-gradient(180deg, #f8fafc 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-brand-copy small {
    color: #94a3b8;
    font-size: 0.68rem;
    line-height: 1.4;
    font-weight: 500;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
}

.sidebar.collapsed .sidebar-brand-copy,
.sidebar.collapsed .sidebar-item span,
.sidebar.collapsed .sidebar-group-label span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* ---------- Menu ---------- */

.sidebar-menu {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.7rem 0.65rem 0.85rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.35) transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.35);
    border-radius: 99px;
}

.sidebar-group {
    margin-bottom: 0.55rem;
}

.sidebar-group:not(:has(.sidebar-item)) {
    display: none;
}

.sidebar-group-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0.15rem 0.45rem 0.4rem;
    color: #64748b;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.sidebar-group-label::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--dash-line);
}

.sidebar.collapsed .sidebar-group-label {
    margin: 0.45rem 0.7rem;
    min-height: 1px;
}

.sidebar.collapsed .sidebar-group-label::after {
    flex: 1;
}

.sidebar-item {
    --nav-accent: var(--dash-blue);
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 44px;
    margin: 0.12rem 0;
    padding: 0.45rem 0.7rem;
    border-radius: 12px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
    border: 1px solid transparent;
    background: transparent;
    transition:
        background var(--dash-ease),
        border-color var(--dash-ease),
        color var(--dash-ease),
        transform var(--dash-ease),
        box-shadow var(--dash-ease);
}

.sidebar-item span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-item svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    stroke: currentColor;
    stroke-width: 1.75;
    transition: transform var(--dash-ease), filter var(--dash-ease), color var(--dash-ease);
}

.sidebar-item.is-primary {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.2), rgba(15, 23, 42, 0.2));
    border-color: rgba(59, 130, 246, 0.22);
    color: #dbeafe;
}

.sidebar-group[data-tone="catalog"] .sidebar-item { --nav-accent: var(--dash-purple); }
.sidebar-group[data-tone="finance"] .sidebar-item { --nav-accent: var(--dash-amber); }
.sidebar-group[data-tone="reports"] .sidebar-item { --nav-accent: var(--dash-green); }
.sidebar-group[data-tone="admin"] .sidebar-item { --nav-accent: var(--dash-purple); }

.sidebar.collapsed .sidebar-item {
    justify-content: center;
    padding: 0.55rem 0.4rem;
    gap: 0;
}

.sidebar-item.active {
    color: #fff;
    background:
        linear-gradient(90deg, rgba(59, 130, 246, 0.22), rgba(15, 23, 42, 0.2) 72%);
    border-color: color-mix(in srgb, var(--nav-accent) 38%, transparent);
    box-shadow:
        inset -2px 0 0 var(--nav-accent),
        0 8px 22px rgba(2, 6, 23, 0.28);
}

.sidebar-item.active::before {
    content: "";
    position: absolute;
    top: 8px;
    bottom: 8px;
    right: 0;
    width: 3px;
    border-radius: 99px 0 0 99px;
    background: var(--nav-accent);
    box-shadow: 0 0 12px color-mix(in srgb, var(--nav-accent) 70%, transparent);
}

.sidebar-group[data-tone="sale"] .sidebar-item.active,
.sidebar-item.is-primary.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.32), rgba(15, 23, 42, 0.25));
}

.sidebar-item:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.85);
    outline-offset: 2px;
}

@media (hover: hover) {
    .sidebar-brand:hover {
        background: rgba(148, 163, 184, 0.06);
    }

    .sidebar-item:hover {
        color: #fff;
        background: rgba(148, 163, 184, 0.08);
        border-color: rgba(148, 163, 184, 0.12);
        transform: translateX(-2px);
    }

    .sidebar-item:hover svg {
        transform: translateX(-1px) scale(1.06);
        filter: drop-shadow(0 0 8px color-mix(in srgb, var(--nav-accent) 55%, transparent));
        color: var(--nav-accent);
    }

    .sidebar.collapsed .sidebar-item:hover {
        transform: none;
        background: rgba(59, 130, 246, 0.14);
    }

    .sidebar.collapsed .sidebar-item[title]:hover::after,
    .sidebar.collapsed .sidebar-brand[title]:hover::after {
        content: attr(title);
        position: absolute;
        top: 50%;
        right: calc(100% + 10px);
        transform: translateY(-50%);
        padding: 0.38rem 0.7rem;
        border-radius: 10px;
        background: rgba(15, 23, 42, 0.92);
        color: #f1f5f9;
        border: 1px solid var(--dash-line);
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
        font-size: 0.78rem;
        font-weight: 600;
        white-space: nowrap;
        pointer-events: none;
        z-index: 20;
    }
}

/* ---------- Footer / identity ---------- */

.sidebar-footer {
    flex-shrink: 0;
    padding: 0.75rem 0.7rem 0.85rem;
    border-top: 1px solid var(--dash-line);
    background: linear-gradient(0deg, rgba(2, 6, 23, 0.55), transparent);
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--dash-line);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #bfdbfe;
    background: linear-gradient(160deg, rgba(59, 130, 246, 0.28), rgba(15, 23, 42, 0.5));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.user-avatar svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.user-details {
    min-width: 0;
    flex: 1;
}

.user-name {
    color: #f1f5f9;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1.3;
    margin-bottom: 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout,
.sidebar-login {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    min-height: 36px;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(244, 63, 94, 0.28);
    background: rgba(244, 63, 94, 0.12);
    color: #fecdd3;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--dash-ease), background var(--dash-ease);
}

.sidebar-login {
    border-color: rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.16);
    color: #dbeafe;
}

.sidebar-logout svg,
.sidebar-login svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
}

.sidebar-auth-links {
    padding: 0.15rem;
}

@media (hover: hover) {
    .sidebar-logout:hover,
    .sidebar-login:hover {
        transform: translateY(-1px);
    }
}

.sidebar-logout:focus-visible,
.sidebar-login:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.85);
    outline-offset: 2px;
}

.sidebar.collapsed .sidebar-user-info {
    flex-direction: column;
    padding: 0.4rem;
    gap: 0.4rem;
}

.sidebar.collapsed .user-details {
    width: auto;
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
}

.sidebar.collapsed .user-name,
.sidebar.collapsed .sidebar-logout span,
.sidebar.collapsed .sidebar-login span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.sidebar.collapsed .sidebar-logout,
.sidebar.collapsed .sidebar-login {
    width: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 12px;
}

/* ---------- Toggle ---------- */

.sidebar-toggle {
    position: fixed;
    right: calc(var(--sidebar-width) - 18px);
    top: 1rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 12px;
    color: #dbeafe;
    cursor: pointer;
    z-index: 1001;
    background: linear-gradient(160deg, rgba(59, 130, 246, 0.45), rgba(15, 23, 42, 0.92));
    box-shadow: 0 8px 24px rgba(2, 6, 23, 0.35);
    transition: right var(--dash-ease), transform var(--dash-ease), box-shadow var(--dash-ease);
}

.sidebar-toggle svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

.sidebar-toggle.is-collapsed {
    right: calc(var(--sidebar-collapsed-width) - 18px);
}

@media (hover: hover) {
    .sidebar-toggle:hover {
        transform: translateY(-1px) scale(1.04);
        box-shadow: 0 10px 28px rgba(37, 99, 235, 0.28);
    }
}

.sidebar-toggle:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.85);
    outline-offset: 3px;
}

/* Overlay polish — behavior unchanged */
.sidebar-overlay {
    background: rgba(2, 6, 23, 0.62);
    backdrop-filter: blur(6px);
}

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-item,
    .sidebar-toggle,
    .sidebar-brand,
    .sidebar-logout,
    .sidebar-login,
    .main-content {
        transition: none !important;
        animation: none !important;
        transform: none !important;
    }
}

@media (max-width: 1280px) {
    .sidebar-item {
        font-size: 0.84rem;
        min-height: 42px;
    }
}

@media (max-width: 768px) {
    .sidebar-item {
        min-height: 46px;
    }
}

@media (max-width: 1400px) and (hover: none) {
    body.pos-page .sidebar-item {
        min-height: 48px;
    }

    body.pos-page .sidebar-toggle,
    body.pos-page .sidebar-toggle.is-collapsed {
        border-radius: 14px;
    }
}
