/* ============================================
   PATRIOT TECH SYSTEMS - BASE LAYOUT
   Sidebar, Topbar, Main Content Grid
   ============================================ */

/* ---- RESET & GLOBALS ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--pt-text-base);
    font-weight: var(--pt-font-normal);
    line-height: var(--pt-leading-normal);
    background: var(--pt-bg-app);
    color: var(--pt-text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--pt-scrollbar-track);
}
::-webkit-scrollbar-thumb {
    background: var(--pt-scrollbar-thumb);
    border-radius: var(--pt-radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--pt-text-muted);
}

/* Focus ring for accessibility */
:focus-visible {
    outline: 2px solid var(--pt-border-focus);
    outline-offset: 2px;
}

a {
    color: var(--pt-interactive-primary);
    text-decoration: none;
}
a:hover {
    color: var(--pt-interactive-primary-hover);
}

/* Skip to main content (accessibility) */
.pt-skip-link {
    position: absolute;
    top: -100%;
    left: var(--pt-space-4);
    padding: var(--pt-space-2) var(--pt-space-4);
    background: var(--pt-interactive-primary);
    color: var(--pt-color-white);
    border-radius: var(--pt-radius-md);
    z-index: var(--pt-z-command);
    font-weight: var(--pt-font-semibold);
    font-size: var(--pt-text-base);
    transition: top var(--pt-transition-fast);
}
.pt-skip-link:focus {
    top: var(--pt-space-4);
    color: var(--pt-color-white);
}

/* ---- LAYOUT SHELL ---- */
.pt-app {
    display: flex;
    min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.pt-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--pt-sidebar-width);
    height: 100vh;
    background: var(--pt-sidebar-bg);
    border-right: 1px solid var(--pt-sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: var(--pt-z-sidebar);
    transition: width var(--pt-transition-slow);
    overflow: hidden;
}

.pt-sidebar.collapsed {
    width: var(--pt-sidebar-collapsed-width);
}

/* Sidebar header / brand */
.pt-sidebar-header {
    padding: var(--pt-space-5);
    border-bottom: 1px solid var(--pt-border-default);
    display: flex;
    align-items: center;
    gap: var(--pt-space-3);
    min-height: var(--pt-topbar-height);
    flex-shrink: 0;
}

.pt-sidebar-logo {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.pt-sidebar-brand {
    display: flex;
    flex-direction: column;
    line-height: var(--pt-leading-tight);
    overflow: hidden;
    white-space: nowrap;
    transition: opacity var(--pt-transition-slow);
}

.pt-sidebar.collapsed .pt-sidebar-brand {
    opacity: 0;
    width: 0;
}

.pt-sidebar-brand-name {
    font-weight: var(--pt-font-bold);
    font-size: 0.95rem;
    color: var(--pt-text-primary);
}

.pt-sidebar-brand-sub {
    font-size: var(--pt-text-sm);
    color: var(--pt-interactive-accent);
    font-weight: var(--pt-font-semibold);
    letter-spacing: 1px;
}

/* Sidebar navigation */
.pt-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--pt-space-3) 0;
}

.pt-nav-section-label {
    font-size: var(--pt-text-xs);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--pt-text-muted);
    padding: var(--pt-space-4) var(--pt-space-5) var(--pt-space-2);
    font-weight: var(--pt-font-semibold);
    transition: opacity var(--pt-transition-slow);
}

.pt-sidebar.collapsed .pt-nav-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
    overflow: hidden;
}

.pt-nav-item {
    padding: 0 var(--pt-space-3);
    margin-bottom: 2px;
}

.pt-nav-link {
    display: flex;
    align-items: center;
    gap: var(--pt-space-3);
    padding: 0.6rem var(--pt-space-3);
    border-radius: var(--pt-radius-md);
    color: var(--pt-text-secondary);
    text-decoration: none;
    font-size: var(--pt-text-base);
    font-weight: var(--pt-font-medium);
    transition: all var(--pt-transition-normal);
    position: relative;
}

.pt-nav-link:hover {
    background: var(--pt-bg-surface);
    color: var(--pt-text-primary);
}

.pt-nav-link.active {
    background: rgba(201, 168, 76, 0.12);
    color: var(--pt-color-gold-300);
}

.pt-nav-link.active i {
    color: var(--pt-interactive-accent);
}

