/* ============================================================================
   CUROVA design system — shared tokens + component styles.
   Extracted from base.html so every page loads one cached source of truth.
   Load once in base.html: <link rel="stylesheet" href="/assets/css/curova.css">
   Page-specific CSS still lives in each template's {% block extra_css %}.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Brand */
    --curova-navy: #001f3f;
    --curova-blue: #67adf5;
    --curova-blue-rgb: 103, 173, 245;
    --curova-navy-light: #003d7a;
    --curova-blue-light: #e8f2fe;
    --curova-dark: #001a33;
    --curova-light: #f8fafc;
    --curova-gradient: linear-gradient(135deg, var(--curova-navy) 0%, var(--curova-navy-light) 100%);
    --curova-gradient-reverse: linear-gradient(135deg, var(--curova-navy-light) 0%, var(--curova-navy) 100%);
    --primary-color: var(--curova-navy);
    --secondary-color: var(--curova-blue);
    --accent-color: var(--curova-blue);
    --success-color: #10b981;
    --warning-color: var(--curova-blue);
    --bs-warning: var(--curova-blue);
    --bs-warning-rgb: var(--curova-blue-rgb);
    --danger-color: #ef4444;
    --dark-color: var(--curova-dark);
    --light-color: var(--curova-light);

    /* Design tokens — Pass #2 */
    /* Surfaces / borders / text */
    --surface:        #ffffff;
    --surface-2:      #fafbfc;
    --surface-3:      #f4f6f9;
    --border-soft:    rgba(11, 37, 69, 0.08);
    --border:         rgba(11, 37, 69, 0.16);
    --border-strong:  rgba(11, 37, 69, 0.32);
    --text:           #0f172a;
    --text-2:         #334155;
    --text-muted:     #64748b;
    --text-faint:     #94a3b8;

    /* Spacing (4-pt scale) */
    --space-1:  4px;
    --space-2:  8px;
    --space-3:  12px;
    --space-4:  16px;
    --space-5:  24px;
    --space-6:  32px;
    --space-7:  48px;
    --space-8:  64px;

    /* Radii */
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-pill: 999px;

    /* Elevation */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 18px 36px rgba(15, 23, 42, 0.10);

    /* Type scale */
    --text-xs:   0.75rem;
    --text-sm:   0.875rem;
    --text-base: 0.95rem;
    --text-lg:   1.05rem;
    --text-xl:   1.2rem;
    --text-2xl:  1.4rem;
    --text-3xl:  1.7rem;
    --text-4xl:  2.2rem;
}

body {
    font-family: 'Greycliff CF', 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    /* 'tnum' (tabular/fixed-width digits) removed — it made numbers look
       oddly spaced everywhere; digits now use normal proportional spacing */
    font-feature-settings: 'ss01' 1, 'ss02' 1, 'cv01' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    background: var(--curova-gradient);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.55;
    letter-spacing: -0.005em;
}
h1, h2, h3, h4, h5 {
    font-family: 'Greycliff CF', 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--curova-navy);
    font-weight: 700;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
button { font-family: inherit; }

/* Headings inside dark/colored surfaces must stay white for contrast
   (the global navy heading color above would otherwise win). */
.text-white :is(h1, h2, h3, h4, h5, h6),
:is(.bg-dark, .bg-primary, .bg-secondary, .bg-success, .bg-danger, .bg-info) :is(h1, h2, h3, h4, h5, h6) {
    color: #fff;
}

.navbar {
    background: rgb(255, 255, 255) !important;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border-soft);
}

.navbar-brand {
    font-weight: 700;
    color: var(--curova-navy) !important;
    font-size: 1.5rem;
}

.main-container {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    margin: var(--space-5) auto;
    overflow: hidden;
}

