/* ==========================================================================
   RCEM QIP ASSISTANT - CUSTOM STYLES
   ========================================================================== */

/* ==========================================================================
   BASE STYLES
   ========================================================================== */

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   CUSTOM SCROLLBAR
   ========================================================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ==========================================================================
   TOGGLE SWITCH
   ========================================================================== */

.toggle-checkbox:checked {
    right: 0;
    border-color: #10b981;
}

.toggle-checkbox:checked + .toggle-label {
    background-color: #10b981;
}

.toggle-label {
    width: 36px;
    transition: background-color 0.2s ease;
}

/* ==========================================================================
   NAVIGATION
   ========================================================================== */

.nav-btn {
    position: relative;
    overflow: hidden;
}

/* Disabled nav state — no project loaded */
.nav-btn-disabled {
    opacity: 0.4;
    cursor: not-allowed !important;
    pointer-events: none;
}

.nav-btn::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #2d2e83;
    transform: scaleY(0);
    transition: transform 0.2s ease;
}

.nav-btn.bg-rcem-purple::before,
.nav-btn:hover::before {
    transform: scaleY(1);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

#toast-container {
    pointer-events: none;
}

#toast-container > * {
    pointer-events: auto;
}

.toast {
    animation: slideIn 0.3s ease-out;
}

.toast.removing {
    animation: slideOut 0.3s ease-in forwards;
}

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

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

/* ==========================================================================
   ANIMATIONS (Onboarding & UI)
   ========================================================================== */

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   FISHBONE DIAGRAM
   ========================================================================== */

.fishbone-label {
    position: absolute;
    padding: 6px 12px;
    background: white;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    z-index: 10;
    /* Without a cap, a long cause/category label could visually extend far
       past its left-anchor position and run into the fixed "Effect" box on
       the right regardless of how carefully that anchor is clamped. */
    max-width: 150px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.fishbone-label:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #2d2e83;
}

.fishbone-label.category {
    font-weight: 700;
    font-size: 13px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-color: #2d2e83;
    color: #2d2e83;
}

.fishbone-label.dragging {
    opacity: 0.8;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

/* ==========================================================================
   DRIVER DIAGRAM
   ========================================================================== */

.driver-column {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    border-radius: 12px;
    padding: 16px;
    min-height: 400px;
}

.driver-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.driver-item:hover {
    border-color: #2d2e83;
    box-shadow: 0 2px 8px rgba(45, 46, 131, 0.1);
}

/* ==========================================================================
   PROCESS MAP
   ========================================================================== */

.process-step {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    position: relative;
    transition: all 0.2s ease;
}

.process-step:hover {
    border-color: #2d2e83;
}

.process-step.decision {
    transform: rotate(45deg);
    width: 100px;
    height: 100px;
}

.process-step.decision > * {
    transform: rotate(-45deg);
}

.process-connector {
    width: 40px;
    height: 2px;
    background: #cbd5e1;
    position: relative;
}

.process-connector::after {
    content: '';
    position: absolute;
    right: 0;
    top: -4px;
    border: 5px solid transparent;
    border-left-color: #cbd5e1;
}

/* ==========================================================================
   STAKEHOLDER MATRIX
   ========================================================================== */

.stakeholder-point {
    transition: transform 0.2s ease;
}

.stakeholder-point:hover {
    transform: scale(1.2);
}

/* ==========================================================================
   GANTT CHART
   ========================================================================== */

.gantt-bar {
    height: 24px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.gantt-bar:hover {
    filter: brightness(1.1);
}

.gantt-milestone {
    width: 16px;
    height: 16px;
    transform: rotate(45deg);
    background: #f59e0b;
}

/* ==========================================================================
   CHARTS
   ========================================================================== */

#chart-wrapper {
    position: relative;
}

#mainChart {
    max-height: 400px;
}

.chart-annotation {
    position: absolute;
    padding: 4px 8px;
    background: rgba(249, 115, 22, 0.9);
    color: white;
    font-size: 13px;
    font-weight: 600;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 20;
}

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-backdrop {
    backdrop-filter: blur(4px);
}

/* ==========================================================================
   FORM ELEMENTS
   ========================================================================== */

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid #2d2e83;
    outline-offset: 1px;
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* ==========================================================================
   PRINT STYLES & POSTER MODE
   ========================================================================== */

