/* SAPAI theme for every Django page: the look of the Streamlit landing page
   (sapai-streamlit/pages/landing.html) with Streamlit's red as the main colour. */

:root {
    --primary: #FF4B4B;
    --primary-hover: #E53E3E;
    --primary-soft: #FFF1F1;
    --text: #1a1a1a;
    --heading: #111;
    --muted: #4b5563;
    --faint: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --soft-bg: #fafafa;
    --sidebar-bg: #F0F2F6;
    --success-bg: #ecfdf3;
    --success-text: #166534;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --info-bg: #eff6ff;
    --info-text: #1e40af;
    --radius: 8px;
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    color: var(--text);
    background: #fff;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { color: var(--heading); line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 0.75rem; }
h1 { font-size: clamp(1.8rem, 3.6vw, 2.4rem); font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; margin-top: 2rem; }
p { margin: 0 0 1rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--faint); font-size: 0.85rem; }

.material-symbols-outlined { font-size: 20px; vertical-align: middle; }

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    text-decoration: none;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.btn-row .btn { flex: 1 1 12rem; }

/* ── Cards, alerts, tables ────────────────────────────────────────────── */

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.92rem;
}
.alert p:last-child { margin-bottom: 0; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-info { background: var(--info-bg); color: var(--info-text); }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--faint); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table-wrap { overflow-x: auto; }

.chip {
    display: inline-block;
    padding: 0.3rem 0.85rem;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.05em;
}
.chip-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    margin-right: 0.5rem;
    vertical-align: middle;
}

.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    vertical-align: -0.15em;
    margin-right: 0.4rem;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ────────────────────────────────────────────────────────────── */

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem; }
.field .help { display: block; color: var(--faint); font-size: 0.8rem; margin-top: 0.3rem; }
.field-check label { display: inline; font-weight: 500; }
.errorlist { list-style: none; padding: 0; margin: 0.3rem 0 0; color: var(--error-text); font-size: 0.85rem; }
.field-error { color: var(--error-text); font-size: 0.85rem; }

input[type=text], input[type=email], input[type=password], input[type=url], select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.95rem;
    background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox] { accent-color: var(--primary); width: 1rem; height: 1rem; vertical-align: -0.15em; margin-right: 0.35rem; }

/* File input styled as Streamlit's upload box. */
input[type=file] {
    display: block;
    width: 100%;
    padding: 1.25rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--soft-bg);
    font: inherit;
    font-size: 0.9rem;
    color: var(--muted);
    cursor: pointer;
}
input[type=file]::file-selector-button {
    margin-right: 1rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* allauth's built-in pages render plain buttons and fields. */
.allauth h1 { font-size: 1.5rem; }
.allauth label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0.75rem 0 0.35rem; }
.allauth button, .allauth input[type=submit] {
    margin-top: 1rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
}
.allauth button:hover, .allauth input[type=submit]:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* ── Public layout (home, privacy, sign-in) ───────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 2rem;
    border-bottom: 1px solid var(--border);
}
.topbar img { height: 40px; display: block; }

.page { max-width: 880px; margin: 0 auto; padding: 3rem 2rem; }
.page-narrow { max-width: 460px; }

.hero { text-align: center; padding: 3rem 0 2rem; }
.hero .chip { margin-bottom: 2rem; }
.hero h1 { font-size: clamp(2.1rem, 4.4vw, 3rem); letter-spacing: -0.025em; line-height: 1.15; }
.hero-tagline { color: var(--primary); font-weight: 500; margin-bottom: 0.5rem; }
.hero-sub { color: var(--muted); font-size: 1.05rem; max-width: 580px; margin: 0 auto 2rem; line-height: 1.65; }

.footer {
    padding: 2rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.82rem;
    color: var(--faint);
}

/* ── App layout (/app/): Streamlit-style sidebar ──────────────────────── */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 244px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    background: var(--sidebar-bg);
    overflow-y: auto;
}
.sidebar-logo img { height: 44px; display: block; margin: 0 0.5rem 1.5rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    color: var(--text);
    font-size: 0.92rem;
}
.sidebar-link:hover { background: rgba(0, 0, 0, 0.05); text-decoration: none; }
.sidebar-link.active { background: rgba(0, 0, 0, 0.07); font-weight: 600; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border-strong); font-size: 0.85rem; }
.sidebar-footer .muted { padding: 0 0.6rem 0.5rem; word-break: break-all; }
.sidebar-footer form { margin: 0; }
.sidebar-footer button.sidebar-link { width: 100%; border: 0; background: none; font: inherit; font-size: 0.92rem; cursor: pointer; text-align: left; }

.app-main { flex: 1; min-width: 0; }
.app-content { max-width: 730px; margin: 0 auto; padding: 3rem 1.5rem 4rem; }