.hero-section {
    background: var(--curova-gradient);
    color: white;
    padding: var(--space-6) var(--space-5);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero-section>* {
    position: relative;
    z-index: 1;
}

.hero-section h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    letter-spacing: -1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.hero-section p {
    font-size: 1.3rem;
    opacity: 0.95;
    margin-bottom: 0;
    font-weight: 300;
}

.content-section {
    padding: 3rem 2rem;
}

.form-control {
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #f8fafc;
}

.form-control:focus {
    border-color: var(--curova-blue);
    box-shadow: 0 0 0 0.2rem rgba(103, 173, 245, 0.25);
    background: white;
}

.btn-primary {
    background: var(--curova-gradient);
    border: none;
    border-radius: 12px;
    padding: 1rem 2rem;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    background: var(--curova-gradient-reverse);
    color: white;
}

.btn-success {
    background: var(--curova-blue);
    border: none;
    border-radius: 12px;
    padding: 1rem 2rem;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    color: var(--curova-navy);
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    background: #9ac8f8;
    color: var(--curova-navy);
}

.alert {
    border-radius: 10px;
    border: none;
    padding: 1rem 1.5rem;
}

.loading-spinner {
    display: none;
    text-align: center;
    padding: 2rem;
}

.spinner-border {
    width: 3rem;
    height: 3rem;
    color: var(--curova-navy);
}

.result-section {
    display: none;
    margin-top: 2rem;
}

.feature-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin: 1rem 0;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-soft);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.feature-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.feature-icon {
    font-size: 2.5rem;
    color: var(--curova-navy);
    margin-bottom: 1rem;
}

.card-header.bg-primary {
    background: var(--curova-gradient) !important;
}

.card-header.bg-success {
    background: var(--curova-gradient) !important;
}

.text-primary {
    color: var(--curova-navy) !important;
}

.spinner-border.text-primary {
    color: var(--curova-navy) !important;
}

