:root {
    --sidebar-width: 250px;
    --brand-dark: #101828;
    --brand-primary: #2563eb;
}

body {
    background-color: #f4f6f9;
}

#app-shell {
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background-color: var(--brand-dark);
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover:not(.disabled) {
    background-color: var(--brand-primary);
    color: #fff !important;
}

.sidebar .nav-link.disabled {
    pointer-events: none;
}

/* A sidebar heading that opens and closes its group of links (Administration). */
.sidebar-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: .4rem 1rem;
    border: 0;
    border-radius: .375rem;
    background: transparent;
    color: rgba(255, 255, 255, .5);
    font-size: .875em;
    text-transform: uppercase;
    letter-spacing: .02em;
    text-align: left;
}
.sidebar-group-toggle:hover,
.sidebar-group-toggle:focus-visible { color: #fff; background: rgba(255, 255, 255, .08); }
.sidebar-group-toggle .bi { transition: transform .2s ease; }
.sidebar-group-toggle.collapsed .bi { transform: rotate(-90deg); }
@media (prefers-reduced-motion: reduce) { .sidebar-group-toggle .bi { transition: none; } }

/* Desktop: the sidebar is its own scroll area pinned to the window, so it
   stays where you left it while the page content scrolls (and, with the
   position restore in layouts/app.php, across page loads too). */
@media (min-width: 769px) {
    .sidebar {
        position: sticky;
        top: 0;
        align-self: flex-start;
        height: 100vh;
        overflow-y: auto;
        overscroll-behavior: contain; /* scrolling the menu never scrolls the page */
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
    }
}

/* Lets wide tables scroll inside the content area instead of pushing the page sideways. */
#app-shell > main {
    min-width: 0;
}