@media print {
    /* ── Page setup ─────────────────────────────────────── */
    @page {
        margin: 1.5cm;
        size: A4 portrait;
    }

    /* ── Typography ─────────────────────────────────────── */
    body {
        font-size: 11pt !important;
        color: #1e293b !important;
        background: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* ── Hide all chrome & interactive elements ──────────── */
    #app-sidebar,
    #top-bar,
    #mobile-menu-btn,
    .no-print,
    button,
    select,
    input[type="date"],
    input[type="text"],
    input[type="number"],
    #chart-mode-controls,
    #signal-panel,
    #arcp-countdown-widget,
    #pdsa-template-row,
    #pdsa-view-toggle,
    .pdsa-template-select,
    [data-lucide="trash-2"],
    [data-lucide="plus"],
    [data-lucide="chevron-down"],
    [data-lucide="chevron-up"],
    [data-lucide="printer"],
    .chart-controls,
    .export-controls {
        display: none !important;
    }

    /* ── Layout: remove sidebar offset, allow full page flow ─ */
    #app-container,
    #main-wrapper {
        margin-left: 0 !important;
        overflow: visible !important;
        height: auto !important;
        display: block !important;
    }

    main,
    #content-area {
        overflow: visible !important;
        height: auto !important;
        padding: 0 !important;
    }

    /* Show the full project view; hide tab/section nav */
    .view-section {
        display: none !important;
    }

    #view-full {
        display: block !important;
        max-width: none !important;
        width: 100% !important;
        padding: 0 !important;
    }

    /* ── Cards & sections ───────────────────────────────── */
    .bg-white.rounded-xl,
    .bg-white.rounded-lg {
        box-shadow: none !important;
        border: 1px solid #cbd5e1 !important;
        page-break-inside: avoid;
    }

    section,
    .pdsa-card {
        page-break-inside: avoid;
    }

    h2, h3 {
        page-break-after: avoid;
    }

    /* ── PDSA cards: force all bodies expanded ───────────── */
    [id^="pdsa-body-"] {
        display: block !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* Hide the toggle chevron buttons inside PDSA cards */
    [id^="pdsa-toggle-"] {
        display: none !important;
    }

    /* ── Textareas: render as plain readable text ────────── */
    textarea {
        border: none !important;
        resize: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
        font-family: inherit !important;
        font-size: inherit !important;
        color: inherit !important;
    }

    /* ── Colours: preserve brand accents for readability ─── */
    .bg-emerald-50 { background-color: #f0fdf4 !important; }
    .bg-blue-50    { background-color: #eff6ff !important; }
    .bg-amber-50   { background-color: #fffbeb !important; }
    .bg-slate-50   { background-color: #f8fafc !important; }
    .text-emerald-700 { color: #047857 !important; }
    .text-blue-700    { color: #1d4ed8 !important; }

    /* ── Poster Mode (existing) ─────────────────────────── */
    body.printing-poster-mode {
        background: white !important;
    }

    body.printing-poster-mode #app-container {
        display: block !important;
        height: auto !important;
    }

    body.printing-poster-mode #main-wrapper {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }

    body.printing-poster-mode #content-area {
        overflow: visible !important;
        height: auto !important;
        padding: 0 !important;
    }

    body.printing-poster-mode .view-section {
        display: none !important;
    }

    body.printing-poster-mode #view-full {
        display: block !important;
        max-width: none !important;
        width: 100% !important;
        padding-bottom: 0 !important;
    }

    body.printing-poster-mode #full-project-container > div {
        border: none !important;
        box-shadow: none !important;
    }
}

/* ==========================================================================
   RESPONSIVE UTILITIES
   ========================================================================== */

@media (max-width: 768px) {
    .fishbone-label {
        font-size: 13px;
        padding: 4px 8px;
    }
    
    .fishbone-label.category {
        font-size: 13px;
        padding: 4px 12px;
    }
    
    #stakeholder-canvas {
        min-height: 400px;
    }

    /* Ensure modals don't overflow on small screens */
    .bg-white.rounded-xl.shadow-2xl {
        max-height: 95vh;
        overflow-y: auto;
    }
    
    /* Prevent iOS auto-zoom on inputs */
    input, select, textarea {
        font-size: 16px !important;
    }
    
    /* Force stacked columns on mobile. minmax(0,1fr) stops wide children
       (tables, long words) from pushing the column past the screen edge. */
    .grid {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 1rem !important;
    }
    .grid > * {
        min-width: 0;
    }
    #app-sidebar .grid.grid-cols-5 {
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        gap: 0.25rem !important;
    }
    
    /* Enable smooth touch scrolling for wide data tables */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
        border: 1px solid #e2e8f0;
        border-radius: 0.5rem;
    }
    
    /* Wide tables scroll inside their own box rather than widening the page */
    .overflow-x-auto table:not([class*="min-w-"]) {
        min-width: 600px;
    }
    
    /* Maximise screen space on small devices */
    .view-section {
        padding: 0.5rem !important;
    }
    
    .p-6 {
        padding: 1rem !important;
    }

    /* Let rows of buttons wrap onto a new line instead of running off screen */
    .flex.gap-2 {
        flex-wrap: wrap;
    }

    /* A card that spans two or three columns on a desktop grid (col-span-2/3)
       would otherwise force an extra, empty implicit column once the grid is
       collapsed to one column above, pushing every odd card into a 0px track
       (seen on the Quick Guide and the dashboard). Make it span the one column. */
    .grid > [class*="col-span-"] {
        grid-column: 1 / -1 !important;
    }

    /* Page headers: title on one line, action buttons on the next, instead of
       both being squeezed side by side (QI Team, Stakeholders, Timeline...). */
    header.flex.justify-between,
    .view-section header.flex,
    .flex.justify-between.items-center.mb-6,
    .flex.justify-between.items-center.mb-4 {
        flex-wrap: wrap;
        row-gap: 0.75rem;
    }
    header.flex.justify-between > .flex.gap-2,
    header.flex.justify-between > .flex.items-center.gap-2 {
        width: 100%;
    }

    /* Page titles are sized for a laptop; bring them down a step on phones. */
    .view-section h1.text-3xl { font-size: 1.5rem; line-height: 2rem; }
    .view-section h2.text-2xl { font-size: 1.25rem; line-height: 1.75rem; }

    /* Two-column grids explicitly marked to stay two-up on phones
       (dashboard stat cards). */
    .grid.grid-cols-2.mobile-keep {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
    }
}