.pt-nav-link i {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.pt-nav-link-text {
    overflow: hidden;
    white-space: nowrap;
    transition: opacity var(--pt-transition-slow);
}

.pt-sidebar.collapsed .pt-nav-link-text {
    opacity: 0;
    width: 0;
}

.pt-nav-badge {
    margin-left: auto;
    font-size: var(--pt-badge-font-size);
    padding: var(--pt-badge-padding);
    border-radius: var(--pt-badge-radius);
    font-weight: var(--pt-font-semibold);
    line-height: 1;
}

.pt-nav-badge.primary { background: rgba(58, 123, 213, 0.2); color: var(--pt-color-blue-300); }
.pt-nav-badge.accent  { background: rgba(201, 168, 76, 0.2); color: var(--pt-color-gold-300); }
.pt-nav-badge.success  { background: var(--pt-status-success-bg); color: var(--pt-color-green-400); }
.pt-nav-badge.warning  { background: var(--pt-status-warning-bg); color: var(--pt-color-yellow-400); }
.pt-nav-badge.danger   { background: var(--pt-status-danger-bg); color: var(--pt-color-red-400); }

.pt-sidebar.collapsed .pt-nav-badge {
    display: none;
}

/* Sidebar collapse toggle */
.pt-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--pt-border-default);
    border-radius: var(--pt-radius-sm);
    background: var(--pt-bg-surface);
    color: var(--pt-text-muted);
    cursor: pointer;
    transition: all var(--pt-transition-normal);
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    z-index: calc(var(--pt-z-sidebar) + 1);
    font-size: 0.75rem;
}

.pt-sidebar-toggle:hover {
    background: var(--pt-bg-surface-hover);
    color: var(--pt-text-primary);
    border-color: var(--pt-border-accent);
}

/* Sidebar footer */
.pt-sidebar-footer {
    padding: var(--pt-space-4) var(--pt-space-5);
    border-top: 1px solid var(--pt-border-default);
    flex-shrink: 0;
}

.pt-sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--pt-space-3);
}

.pt-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--pt-radius-md);
    background: var(--pt-gradient-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--pt-font-semibold);
    font-size: 0.85rem;
    color: var(--pt-color-navy-700);
    flex-shrink: 0;
}

.pt-user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    transition: opacity var(--pt-transition-slow);
}

.pt-sidebar.collapsed .pt-user-info {
    opacity: 0;
    width: 0;
}

.pt-user-name {
    font-weight: var(--pt-font-semibold);
    font-size: 0.85rem;
    color: var(--pt-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pt-user-role {
    font-size: var(--pt-text-sm);
    color: var(--pt-text-muted);
}

/* Product switcher trigger */
.pt-product-switcher-trigger {
    display: flex;
    align-items: center;
    gap: var(--pt-space-2);
    padding: var(--pt-space-2) var(--pt-space-3);
    margin: 0 var(--pt-space-3);
    border: 1px dashed var(--pt-border-accent);
    border-radius: var(--pt-radius-md);
    color: var(--pt-text-muted);
    cursor: pointer;
    font-size: var(--pt-text-sm);
    transition: all var(--pt-transition-normal);
    background: transparent;
    width: calc(100% - var(--pt-space-6));
}

.pt-product-switcher-trigger:hover {
    background: var(--pt-bg-surface);
    color: var(--pt-interactive-accent);
    border-color: var(--pt-interactive-accent);
}

.pt-sidebar.collapsed .pt-product-switcher-trigger span {
    display: none;
}


/* ---- MAIN CONTENT ---- */
.pt-main {
    margin-left: var(--pt-sidebar-width);
    min-height: 100vh;
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--pt-transition-slow);
}

.pt-sidebar.collapsed ~ .pt-main {
    margin-left: var(--pt-sidebar-collapsed-width);
}

/* ---- TOP BAR ---- */
.pt-topbar {
    position: sticky;
    top: 0;
    z-index: var(--pt-z-sticky);
    background: color-mix(in srgb, var(--pt-bg-app) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--pt-border-default);
    padding: 0 var(--pt-space-8);
    height: var(--pt-topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pt-topbar-left {
    display: flex;
    align-items: center;
    gap: var(--pt-space-4);
}

.pt-topbar-right {
    display: flex;
    align-items: center;
    gap: var(--pt-space-3);
}

.pt-page-title {
    font-size: var(--pt-text-xl);
    font-weight: var(--pt-font-bold);
    color: var(--pt-text-primary);
}

.pt-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--pt-space-2);
    font-size: 0.8rem;
    color: var(--pt-text-muted);
    list-style: none;
}

.pt-breadcrumb li + li::before {
    content: "/";
    margin-right: var(--pt-space-2);
    color: var(--pt-text-muted);
    opacity: 0.5;
}

.pt-breadcrumb a {
    color: var(--pt-text-muted);
    text-decoration: none;
}

.pt-breadcrumb a:hover {
    color: var(--pt-interactive-primary);
}

.pt-breadcrumb .active {
    color: var(--pt-text-secondary);
}

/* Search box */
.pt-search-box {
    display: flex;
    align-items: center;
    gap: var(--pt-space-2);
    background: var(--pt-bg-surface);
    border: 1px solid var(--pt-border-default);
    border-radius: var(--pt-radius-md);
    padding: var(--pt-space-2) var(--pt-space-3);
    cursor: pointer;
    transition: all var(--pt-transition-normal);
}

.pt-search-box:hover {
    border-color: var(--pt-border-accent);
    background: var(--pt-bg-surface-hover);
}

.pt-search-box span {
    font-size: 0.85rem;
    color: var(--pt-text-muted);
}

.pt-search-box kbd {
    font-size: var(--pt-text-sm);
    background: rgba(255,255,255,0.08);
    padding: 0.15rem 0.4rem;
    border-radius: var(--pt-radius-sm);
    color: var(--pt-text-muted);
    border: 1px solid var(--pt-border-default);
    font-family: inherit;
}

/* Icon button (notification bell, settings, etc.) */
.pt-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--pt-radius-md);
    border: 1px solid var(--pt-border-default);
    background: var(--pt-bg-surface);
    color: var(--pt-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--pt-transition-normal);
    font-size: 1rem;
    position: relative;
}