.card {
    border: none;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

/* Everything in the sidebar below the logo. On computers it fills the
   sidebar as before; on phones it folds away behind the Menu button. */
.sidebar-body {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.sidebar-menu-toggle { display: none; }

@media (max-width: 768px) {
    #app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
        flex-direction: row !important;
        flex-wrap: wrap;
        align-items: center;
        padding-top: .6rem !important;
        padding-bottom: .6rem !important;
    }
    .sidebar-brand { margin-bottom: 0; }
    .sidebar-logo-card { padding: 5px 9px; }
    .sidebar-logo-card img { height: 32px; }
    .sidebar-logo-word { font-size: 1.05rem; }
    .sidebar-menu-toggle {
        display: inline-flex;
        align-items: center;
        gap: .35rem;
        margin-left: auto;
        padding: .45rem .8rem;
        border: 1px solid rgba(255, 255, 255, .35);
        border-radius: .5rem;
        background: transparent;
        color: #fff;
        font-size: .95rem;
    }
    .sidebar-menu-toggle .bi { font-size: 1.3rem; line-height: 1; }
    .sidebar-menu-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
    .sidebar-body { display: none; width: 100%; }
    .sidebar.menu-open .sidebar-body { display: flex; }
}

/* Dashboard */
.min-w-0 {
    min-width: 0;
}

.kpi-card {
    transition: box-shadow 0.15s ease-in-out;
}

.kpi-card:hover {
    box-shadow: 0 4px 12px rgba(16, 24, 40, 0.12);
}

/* One row per pipeline stage: name | bar | count | value. */
.pipeline-row {
    display: grid;
    grid-template-columns: minmax(110px, 180px) 1fr 40px minmax(90px, 130px);
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.25rem;
    border-radius: 0.375rem;
}

.pipeline-row:hover {
    background-color: #f4f6f9;
}

.pipeline-bar {
    height: 0.75rem;
}

.pipeline-count {
    text-align: right;
}

.pipeline-value {
    text-align: right;
    white-space: nowrap;
}

@media (max-width: 576px) {
    /* Phones: stage name + count on one line, bar and value below. */
    .pipeline-row {
        grid-template-columns: 1fr auto;
        row-gap: 0.25rem;
    }

    .pipeline-bar {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .pipeline-value {
        grid-column: 1 / -1;
        text-align: left;
    }
}

/* Global search (navbar) */
.global-search {
    max-width: 480px;
}

.global-search-icon {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    pointer-events: none;
}

.global-search-results {
    max-height: 70vh;
    overflow-y: auto;
}

.global-search-results .dropdown-item {
    white-space: normal;
}

/* Calendar
 * One accent colour per event type, used for the event's left border and
 * the matching filter toggle. Text stays dark on a light tint for contrast. */
.cal-follow_up { --cal-accent: #d97706; --cal-tint: #fef3c7; }
.cal-task      { --cal-accent: #64748b; --cal-tint: #f1f5f9; }
.cal-demo      { --cal-accent: #2563eb; --cal-tint: #dbeafe; }
.cal-meeting   { --cal-accent: #0891b2; --cal-tint: #cffafe; }
.cal-campaign  { --cal-accent: #16a34a; --cal-tint: #dcfce7; }
.cal-content   { --cal-accent: #7c3aed; --cal-tint: #ede9fe; }
.cal-renewal   { --cal-accent: #dc2626; --cal-tint: #fee2e2; }

.cal-event {
    display: block;
    margin-bottom: 0.2rem;
    padding: 0.15rem 0.4rem;
    border-left: 3px solid var(--cal-accent);
    border-radius: 0.25rem;
    background-color: var(--cal-tint);
    color: #1f2937;
    font-size: 0.8rem;
    text-decoration: none;
}

.cal-event:hover {
    filter: brightness(0.96);
    color: #111827;
}

.cal-event .bi {
    color: var(--cal-accent);
}

.cal-event.cal-muted {
    opacity: 0.55;
    text-decoration: line-through;
}

.cal-filter {
    border: 1px solid var(--cal-accent);
    color: var(--cal-accent);
    background-color: #fff;
}

.btn-check:checked + .cal-filter {
    background-color: var(--cal-accent);
    border-color: var(--cal-accent);
    color: #fff;
}

.btn-check:checked + .cal-filter .bi {
    color: #fff;
}

.cal-month {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-dow {
    padding: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    text-align: center;
}

.cal-cell {
    min-height: 7.5rem;
    padding: 0.25rem;
    border-right: 1px solid #f0f1f3;
    border-bottom: 1px solid #f0f1f3;
    min-width: 0;
}

.cal-cell:nth-child(7n) {
    border-right: none;
}

.cal-outside {
    background-color: #fafafa;
}

.cal-outside .cal-daynum {
    color: #9ca3af;
}

.cal-daynum {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.2rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    font-size: 0.85rem;
    color: #374151;
    text-decoration: none;
}

.cal-today .cal-daynum {
    background-color: var(--brand-primary);
    color: #fff;
    font-weight: 600;
}

.cal-week {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.5rem;
}

.cal-week-day {
    min-height: 12rem;
}

.cal-week-day.cal-today {
    outline: 2px solid var(--brand-primary);
}

@media (max-width: 768px) {
    .cal-cell {
        min-height: 3.25rem;
        text-align: center;
    }

    .cal-daynum {
        flex-direction: column;
        gap: 0;
    }

    /* Week view becomes a list of days on phones. */
    .cal-week {
        grid-template-columns: 1fr;
    }

    .cal-week-day {
        min-height: 0;
    }
}

/* Segment builder: long option lists scroll inside their box. */
.segment-options {
    max-height: 11rem;
    overflow-y: auto;
}

/* Dashboard workspace tabs: scroll sideways on phones instead of wrapping. */
.workspace-tabs .nav-link {
    padding: 0.35rem 0.85rem;
}

/* Built-in user manual (/help) */
.manual-toc {
    position: sticky;
    top: 1rem;
}

.manual-body h2 {
    margin-top: 2.25rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
    font-size: 1.4rem;
    scroll-margin-top: 1rem;
}

.manual-body h2:first-child {
    margin-top: 0;
    border-top: none;
}

.manual-body h3 {
    margin-top: 1.5rem;
    font-size: 1.1rem;
}

.manual-body pre.mermaid {
    background: #fff;
    text-align: center;
    padding: 0.5rem 0;
}

@media print {
    .sidebar, .navbar, .workspace-tabs {
        display: none !important;
    }

    .manual .col-lg-9 {
        width: 100%;
    }

    .manual-body h2 {
        break-before: page;
    }

    .manual-body h2:first-child {
        break-before: auto;
    }
}

/* Sidebar brand: the "M" symbol at the side with the name beside it, on a white card
   (the logo's navy lettering would vanish on the dark sidebar). */
.sidebar-brand { display: block; margin-bottom: .75rem; }
.sidebar-logo-card { display: flex; align-items: center; justify-content: center; gap: 7px; background: #fff; border-radius: 10px; padding: 8px 12px; }
.sidebar-logo-card img { height: 42px; width: auto; flex: 0 0 auto; }
.sidebar-logo-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.sidebar-logo-word { font-size: 1.25rem; font-weight: 900; letter-spacing: .01em; }
.sidebar-logo-word .mis { color: #00256a; }
.sidebar-logo-word .nexus { color: #fe7600; }
.sidebar-logo-sub { margin-top: 2px; color: #00256a; font-size: .62rem; font-weight: 600; white-space: nowrap; }
@media (max-width: 768px) {
    .sidebar-logo-card { display: inline-flex; }
}

/* Sign-in and password pages */
.auth-page { background: radial-gradient(900px 500px at 100% 0%, #e8f1ff, transparent 60%), radial-gradient(700px 400px at 0% 100%, #fff1e5, transparent 60%), #f5f7fb; }
.auth-card { border: 0; border-top: 4px solid #fe7600; border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 37, 106, .12); }
.auth-logo { display: block; width: 140px; max-width: 60%; height: auto; margin: 0 auto .75rem; }
.auth-card .btn-primary { background: #00256a; border-color: #00256a; }
.auth-card .btn-primary:hover, .auth-card .btn-primary:focus { background: #0142a6; border-color: #0142a6; }
.auth-card a { color: #0142a6; }

/* Show/hide password button (assets/js/password-toggle.js): matches the input's border. */
.password-toggle { border-color: var(--bs-border-color); color: #6c757d; background: #fff; }
.password-toggle:hover, .password-toggle:focus { border-color: var(--bs-border-color); background: #f1f4f9; color: #00256a; }
.password-toggle-group .form-control:focus { z-index: 3; }
