/* ============================================
   Shared Sidebar Styles
   Usage: load this file first, then each app's
   brand.css which sets --sidebar-brand-start and
   --sidebar-brand-end to its own palette.
   ============================================ */

/* Default brand colours (green / workorder).
   Override in each app's own CSS:
     :root { --sidebar-brand-start: #1a5f9f; --sidebar-brand-end: #2d78c8; } */
:root {
    --sidebar-brand-start: #1a7f5f;
    --sidebar-brand-end:   #2d8659;
}

html { overflow-y: scroll; }

/* ── Sidebar Container ─────────────────────── */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: all 0.3s ease;
    z-index: 100;
    font-size: 14px !important;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Brand gradient — controlled by per-app CSS variables */
.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--sidebar-brand-start) 0%, var(--sidebar-brand-end) 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px !important;
    color: white;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 18px !important;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* ── Navigation ────────────────────────────── */
.sidebar-nav {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.nav-section { margin-bottom: 1.5rem; }

.nav-section-title {
    font-size: 11px !important;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0 1rem;
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    color: var(--sidebar-text) !important;
    text-decoration: none !important;
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: 14px !important;
}

.sidebar .nav-item,
.sidebar .nav-item:link,
.sidebar .nav-item:visited,
.sidebar .nav-item:focus,
.sidebar .nav-item:active {
    color: var(--sidebar-text) !important;
    text-decoration: none !important;
    outline: none !important;
}

.sidebar .nav-item:hover {
    background: var(--sidebar-active);
    color: var(--sidebar-text) !important;
}

.nav-item.active,
.sidebar .nav-item.active {
    background: var(--primary-color);
    color: white !important;
}

.sidebar .nav-item.active:link,
.sidebar .nav-item.active:visited,
.sidebar .nav-item.active:hover,
.sidebar .nav-item.active:focus,
.sidebar .nav-item.active:active {
    color: white !important;
    text-decoration: none !important;
    outline: none !important;
}

.nav-item i { width: 20px; text-align: center; flex-shrink: 0; }
.nav-item span { white-space: nowrap; }

/* ── Footer ────────────────────────────────── */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar .theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 8px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    font-size: 14px;
}

.sidebar .theme-toggle:hover { background: rgba(255, 255, 255, 0.2); }

/* ── Main Content Offset ───────────────────── */
.main-content,
.main-container {
    margin-left: 260px;
    flex: 1;
    background: var(--bg-primary);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* ── Mobile Toggle Button ──────────────────── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 150;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 18px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover { opacity: 0.9; transform: scale(1.05); }

/* ── Sidebar Overlay ───────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show { opacity: 1; }

/* ── Sidebar Close Button (mobile) ─────────── */
.sidebar-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--sidebar-active);
    color: var(--text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px !important;
    transition: all 0.2s ease;
}

.sidebar-close:hover { background: var(--danger-color); color: white; }

/* ── Responsive Breakpoints ────────────────── */
@media (max-width: 1024px) {
    .sidebar { width: 220px; }
    .main-content, .main-container { margin-left: 220px; }
    .sidebar-header { padding: 1.25rem; }
    .sidebar-title { font-size: 16px !important; }
}

@media (max-width: 768px) {
    .sidebar-toggle { display: flex; }
    .sidebar-overlay { display: block; pointer-events: none; }
    .sidebar-overlay.show { pointer-events: auto; }
    .sidebar { width: 280px; transform: translateX(-100%); box-shadow: none; }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15); }
    .sidebar.open .sidebar-close { display: flex; }
    .main-content, .main-container { margin-left: 0; }
    .top-bar { padding-left: 4.5rem !important; }
    .search-box { width: 100% !important; max-width: 300px; }
}

@media (max-width: 480px) {
    .sidebar { width: 100%; }
    .sidebar-toggle { top: 0.75rem; left: 0.75rem; width: 40px; height: 40px; }
    .top-bar {
        padding: 0.75rem !important;
        padding-left: 4rem !important;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .search-box { max-width: 100%; flex: 1; min-width: 150px; }
    .top-bar-actions { gap: 8px; }
}

@keyframes slideIn  { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slideOut { from { transform: translateX(0); }    to { transform: translateX(-100%); } }

body.sidebar-open { overflow: hidden; }
@media (min-width: 769px) { body.sidebar-open { overflow: auto; } }

/* ============================================
   Top-Bar User Avatar + Profile Dropdown
   Shared by both workorder and invoice apps
   ============================================ */

/* Ensure the sticky top-bar never clips the dropdown */
.top-bar { overflow: visible !important; }

.topbar-user {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color, #1a7f5f);
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    padding: 0;
    flex-shrink: 0;
}

.topbar-avatar:hover,
.topbar-user.active .topbar-avatar {
    border-color: var(--primary-color, #1a7f5f);
    box-shadow: 0 0 0 3px rgba(26, 127, 95, 0.18);
    transform: scale(1.05);
}

.topbar-initials {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
    user-select: none;
    line-height: 1;
}

/* Dropdown panel */
.topbar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 220px;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    z-index: 500;
    overflow: hidden;
    animation: topbarDropdownIn 0.15s ease;
}

.topbar-dropdown.open {
    display: block;
}

@keyframes topbarDropdownIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Dropdown header (avatar + name) */
.topbar-dropdown-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.75rem;
}

.topbar-dropdown-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary-color, #1a7f5f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.topbar-dropdown-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-dropdown-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #212529);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-dropdown-role {
    font-size: 11px;
    color: var(--text-secondary, #6c757d);
    text-transform: capitalize;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Divider */
.topbar-dropdown-divider {
    height: 1px;
    background: var(--border-color, #dee2e6);
    margin: 0;
}

/* Menu items */
.topbar-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.7rem 1rem;
    font-size: 14px;
    color: var(--text-primary, #212529) !important;
    text-decoration: none !important;
    cursor: pointer;
    transition: background 0.15s;
}

.topbar-dropdown-item:hover {
    background: var(--bg-secondary, #f8f9fa);
}

.topbar-dropdown-item i {
    width: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary, #6c757d);
    flex-shrink: 0;
}

.topbar-dropdown-item:hover i {
    color: var(--primary-color, #1a7f5f);
}

.topbar-dropdown-logout {
    color: var(--danger-color, #dc3545) !important;
}

.topbar-dropdown-logout i {
    color: var(--danger-color, #dc3545) !important;
}

.topbar-dropdown-logout:hover {
    background: rgba(220, 53, 69, 0.07) !important;
}

/* Mobile — keep dropdown visible when near edge */
@media (max-width: 480px) {
    .topbar-dropdown {
        right: -8px;
        min-width: 190px;
    }
}