/* Finger-sized hit areas for icon-only buttons (edit/delete pencils and bins)
   on touch screens, without changing how they look with a mouse. */
@media (pointer: coarse) {
    button.p-1:has(> svg:only-child),
    button.p-1\.5:has(> svg:only-child),
    button.p-2:has(> svg:only-child),
    button.p-0\.5:has(> svg:only-child) {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Pages designed for small screens opt out of the blanket mobile rules
   above (stacked flex rows, full-width buttons, single-column grids,
   600px-wide tables): Data & charts, QIP Lead and Supervisor overviews. */
@media (max-width: 768px) {
    .mobile-keep .flex.gap-2,
    .mobile-keep.flex.gap-2 {
        flex-direction: row;
    }
    .mobile-keep .flex.gap-2 button,
    .mobile-keep.flex.gap-2 button {
        width: auto;
    }
    .mobile-keep .grid.grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }
    .mobile-keep .grid.grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }
    .mobile-keep table {
        min-width: 0;
    }
}

@media (max-width: 640px) {
    #toast-container {
        left: 16px;
        right: 16px;
    }
    
    #toast-container > * {
        max-width: 100%;
    }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid #2d2e83;
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Safe area insets for mobile */
@supports (padding: env(safe-area-inset-bottom)) {
    #app-sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    #toast-container {
        bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* ==========================================================================
   COLLAPSIBLE NAV GROUPS & ACCORDIONS (streamlined sidebar, Data & SPC page)
   ========================================================================== */

/* Sidebar nav group chevron rotation is applied inline via JS (transform
   style), but keep a default upright state + smooth transition here. */
.nav-group-header {
    cursor: pointer;
}
.nav-group-chevron {
    transform: rotate(0deg);
}

/* Native <details> accordions (Rapid Entry / Operational Definition cards) */
details > summary {
    -webkit-tap-highlight-color: transparent;
}
details > summary::-webkit-details-marker {
    display: none;
}
.details-chevron {
    transition: transform 0.2s ease;
    transform: rotate(0deg);
}
details[open] .details-chevron {
    transform: rotate(90deg);
}

/* Read-only review (QIP Lead, supervisor, admin, share link): hide the
   widgets whose only job is to change the project. */
body.readonly-mode .readonly-hide { display: none !important; }

/* PDF report (export.js builds an off-screen copy of the Whole Project View
   at A4 width): show everything in full and fit it to the page width. */
.pdf-export .truncate { overflow: visible; white-space: normal; text-overflow: clip; }
.pdf-export .line-clamp-3 { display: block; -webkit-line-clamp: unset; overflow: visible; }
.pdf-export .overflow-x-auto { overflow: visible; }
.pdf-export [class*="min-w-["] { min-width: 0 !important; }
.pdf-export svg { max-width: 100%; height: auto; }
.pdf-export .shadow-sm, .pdf-export .shadow { box-shadow: none; }
/* A tiny letter-spacing makes html2canvas place each character where the
   browser laid it out, instead of re-wrapping words (which overlapped
   wrapped labels such as "Sign-off" or "Supervisor / QIAT"). */
.pdf-export, .pdf-export * { letter-spacing: 0.01px; }
/* In the PDF the page margins frame the report, so drop the on-screen card
   edge and its side padding. */
.pdf-export > * > .rounded-xl { border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
.pdf-export > * > .rounded-xl > header { border-radius: 10px !important; }
.pdf-export .p-8.space-y-8 { padding-left: 0 !important; padding-right: 0 !important; }
.pdf-export > * > .rounded-xl > footer { display: none !important; }

/* Sidebar: one icon colour; the active item's icon turns white with it. */
#app-sidebar .nav-icon { color: #94a3b8; }
#app-sidebar .nav-btn:hover .nav-icon { color: #e2e8f0; }
#app-sidebar .nav-btn.bg-rcem-purple .nav-icon { color: #fff; }
/* The blanket phone rules above stack every .flex.gap-2 row and grid; the
   sidebar is already laid out for a narrow column, so keep its rows. */
@media (max-width: 768px) {
    #app-sidebar .flex.gap-2 { flex-direction: row; }
    #app-sidebar .grid.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 0.25rem !important; }
}

/* Supervisor / QIP Lead sidebar buttons when the account doesn't have that
   role: still reachable (the view explains how to get access), but quieter. */
#app-sidebar .role-btn-inactive {
    background-color: rgba(255, 255, 255, 0.05);
    color: rgb(203 213 225);
    font-weight: 500;
}
#app-sidebar .role-btn-inactive:hover { background-color: rgba(255, 255, 255, 0.1); color: #fff; }

/* ── Hover / tap hints (hints.js) ───────────────────────────────────────── */
.qip-hint-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; margin-left: 6px; vertical-align: middle;
    border-radius: 9999px; border: 1px solid #c7d2fe; background: #eef2ff;
    color: #4338ca; font-size: 10px; font-weight: 700; line-height: 1;
    cursor: help; flex-shrink: 0; padding: 0;
}
.qip-hint-btn:hover, .qip-hint-btn[aria-expanded="true"] { background: #4338ca; color: #fff; border-color: #4338ca; }
.qip-hint-btn:focus-visible { outline: 2px solid #4338ca; outline-offset: 2px; }
h1 .qip-hint-btn, h2 .qip-hint-btn { width: 18px; height: 18px; font-size: 11px; }
#qip-hint-pop {
    position: fixed; z-index: 9999; max-height: min(70vh, 520px); overflow-y: auto;
    background: #fff; color: #334155; border: 1px solid #e2e8f0; border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18); padding: 14px 16px;
    font-size: 13px; line-height: 1.45; text-transform: none; letter-spacing: normal; font-weight: 400;
}
#qip-hint-pop[hidden] { display: none; }
.qip-hint-title { font-weight: 700; color: #1e293b; font-size: 14px; margin-bottom: 4px; }
.qip-hint-what { margin: 0 0 8px; }
.qip-hint-tips { margin: 0 0 8px; padding-left: 18px; list-style: disc; }
.qip-hint-tips li { margin-bottom: 3px; }
.qip-hint-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; margin: 8px 0 4px; }
.qip-hint-example { background: #f8fafc; border: 1px solid #e2e8f0; border-left: 3px solid #6366f1; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.qip-hint-example p { margin: 0; font-style: italic; }
.qip-hint-actions { display: flex; gap: 8px; margin-top: 6px; }
.qip-hint-actions button { font-size: 11px; font-weight: 600; color: #4338ca; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 6px; padding: 2px 8px; }
.qip-hint-actions button:hover { background: #e0e7ff; }
.qip-hint-foot { font-size: 11px; color: #94a3b8; margin: 4px 0 0; }
@media print { .qip-hint-btn, #qip-hint-pop { display: none !important; } }
/* Keep hint buttons small even inside the mobile "stack buttons" rules. */
/* Bigger invisible tap area around the small "?" so it is easy to hit on a phone */
.qip-hint-btn { position: relative; }
.qip-hint-btn::before { content: ""; position: absolute; inset: -10px; }
button.qip-hint-btn { width: 16px !important; min-width: 0 !important; display: inline-flex !important; flex: 0 0 auto !important; }
h1 button.qip-hint-btn, h2 button.qip-hint-btn { width: 18px !important; }

/* ── Usability fixes (19 Oct 2026 review) ───────────────────────────────── */
/* The top bar must stay on one line (the title truncates instead) */
#top-bar, #top-bar .flex { flex-wrap: nowrap !important; }
/* slate-400 grey on white is only 2.6:1; use slate-500 (4.8:1) for text in the main pages */
#content-area .text-slate-400 { color: #64748b; }

/* Controls that only appear on hover can't be found on a touch screen, so show them there */
@media (hover: none) {
    [class*="group-hover:opacity-100"] { opacity: 1 !important; }
}