@media (max-width: 768px) {
    .hero-section h1 {
        font-size: 2rem;
    }

    .content-section {
        padding: 2rem 1rem;
    }

    .main-container {
        margin: 1rem;
    }
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-up {
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}


/* Fix for btn-sm to actually be small despite global overrides */
.btn-sm {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
}

/* Curova-branded primary CTA (blue) and ghost secondary (navy outline) */
.btn-enter {
    background: var(--curova-blue);
    color: var(--curova-navy);
    border: 3px solid var(--curova-navy);
    border-radius: 12px;
    padding: 1.2rem 3rem;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-enter:hover {
    background: var(--curova-navy);
    color: var(--curova-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-back {
    background: transparent;
    color: var(--curova-navy);
    border: 2px solid var(--curova-navy);
    border-radius: 12px;
    padding: 0.8rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-back:hover {
    background: var(--curova-navy);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Pair-button row: equalizes sizes when btn-enter and btn-back sit side-by-side */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-row .btn-enter,
.btn-row .btn-back {
    padding: 0.9rem 1.75rem;
    font-size: 1.1rem;
    border-width: 2px;
    margin: 0;
    flex: 0 1 auto;
    min-width: 160px;
}

@media (max-width: 480px) {
    .btn-row .btn-enter,
    .btn-row .btn-back {
        flex: 1 1 100%;
        min-width: 0;
    }
}

/* Round paperclip "attach file" button used in chat composers */
.btn-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    background: transparent;
    border: none;
    color: #6c757d;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}

.btn-attach:hover {
    background: #e2e8f0;
    color: #334155;
}

/* ============================================================================
   Chat drawer — collapsible reference panel above a chat thread.

   Case context (trial, patient contact, linked clinician) used to sit in three
   always-open stacked panels above the message list. On a phone that left almost
   no room for the conversation itself, which is the point of the screen. These
   collapse it into one disclosure: open by default on desktop, closed on mobile
   (set by initChatDrawers() in the templates, since CSS cannot set `open`).

   Native <details>/<summary> so it works with no JS beyond the initial state,
   and keeps keyboard and screen-reader behaviour for free.
   ========================================================================== */
.chat-drawer {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    margin-bottom: .5rem;
}

.chat-drawer > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .6rem .75rem;
    cursor: pointer;
    list-style: none;
    font-size: .9rem;
    color: #334155;
    border-radius: 10px;
}

/* Hide the default disclosure triangle; the chevron below replaces it. */
.chat-drawer > summary::-webkit-details-marker { display: none; }
.chat-drawer > summary::marker { content: ""; }

.chat-drawer > summary:hover { background: #f8fafc; }

.chat-drawer > summary:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-drawer-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

/* Long trial titles and patient names must truncate, not wrap the header onto
   three lines — the header is the thing saving vertical space. */
.chat-drawer-title > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-drawer-chevron {
    flex-shrink: 0;
    color: #94a3b8;
    transition: transform .15s ease;
}

.chat-drawer[open] > summary .chat-drawer-chevron {
    transform: rotate(180deg);
}

.chat-drawer-body {
    padding: 0 .75rem .75rem;
    border-top: 1px solid #eef2f7;
    padding-top: .75rem;
}

.chat-drawer-body dl { margin-bottom: 0; }

/* Intake record rendered inside the thread. Server-generated, newline
   separated — pre-wrap or it reads as one run-on line. */
.chat-intake-details {
    white-space: pre-wrap;
    font-size: .85rem;
    color: #475569;
    margin: 0;
}

/* Chat bubbles: user-typed text keeps its line breaks. */
.chat-bubble-text { white-space: pre-wrap; }

/* Unread-reply count on the Profile nav link. Sized to stay legible next to the
   label without pushing the nav wider when it appears. */
.nav-unread-badge {
    display: inline-block;
    min-width: 1.25rem;
    margin-left: .35rem;
    padding: .1rem .35rem;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    vertical-align: middle;
}

/* Sent-at, on the sender line. Dimmed against whichever bubble it sits in and
   allowed to drop to its own line rather than widen a bubble on a phone. */
.chat-bubble-time {
    margin-left: .35rem;
    opacity: .75;
    white-space: nowrap;
}

@media (max-width: 767.98px) {
    .chat-drawer > summary { padding: .5rem .6rem; font-size: .85rem; }
    .chat-drawer-body { padding-bottom: .6rem; }
}

/* ============================================================================
   Admin shell — persistent sidebar layout shared by all admin pages
   (admin_base.html). Fixes the ad-hoc cross-link navigation that made the
   admin section feel scattered.
   ========================================================================== */
.admin-shell {
    display: flex;
    gap: var(--space-5);
    align-items: flex-start;
    max-width: 1320px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4);
}

.admin-sidebar {
    flex: 0 0 236px;
    position: sticky;
    top: var(--space-5);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-4) var(--space-3);
    overflow: hidden;
}

.admin-sidebar__title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    font-weight: 700;
    padding: var(--space-2) var(--space-3);
    margin: 0;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: var(--space-2);
}

.admin-nav__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.6rem var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-weight: 600;
    font-size: var(--text-sm);
    text-decoration: none;
    transition: background .15s, color .15s;
}

.admin-nav__link i {
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    transition: color .15s;
}

.admin-nav__link:hover {
    background: var(--surface-3);
    color: var(--curova-navy);
}

.admin-nav__link.is-active {
    background: var(--curova-blue-light);
    color: var(--curova-navy);
}

.admin-nav__link.is-active i {
    color: var(--curova-navy);
}

.admin-main {
    flex: 1 1 auto;
    min-width: 0;
}

/* Inside the shell, page cards shouldn't re-center or add top margin —
   the shell already provides the outer gutter. */
.admin-main .main-container {
    margin: 0;
    width: 100%;
}

/* Tabs sitting inside a navy .card-header (Metrics dashboard, Users tools):
   light text when inactive, navy-on-white when active. */
.card-header .card-header-tabs .nav-link { color: rgba(255, 255, 255, 0.85); border: none; }
.card-header .card-header-tabs .nav-link:hover { color: #fff; }
.card-header .card-header-tabs .nav-link.active { color: var(--curova-navy); background: #fff; }

@media (max-width: 900px) {
    .admin-shell {
        flex-direction: column;
        padding: var(--space-3);
    }
    .admin-sidebar {
        position: static;
        flex-basis: auto;
        width: 100%;
    }
    .admin-nav {
        flex-direction: row;
        flex-wrap: wrap;
    }
}
