/* Layout & Global Structures */

body {
    background-color: var(--cci-color-background);
    color: var(--cci-color-text-main);
    font-family: var(--cci-font-family);
}

/* Logged-In Layout */
.cci-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--cci-space-4);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Content links inherit the theme-aware link token. Without this, unclassed
   anchors (e.g. the CI run repo/branch/commit links, auth "Forgot password" /
   "Sign Up") fell back to the UA default blue, which is illegible on the dark
   surface. Buttons and header links set their own colour via higher-specificity
   class rules, so this low-specificity base does not affect them. */
a {
    color: var(--cci-link);
}

.cci-header {
    display: flex;
    justify-content: flex-end;
    padding: var(--cci-space-4) 0;
}

.cci-user {
    display: flex;
    align-items: center;
    gap: var(--cci-space-3);
    background: var(--cci-color-surface);
    padding: var(--cci-space-2) var(--cci-space-4);
    border-radius: var(--cci-radius-pill);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.cci-avatar {
    width: 2rem;
    height: 2rem;
    background-color: var(--cci-color-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.cci-user-email {
    font-size: var(--cci-text-sm);
    font-weight: 500;
}

.cci-backlink {
    font-size: var(--cci-text-sm);
    color: var(--cci-color-text-muted);
    text-decoration: none;
    margin-left: var(--cci-space-2);
}
.cci-backlink:hover {
    color: var(--cci-color-primary);
}

.cci-footer {
    margin-top: auto;
    /* Horizontal padding so the right-aligned text isn't flush against (and
       clipped at) the viewport edge. The footer is a sibling of .cci-main, so
       it doesn't inherit the main content gutter; give it its own. */
    padding: var(--cci-space-6);
    text-align: right;
    font-size: var(--cci-text-xs);
    color: var(--cci-color-text-muted);
}

/* Logged-Out Layout */
.cci-logged-out {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--cci-space-4);
    background-color: var(--cci-color-background);
}

/* Topbar (Common in dashboards) */
.cci-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--cci-space-6);
}

/* ============================================================================
   Navigation shell — persistent left sidebar (M1, CircleCI-style)
   rewrite-docs/06-frontend-ui/navigation-and-projects.md
   All colours/space/radii below come from --cci-* tokens so light + dark and
   the density axis stay in sync. --cci-sidebar-width is a structural layout
   constant (rail width), not a colour/space design token.
   ============================================================================ */

.cci-shell {
    --cci-sidebar-width: 240px;
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--cci-sidebar-width) minmax(0, 1fr);
}

/* ---- The rail ---- */
.cci-sidebar {
    /* Fill the full grid-row height so the rail's surface reaches the bottom of
       the page even when the main content is taller than one viewport, and so
       the footer (avatar + logout) docks at the true bottom of the rail on
       every page — not at the first fold. */
    align-self: stretch;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--cci-color-surface);
    border-right: 1px solid var(--cci-color-border);
}

.cci-sidebar-inner {
    display: flex;
    flex-direction: column;
    /* Fill the whole rail so the footer's margin-top:auto pushes it to the very
       bottom consistently across short and tall pages. */
    flex: 1;
    gap: var(--cci-space-4);
    padding: var(--cci-space-4);
}

/* ---- Org switcher (top) ---- */
.cci-org-switcher {
    position: relative;
    flex-shrink: 0;
}

.cci-org-switcher-summary {
    display: flex;
    align-items: center;
    gap: var(--cci-space-2);
    padding: var(--cci-space-2) var(--cci-space-3);
    border: 1px solid var(--cci-color-border);
    border-radius: var(--cci-radius-md);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.cci-org-switcher-summary::-webkit-details-marker { display: none; }

.cci-org-switcher-summary:hover { background-color: var(--cci-hover); }

.cci-org-switcher-summary:focus-visible {
    outline: 2px solid var(--cci-focus);
    outline-offset: 2px;
}

.cci-org-avatar {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--cci-radius-sm);
    font-size: var(--cci-text-xs);
    flex-shrink: 0;
}