.pt-icon-btn:hover {
    background: var(--pt-bg-surface-hover);
    color: var(--pt-text-primary);
    border-color: var(--pt-border-accent);
}

.pt-icon-btn .pt-badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pt-status-danger);
    border: 2px solid var(--pt-bg-app);
}

/* ---- PAGE CONTENT ---- */
.pt-content {
    flex: 1;
    padding: var(--pt-space-6) var(--pt-space-8) var(--pt-space-8);
}

/* Organization selector bar */
.pt-org-bar {
    background: var(--pt-card-bg);
    border: 1px solid var(--pt-card-border);
    border-radius: var(--pt-card-radius);
    padding: var(--pt-space-4) var(--pt-space-5);
    margin-bottom: var(--pt-space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--pt-space-4);
}

/* Section headers */
.pt-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--pt-space-4);
}

.pt-section-title {
    font-size: var(--pt-text-md);
    font-weight: var(--pt-font-semibold);
    color: var(--pt-text-primary);
}


/* ---- MOBILE RESPONSIVE ---- */
.pt-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--pt-bg-overlay);
    z-index: calc(var(--pt-z-sidebar) - 1);
}

.pt-mobile-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--pt-radius-md);
    border: 1px solid var(--pt-border-default);
    background: var(--pt-bg-surface);
    color: var(--pt-text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
}

@media (max-width: 991.98px) {
    .pt-sidebar {
        transform: translateX(-100%);
        width: var(--pt-sidebar-width);
    }

    .pt-sidebar.mobile-open {
        transform: translateX(0);
    }

    .pt-sidebar.mobile-open + .pt-sidebar-overlay {
        display: block;
    }

    .pt-sidebar.collapsed {
        width: var(--pt-sidebar-width);
    }

    .pt-main {
        margin-left: 0;
    }

    .pt-sidebar.collapsed ~ .pt-main {
        margin-left: 0;
    }

    .pt-mobile-toggle {
        display: flex;
    }

    .pt-sidebar-toggle {
        display: none;
    }

    .pt-content {
        padding: var(--pt-space-4) var(--pt-space-4) var(--pt-space-6);
    }

    .pt-topbar {
        padding: 0 var(--pt-space-4);
    }
}

@media (max-width: 575.98px) {
    .pt-search-box span,
    .pt-search-box kbd {
        display: none;
    }

    .pt-search-box {
        padding: var(--pt-space-2);
    }

    .pt-page-title {
        font-size: var(--pt-text-md);
    }
}