.menu-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 20;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
}

/* ── Mobile ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .topbar { padding: 0.75rem 1rem; }
    .page { padding: 2rem 1rem; }
    .hero { padding: 1.5rem 0 1rem; }

    .menu-toggle { display: block; }
    .sidebar {
        position: fixed;
        z-index: 10;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
        padding-top: 3.5rem;
    }
    .sidebar.open { transform: none; }
    .app-content { padding: 3.5rem 1rem 3rem; }
}

/* ── Trial pages ──────────────────────────────────────────────────────── */

:root {
    --warning-bg: #fffbeb;
    --warning-text: #92400e;
}
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }
.alert ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.alert details { margin-top: 0.4rem; }
.warning-text { color: var(--error-text); font-weight: 600; }
.help { display: block; color: var(--faint); font-size: 0.8rem; margin: 0.4rem 0 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0 1.5rem; }
code { font-size: 0.85em; background: rgba(0, 0, 0, 0.05); padding: 0.1rem 0.35rem; border-radius: 4px; }

.app-content-wide { max-width: 1100px; }

.btn-small { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-row { margin-bottom: 1rem; }
.btn-row-inline .btn { flex: 0 0 auto; }
.icon-btn {
    border: 0;
    background: none;
    color: var(--faint);
    padding: 0.25rem;
    border-radius: 6px;
    cursor: pointer;
}
.icon-btn:hover { color: var(--error-text); background: var(--error-bg); }

/* Editable tables, styled after Streamlit's data editor. */
.table-edit { margin-bottom: 0.75rem; }
.table-edit th, .table-edit td { padding: 0.35rem 0.4rem; vertical-align: middle; }
.table-edit input[type=text], .table-edit input[type=number], .table-edit select {
    padding: 0.35rem 0.5rem;
    font-size: 0.88rem;
    border-color: var(--border);
    min-width: 6rem;
}
.table-edit input[type=number] { width: 100%; min-width: 4.5rem; }
.table-edit .col-narrow { width: 6.5rem; }
.table-edit .col-check { text-align: center; width: 1%; white-space: nowrap; }
.table-edit .col-check input { margin: 0; }
.table-edit .col-action { width: 2.5rem; }
input[type=number] {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.95rem;
    background: #fff;
}

.card-collapsible > summary { cursor: pointer; font-weight: 600; }
.card-collapsible[open] > summary { margin-bottom: 0.75rem; }

/* Analyses: one card per analysis, numbered. */
.analysis-boxes { counter-reset: analysis; }
.analysis-box { counter-increment: analysis; padding: 1.25rem; }
.analysis-number::after { content: " " counter(analysis); }
.analysis-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip-check {
    display: inline-flex !important;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: 100px;
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    margin: 0 !important;
    cursor: pointer;
    background: #fff;
}
.chip-check input { margin: 0; }
.chip-check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

/* Draft SAP */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab { padding: 0.5rem 0.9rem; color: var(--muted); font-weight: 600; font-size: 0.9rem; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--primary); border-bottom-color: var(--primary); text-decoration: none; }
.tab-panel h3 { margin-top: 1.5rem; }
.section-form { margin-bottom: 1.5rem; }
.section-form label { display: block; margin-bottom: 0.35rem; }
.section-form textarea { margin-bottom: 0.5rem; font-size: 0.9rem; line-height: 1.5; }
.download-card .btn-row { margin-bottom: 0; }
.raw { white-space: pre-wrap; font-size: 0.78rem; max-height: 30rem; overflow: auto; background: var(--soft-bg); padding: 1rem; border-radius: var(--radius); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Sidebar: the selected trial's pages and the trial list. */
.sidebar-section { margin: 1.25rem 0 0.5rem; }
.sidebar-section:first-of-type { margin-top: 0; }
.sidebar-heading { padding: 0 0.6rem 0.35rem; font-weight: 700; font-size: 0.9rem; }
.sidebar-trial { font-weight: 500; }
.sidebar-empty { padding: 0 0.6rem; }

@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* Methods: each method's details as label / value rows. */
.details-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 0; font-size: 0.9rem; }
.details-list dt { font-weight: 600; color: var(--muted); }
.details-list dd { margin: 0; }
@media (max-width: 768px) {
    .details-list { grid-template-columns: 1fr; }
    .details-list dd { margin-bottom: 0.5rem; }
}
.btn:disabled, .btn:disabled:hover { opacity: 0.45; cursor: not-allowed; background: var(--primary); border-color: var(--primary); }
.btn:not(.btn-primary):disabled, .btn:not(.btn-primary):disabled:hover { background: #fff; border-color: var(--border-strong); color: var(--faint); }