.cci-org-avatar-sm {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--cci-radius-sm);
    background-color: var(--cci-color-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.cci-org-name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
    font-size: var(--cci-text-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cci-org-chevron {
    flex-shrink: 0;
    color: var(--cci-color-text-muted);
    transition: transform 0.15s ease;
}

.cci-org-switcher[open] .cci-org-chevron { transform: rotate(180deg); }

.cci-org-menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + var(--cci-space-1));
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 60vh;
    overflow-y: auto;
    padding: var(--cci-space-1);
    background-color: var(--cci-color-surface);
    border: 1px solid var(--cci-color-border);
    border-radius: var(--cci-radius-md);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.cci-org-menu-item {
    display: flex;
    align-items: center;
    gap: var(--cci-space-2);
    padding: var(--cci-space-2);
    border-radius: var(--cci-radius-sm);
    text-decoration: none;
    color: var(--cci-color-text-main);
    font-size: var(--cci-text-sm);
}

.cci-org-menu-item:hover { background-color: var(--cci-hover); }

.cci-org-menu-item:focus-visible {
    outline: 2px solid var(--cci-focus);
    outline-offset: -2px;
}

.cci-org-menu-item-current { background-color: var(--cci-select); }

.cci-org-menu-item-name {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cci-org-menu-check {
    flex-shrink: 0;
    color: var(--cci-color-primary);
}

.cci-org-menu-divider {
    height: 1px;
    margin: var(--cci-space-1) 0;
    background-color: var(--cci-color-border);
}

.cci-org-menu-create {
    color: var(--cci-color-primary);
    font-weight: 600;
}

.cci-org-menu-plus {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--cci-color-border);
    border-radius: var(--cci-radius-sm);
    font-size: var(--cci-text-base);
    flex-shrink: 0;
}

.cci-org-menu-empty {
    padding: var(--cci-space-2);
    color: var(--cci-color-text-muted);
    font-size: var(--cci-text-sm);
}

/* ---- Primary nav ---- */
.cci-nav {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cci-nav-item {
    display: flex;
    align-items: center;
    gap: var(--cci-space-3);
    padding: var(--cci-space-2) var(--cci-space-3);
    border-radius: var(--cci-radius-md);
    text-decoration: none;
    color: var(--cci-color-text-main);
    font-size: var(--cci-text-sm);
    font-weight: 500;
}

.cci-nav-item:hover { background-color: var(--cci-hover); }

.cci-nav-item:focus-visible {
    outline: 2px solid var(--cci-focus);
    outline-offset: 2px;
}

.cci-nav-icon {
    flex-shrink: 0;
    color: var(--cci-color-text-muted);
}

.cci-nav-item-active {
    background-color: var(--cci-select);
    /* Active label must read on the tinted select bg; the pale light primary
       (#a5b4fc) is too low-contrast as text, so use the main text token. The
       --cci-select fill + bold weight already signal the active state. */
    color: var(--cci-color-text-main);
    font-weight: 600;
}

.cci-nav-item-active .cci-nav-icon { color: var(--cci-color-primary); }

/* ---- User badge + logout (bottom) ---- */
.cci-sidebar-footer {
    margin-top: auto;
    padding-top: var(--cci-space-3);
    border-top: 1px solid var(--cci-color-border);
    display: flex;
    flex-direction: column;
    gap: var(--cci-space-2);
}

.cci-sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--cci-space-2);
    min-width: 0;
    padding: var(--cci-space-1) var(--cci-space-3);
}

.cci-sidebar-user .cci-avatar { flex-shrink: 0; }

.cci-sidebar-user-email {
    min-width: 0;
    font-size: var(--cci-text-sm);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cci-sidebar-logout {
    display: flex;
    align-items: center;
    gap: var(--cci-space-3);
    padding: var(--cci-space-2) var(--cci-space-3);
    border-radius: var(--cci-radius-md);
    text-decoration: none;
    color: var(--cci-color-text-muted);
    font-size: var(--cci-text-sm);
    font-weight: 500;
}

.cci-sidebar-logout:hover {
    background-color: var(--cci-hover);
    color: var(--cci-color-text-main);
}

.cci-sidebar-logout:focus-visible {
    outline: 2px solid var(--cci-focus);
    outline-offset: 2px;
}

.cci-sidebar-logout svg {
    flex-shrink: 0;
    color: var(--cci-color-text-muted);
}

/* ---- Main content column ---- */
.cci-main-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

.cci-main {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1200px;
    padding: var(--cci-space-6);
}

/* ---- Breadcrumbs (top of content) ---- */
.cci-breadcrumbs { margin-bottom: var(--cci-space-6); }

.cci-breadcrumbs ol {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--cci-space-2);
}

.cci-breadcrumbs li {
    display: flex;
    align-items: center;
    gap: var(--cci-space-2);
    font-size: var(--cci-text-sm);
}

.cci-breadcrumbs li + li::before {
    content: "\25B8"; /* ▸ */
    color: var(--cci-color-text-muted);
}

.cci-breadcrumbs a {
    color: var(--cci-color-text-muted);
    text-decoration: none;
}

.cci-breadcrumbs a:hover {
    color: var(--cci-color-primary);
    text-decoration: underline;
}

.cci-breadcrumbs [aria-current="page"] {
    color: var(--cci-color-text-main);
    font-weight: 600;
}

/* ---- Mobile top bar + off-canvas drawer (narrow viewports) ---- */
.cci-mobile-topbar { display: none; }
.cci-sidebar-backdrop { display: none; }

@media (max-width: 1024px) {
    .cci-shell { grid-template-columns: minmax(0, 1fr); }

    .cci-mobile-topbar {
        display: flex;
        align-items: center;
        gap: var(--cci-space-3);
        padding: var(--cci-space-3) var(--cci-space-4);
        background-color: var(--cci-color-surface);
        border-bottom: 1px solid var(--cci-color-border);
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .cci-mobile-title {
        font-weight: 700;
        font-size: var(--cci-text-base);
    }

    .cci-drawer-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.5rem;
        height: 2.5rem;
        border: 1px solid var(--cci-color-border);
        border-radius: var(--cci-radius-md);
        background: transparent;
        color: var(--cci-color-text-main);
        cursor: pointer;
    }

    .cci-drawer-toggle:focus-visible {
        outline: 2px solid var(--cci-focus);
        outline-offset: 2px;
    }

    .cci-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(300px, 85vw);
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 60;
        /* No shadow while closed — a blurred shadow bleeds past the off-canvas
           edge and shows as a sliver at the viewport's left. Only when open. */
        box-shadow: none;
    }

    body.cci-drawer-open .cci-sidebar {
        transform: translateX(0);
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    }

    body.cci-drawer-open .cci-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(0, 0, 0, 0.45);
    }
}

/* ---- Content padding on narrow viewports ---- */
/* The wide-screen --cci-space-6 gutter eats too much of a phone/tablet width;
   tighten it so cards and tables get more room and don't overflow the viewport.
   Additive: only applies ≤768px, leaving laptop/wide untouched. */
@media (max-width: 768px) {
    .cci-main {
        padding: var(--cci-space-4);
    }
}

@media (max-width: 480px) {
    .cci-main {
        padding: var(--cci-space-3);
    }
}
