/* ─── Capture-phase details (project detail page) ─────────
   Each phase is a <details> block; hide the default disclosure
   marker so the custom chevron + counts in the summary line is the
   only visual affordance. Chevron rotates when the block is open. */
.capture-phase summary { list-style: none; }
.capture-phase summary::-webkit-details-marker { display: none; }
.capture-phase summary .chev { transition: transform 0.15s ease; }
.capture-phase[open] summary .chev { transform: rotate(180deg); }

/* ─── Chat: inline-editable conversation title ───────────────
   Default reads as label-like text; hovering reveals it's editable
   via a dashed underline + softened background. On focus the input
   gets a real border so the user sees the active edit state. */
.chat-title-input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    padding: 0.15rem 0.4rem;
    transition: background-color 0.12s, border-color 0.12s;
}
.chat-title-input:hover {
    background: #f9fafb;
    border-bottom: 1px dashed #d1d5db;
    cursor: text;
}
.chat-title-input:focus {
    outline: none;
    background: white;
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

/* ─── Chat: markdown-rendered assistant replies ─────────────
   Tailwind's preflight strips headings + list bullets globally, so
   markdown coming out of marked needs its own typography styles
   scoped to the chat bubble (.chat-md). Keeps things tight — this
   is for short conversational replies, not long-form prose. */
.chat-md > *:first-child { margin-top: 0; }
.chat-md > *:last-child  { margin-bottom: 0; }
.chat-md p  { margin: 0 0 0.5em; line-height: 1.5; }
.chat-md h1 { font-size: 1.05rem; font-weight: 600; margin: 0.4em 0 0.3em; }
.chat-md h2 { font-size: 1.0rem;  font-weight: 600; margin: 0.4em 0 0.3em; }
.chat-md h3,
.chat-md h4 { font-size: 0.925rem; font-weight: 600; margin: 0.4em 0 0.3em; }
.chat-md ul,
.chat-md ol { margin: 0.25em 0 0.5em 1.25em; }
.chat-md ul { list-style: disc; }
.chat-md ol { list-style: decimal; }
.chat-md li { margin: 0.15em 0; }
.chat-md strong { font-weight: 600; }
.chat-md em { font-style: italic; }
.chat-md code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background-color: rgba(0,0,0,0.06);
    padding: 0.05em 0.3em;
    border-radius: 0.25em;
    font-size: 0.875em;
}
.chat-md pre {
    background-color: rgba(0,0,0,0.06);
    padding: 0.5em 0.75em;
    border-radius: 0.4em;
    overflow-x: auto;
    margin: 0.4em 0;
}
.chat-md pre code { background: none; padding: 0; }
.chat-md blockquote {
    border-left: 3px solid #d1d5db;
    padding-left: 0.6em;
    margin: 0.4em 0;
    color: #4b5563;
}
.chat-md a { color: #4f46e5; text-decoration: underline; }
.chat-md table {
    border-collapse: collapse;
    margin: 0.4em 0;
    font-size: 0.875em;
}
.chat-md th, .chat-md td {
    border: 1px solid #e5e7eb;
    padding: 0.25em 0.5em;
    text-align: left;
}
.chat-md th { background-color: rgba(0,0,0,0.04); font-weight: 600; }
.chat-md hr { border: 0; border-top: 1px solid #e5e7eb; margin: 0.6em 0; }

/* ─── Documents & Reference tabs ───────────────────────────── */
.docref-tab {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    background: transparent;
    white-space: nowrap;
}
.docref-tab:hover { color: #4f46e5; }
.docref-tab.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
}

/* ─── Stakeholder Map chart container ─────────────────────── */
/* Phone default is 380px (set inline); md+ bumps to 520px. Inline
   default + media-query override is robust against the Tailwind CDN
   JIT missing arbitrary-value classes that get injected after page
   load. */
@media (min-width: 768px) {
    #stakeholder-chart-container { height: 520px !important; }
}

/* ─── Sidebar ─────────────────────────────────────────────── */
/* Body is the page scroller (see templates/index.html). Sidebar uses
   position: sticky at md+ so it stays anchored to the viewport while
   the body scrolls — required for iOS status-bar tap-to-scroll-top to
   reach the actual page content. On phones the sidebar becomes an
   off-canvas drawer (see the @media block below). */
.sidebar {
    width: 220px;
    transition: width 0.2s ease;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

/* Collapse-to-icon-only is a desktop-only state. Scoped to md+ so the
   side-effects (narrow padding, auto-expanded user menu, hidden labels)
   don't leak into the mobile drawer when the user rotates from landscape
   (where they collapsed) back to portrait. */
@media (min-width: 768px) {
    .sidebar.collapsed {
        width: 60px;
    }

    .sidebar.collapsed .sidebar-full-only {
        display: none;
    }

    .sidebar.collapsed .sidebar-icon-only {
        display: flex !important;
    }

    /* Shrink horizontal padding so the brand mark and the expand
       chevron both fit comfortably at 60px sidebar width. */
    .sidebar.collapsed > div:first-child {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* ─── Navigation links ───────────────────────────────────── */
.nav-link.active {
    color: #4f46e5;
    background-color: #eef2ff;
    font-weight: 600;
}

/* Dashboard row wraps nav-link + chevron button; highlight the whole row */
#dashboard-nav-row:has(.nav-link.active) {
    background-color: #eef2ff;
    border-radius: 0.375rem;
}
#dashboard-nav-row .nav-link.active {
    background: none;
}

.subnav-link.active {
    color: #4f46e5;
    background-color: #eef2ff;
    font-weight: 600;
}

/* ─── Slide-over ─────────────────────────────────────────── */
#slideover-panel {
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

#slideover-overlay.open #slideover-panel {
    transform: translateX(0);
}

/* ─── Toast notifications ────────────────────────────────── */
.toast {
    animation: slideIn 0.3s ease-out, fadeOut 0.3s ease-in 3.7s forwards;
}

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

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ─── Status dots ────────────────────────────────────────── */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.red    { background-color: #ef4444; }
.status-dot.yellow { background-color: #f59e0b; }
.status-dot.green  { background-color: #10b981; }
.status-dot.gray   { background-color: #9ca3af; }

/* ─── Outcome badges ─────────────────────────────────────── */
.outcome-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
}
.outcome-positive  { background-color: #d1fae5; color: #065f46; }
.outcome-neutral   { background-color: #f3f4f6; color: #374151; }
.outcome-negative  { background-color: #fee2e2; color: #991b1b; }
.outcome-no_response { background-color: #fef3c7; color: #92400e; }

/* ─── Pipeline stage badges ──────────────────────────────── */
.stage-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
/* Active capture phases C1..C4 */
.stage-c1_opportunity     { background-color: #e0e7ff; color: #3730a3; }
.stage-c2_capture         { background-color: #dbeafe; color: #1e40af; }
.stage-c3_bid_planning    { background-color: #ede9fe; color: #5b21b6; }
.stage-c4_bid_development { background-color: #fef3c7; color: #92400e; }
/* Closed column header + terminal sub-states */
.stage-closed             { background-color: #f3f4f6; color: #374151; }
.stage-won                { background-color: #d1fae5; color: #065f46; }
.stage-lost               { background-color: #fee2e2; color: #991b1b; }
.stage-no_bid             { background-color: #fef9c3; color: #854d0e; }
.stage-dropped            { background-color: #f3f4f6; color: #6b7280; }
.stage-watch              { background-color: #ffedd5; color: #9a3412; }
/* Legacy stages retained briefly until any cached frontends drop them. */
.stage-prospecting  { background-color: #e0e7ff; color: #3730a3; }
.stage-engaged      { background-color: #dbeafe; color: #1e40af; }
.stage-proposal     { background-color: #ede9fe; color: #5b21b6; }
.stage-negotiation  { background-color: #fef3c7; color: #92400e; }
.stage-inactive     { background-color: #f3f4f6; color: #6b7280; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
    background: white;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    padding: 1rem;
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    gap: 0.375rem;
}
.btn-primary   { background-color: #4f46e5; color: white; border: none; }
.btn-primary:hover   { background-color: #4338ca; }
.btn-secondary { background-color: white; color: #374151; border: 1px solid #d1d5db; }
.btn-secondary:hover { background-color: #f9fafb; }
.btn-danger    { background-color: #ef4444; color: white; border: none; }
.btn-danger:hover    { background-color: #dc2626; }
.btn-ghost     { background-color: transparent; color: #6b7280; border: none; }
.btn-ghost:hover     { background-color: #f3f4f6; color: #374151; }
.btn-sm        { padding: 0.25rem 0.75rem; font-size: 0.75rem; }

/* ─── Icon button ─────────────────────────────────────────
   Per-row Edit/Delete style buttons. 32×32px hit area for thumb-
   friendly tapping on phones; transparent background with hover
   feedback. .btn-icon-danger swaps the hover colour to red. Use
   anywhere a row action takes just an emoji/SVG glyph. */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    flex-shrink: 0;
}
.btn-icon:hover    { background-color: #f3f4f6; color: #374151; }
.btn-icon-danger:hover { background-color: #fee2e2; color: #b91c1c; }

/* ─── Form inputs ────────────────────────────────────────── */
.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: border-color 0.15s;
    font-family: inherit;
}
.input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}
/* iOS Safari auto-zooms the viewport on focus of any <input> /
   <textarea> / <select> whose computed font-size is < 16px. The
   "zoom" never zooms back out so the user sees the page jump and
   parts of the layout clip. Bump to 16px below md across all
   .input controls + native select / textarea so focus never
   triggers the zoom. Desktop keeps the compact 14px. */
@media (max-width: 767px) {
    .input,
    input.input,
    textarea.input,
    select.input { font-size: 16px; }
}
select.input       { appearance: auto; }
textarea.input     { resize: vertical; min-height: 80px; }

/* iOS Safari renders `input[type="date"]` (and time/datetime variants)
   with an internal min-width derived from the locale's date format
   that escapes a narrow grid cell or form column. Pin to the parent
   and strip Safari's auto-styling. The min-height matches the
   computed height of a text input under the .input class (padding +
   font-size + line-height + border) so the inputs line up vertically;
   without it, `appearance: none` collapses an empty date input to a
   near-zero content height. */
input[type="date"].input,
input[type="time"].input,
input[type="datetime-local"].input {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    display: block;
    background-color: white;
    min-height: 2.375rem; /* ~38px, matches .input's text-input height */
    line-height: 1.5;
}

/* ─── Page header ────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}
/* On phone widths, the title block sits above the action buttons so
   3+ buttons don't squeeze the title into a narrow column. */
@media (max-width: 767px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        margin-bottom: 1rem;
    }
    .page-header > div:last-child {
        width: 100%;
        flex-wrap: wrap;
    }
}
.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}
.page-subtitle {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.125rem;
}
.section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #374151;
}

/* ─── Loading ────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── File drop zone ─────────────────────────────────────── */
.drop-zone {
    border: 2px dashed #d1d5db;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: #4f46e5;
    background-color: #eef2ff;
}

/* ─── Engagement type icons ──────────────────────────────── */
.type-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: white;
    shrink: 0;
}
.type-icon.meeting { background-color: #6366f1; }
.type-icon.call    { background-color: #10b981; }
.type-icon.email   { background-color: #f59e0b; }
.type-icon.note    { background-color: #8b5cf6; }
.type-icon.other   { background-color: #6b7280; }

/* ─── Empty state ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}
.empty-state svg   { margin: 0 auto 0.75rem; opacity: 0.4; }
.empty-state p     { font-size: 0.9375rem; font-weight: 500; color: #6b7280; }
.empty-state small { font-size: 0.8125rem; }

/* ─── Data table ─────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.data-table th {
    text-align: left;
    padding: 0.625rem 0.875rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
}
.data-table td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    vertical-align: middle;
}
.data-table tbody tr:hover { background-color: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ─── Master-detail customer layout ─────────────────────── */
/* Body is the page scroller. The list panel sticks to the top of the
   viewport while the user scrolls through long detail content; the
   detail panel flows naturally with body scroll (no internal overflow,
   so iOS status-bar tap-to-top works). The negative margin still
   bleeds the layout out of the parent's px-6/py-6 padding so the
   panels touch the page edges. */
.customers-master-detail {
    display: flex;
    gap: 0;
    margin: -1.5rem;
}
.customers-list-panel {
    width: 280px;
    min-width: 220px;
    max-width: 320px;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    background: white;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}
.customers-list-header {
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}
.customers-list-scroll {
    flex: 1;
    overflow-y: auto;
}
.customers-detail-panel {
    flex: 1;
    background: #f9fafb;
    min-width: 0;
}
.customer-list-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.1s;
}
.customer-list-row:hover { background: #f3f4f6; }
.customer-list-row.active { background: #eef2ff; border-left: 3px solid #4f46e5; padding-left: calc(0.75rem - 3px); }

/* Below md the two panels stack and only one is visible at a time.
   The `detail-active` class (toggled by Projects/Stakeholders pages
   when a detail loads) swaps which panel is shown. A "← Back" link
   inside the detail panel returns to the list view. Body is the
   page scroller so neither panel uses internal overflow; both flow
   naturally and a status-bar tap scrolls the whole page to top. */
@media (max-width: 767px) {
    .customers-master-detail {
        margin: -1rem;
    }
    .customers-list-panel {
        width: 100%;
        max-width: none;
        min-width: 0;
        border-right: none;
        position: static;
        height: auto;
    }
    .customers-list-scroll {
        overflow-y: visible;
        flex: none;
    }
    .customers-detail-panel {
        display: none;
    }
    .customers-master-detail.detail-active .customers-list-panel {
        display: none;
    }
    .customers-master-detail.detail-active .customers-detail-panel {
        display: block;
        width: 100%;
    }
}

/* ─── Engagement timeline ────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 1.5rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 2px;
    background: #e5e7eb;
}
.timeline-item {
    position: relative;
    margin-bottom: 1rem;
}
.timeline-item:last-child { margin-bottom: 0; }
.timeline-dot {
    position: absolute;
    left: -1.25rem;
    top: 0.5rem;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    border: 2px solid white;
}
.timeline-dot.meeting { background: #6366f1; }
.timeline-dot.call    { background: #10b981; }
.timeline-dot.email   { background: #f59e0b; }
.timeline-dot.note    { background: #8b5cf6; }
.timeline-dot.other   { background: #6b7280; }
.timeline-body {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.75rem;
    transition: box-shadow 0.15s;
}
.timeline-body:hover { box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ─── Dashboard sub-menu collapsible ─────────────────────── */
#dashboard-subnav {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
#dashboard-subnav.open {
    max-height: 200px;
}
#dashboard-chevron {
    transition: transform 0.2s ease;
}
#dashboard-chevron.open {
    transform: rotate(180deg);
}

/* ─── Sidebar scroll overflow indicator ──────────────────── */
#sidebar-scroll-indicator {
    position: sticky;
    bottom: 0;
    padding: 10px 0 4px;
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    line-height: 1;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.9) 55%);
    opacity: 0.7;
}

/* ─── Responsive: sidebar becomes an off-canvas drawer on phones ──
   At md (768px) and above the sidebar is a normal flex column. Below
   that it slides off-screen by default and overlays the page content
   when the burger button (in #mobile-topbar) toggles `.open`. The
   backdrop #mobile-sidebar-backdrop dims the page behind it. */
@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        /* Prefer the dynamic viewport so the iOS URL bar doesn't squeeze
           the bottom of the drawer (the last nav item ends up under the
           scroll-fade gradient otherwise). Falls back to 100% on browsers
           that don't support 100dvh yet. */
        height: 100%;
        height: 100dvh;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        width: 260px;
        box-shadow: 0 0 20px rgba(0,0,0,0.15);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    /* The collapse-to-icon-only toggle only makes sense on desktop where
       the sidebar lives in the flex row; hide it on phones. */
    #sidebar-toggle {
        display: none;
    }
}

/* ─── Dashboard subnav collapse animation ─────────────────── */
#dashboard-subnav {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.2s ease;
}
#dashboard-subnav.open {
    max-height: 200px;
}
@media (min-width: 768px) {
    .sidebar.collapsed #dashboard-subnav {
        max-height: 0 !important;
        transition: none;
    }
}
#dashboard-chevron {
    transition: transform 0.2s ease;
}
#dashboard-chevron.open {
    transform: rotate(180deg);
}

/* ─── User-menu collapse (sidebar bottom) ─────────────────── */
/* Mirrors the dashboard-subnav pattern: max-height animation for the
   user-menu (Settings + Sign Out) hidden under the user pill. Default
   collapsed; expands on user-pill click. When the sidebar itself is
   in icon-only collapsed mode we ignore the open/closed state and
   show the items as plain icon rows so the user can still reach
   Settings + Sign Out without expanding the sidebar. */
#sidebar-user-menu {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.2s ease;
}
#sidebar-user-menu.open {
    max-height: 200px;
}
@media (min-width: 768px) {
    .sidebar.collapsed #sidebar-user-menu {
        max-height: none !important;
        overflow: visible;
        transition: none;
    }
}
#sidebar-user-chevron.open {
    transform: rotate(180deg);
}

/* ─── Sidebar scroll indicators ───────────────────────────── */
#sidebar-scroll-indicator,
#sidebar-scroll-top-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #6b7280;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#sidebar-scroll-indicator {
    position: sticky;
    bottom: 0;
    padding: 10px 0 4px;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.97) 60%);
}

#sidebar-scroll-top-indicator {
    position: sticky;
    top: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    background: linear-gradient(to top, transparent, rgba(255,255,255,0.97) 60%);
    transition: opacity 0.2s ease, max-height 0.2s ease, padding 0.2s ease;
}

#sidebar-scroll-indicator.visible,
#sidebar-scroll-top-indicator.visible {
    opacity: 0.87;
}

#sidebar-scroll-top-indicator.visible {
    max-height: 60px;
    padding: 4px 0 10px;
}
