/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #fff;
    color: #1a1a1a;
    line-height: 1.5;
    min-height: 100vh;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ────────────────────────────────────────────────── */
.site-header {
    border-bottom: 1px solid #e5e7eb;
    padding: 0 1.25rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 200;
    background: #fff;
}

/* App body: sidebar + content side by side */
.app-body {
    display: flex;
    min-height: calc(100vh - 56px);
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: 210px;
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
    padding: 1rem 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.2s ease;
    background: #fff;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    align-self: flex-start;
}

body.sidebar-closed .sidebar {
    width: 0;
    padding: 0;
    border-right: none;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.9375rem;
    color: #374151;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
}

a.sidebar-item:hover { background: #f3f4f6; text-decoration: none; }

.sidebar-item-active {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 500;
}

.sidebar-item-muted { color: #9ca3af; cursor: default; }

.sidebar-item-commit { color: #374151; }

.sidebar-commit-count {
    margin-left: auto;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0.5rem 0;
}

/* ─── Sidebar toggle (hamburger) ─────────────────────────────── */
.sidebar-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    color: #4b5563;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}

.sidebar-toggle:hover {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #1a1a1a;
}

/* Badge on hamburger: visible only when sidebar is collapsed + commits pending */
.sidebar-badge {
    display: none;
    position: absolute;
    top: 1px;
    right: 1px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #dc2626;
    color: #fff;
    font-size: 0.625rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

body.sidebar-closed .sidebar-badge { display: flex; }

/* App content area */
.app-content {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.site-header .wordmark {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #1a1a1a;
    text-decoration: none;
    display: flex;
    align-items: center;
    height: 100%;
}

.site-header .logo {
	max-height: 40px;
	max-width: 100%;
	height: auto;
	width: auto;
	object-fit: contain;
	flex-shrink: 1;
}

/* ─── Nav menu (dropdown) ────────────────────────────────────── */
.nav-menu { position: relative; }

.nav-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.375rem 0.625rem;
    font-size: 0.875rem;
    color: #4b5563;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.nav-toggle:hover,
.nav-toggle-open {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #1a1a1a;
}

.nav-chevron {
    transition: transform 0.2s;
    flex-shrink: 0;
}

.nav-toggle-open .nav-chevron { transform: rotate(180deg); }

.nav-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding: 0.375rem 0;
    z-index: 100;
}

.nav-item {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
    color: #1a1a1a;
    text-decoration: none;
}

.nav-item:hover { background: #f9fafb; text-decoration: none; }

.nav-item-muted { color: #6b7280; }

.nav-item-label {
    display: block;
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
    color: #9ca3af;
    cursor: default;
}

.nav-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0.375rem 0;
}

.site-main {
    max-width: 1060px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

/* ─── Auth pages (centered single-column) ───────────────────── */
.auth-wrap {
    min-height: calc(100vh - 56px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.auth-card h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.auth-card .subtitle {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 2rem;
}

.auth-card .logo {
	max-height: 100%;
	max-width: 100%;
	height: auto;
	width: auto;
	object-fit: contain;
	flex-shrink: 1;
}

/* ─── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: #374151;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9375rem;
    color: #1a1a1a;
    background: #fff;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group .field-error {
    font-size: 0.8125rem;
    color: #dc2626;
    margin-top: 0.3rem;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.125rem;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; text-decoration: none; }

.btn-secondary {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}

.btn-secondary:hover { background: #f9fafb; text-decoration: none; }

.btn-danger {
    background: #fff;
    color: #dc2626;
    border-color: #fca5a5;
}

.btn-danger:hover { background: #fef2f2; text-decoration: none; }

.btn-full { width: 100%; justify-content: center; }

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    margin: 1rem;
}

.modal h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.625rem;
}

.modal p {
    font-size: 0.9375rem;
    color: #4b5563;
    margin-bottom: 1.5rem;
}

.modal-actions { display: flex; gap: 0.75rem; }

/* ─── Flash messages ─────────────────────────────────────────── */
.flash-list { list-style: none; margin-bottom: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
}

.flash-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5; }
.flash-success { background: #f0fdf4; color: #16a34a; border: 1px solid #86efac; }
.flash-info    { background: #eff6ff; color: #2563eb; border: 1px solid #93c5fd; }
.flash-warning { background: #fffbeb; color: #d97706; border: 1px solid #fcd34d; }
.setup-warning { margin-bottom: 1.5rem; color: #92400e; }
.setup-loading { margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.625rem; }
.spinner {
    width: 1rem; height: 1rem; flex-shrink: 0; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent;
    animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }   /* spin: below */
.setup-warning ul { margin: 0.375rem 0 0.375rem 1.25rem; }
.setup-warning a { color: #92400e; font-weight: 600; text-decoration: underline; }

/* ─── Loading overlay ────────────────────────────────────────── */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.75);
    z-index: 300;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}

.loading-overlay.active { display: flex; }

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-message {
    font-size: 0.9375rem;
    color: #374151;
    font-weight: 500;
}

/* ─── Markdown output (sections + requirement fields) ───────── */
.doc-section-text p, .md-field p        { margin: 0 0 0.6em; }
.doc-section-text p:last-child,
.md-field p:last-child                  { margin-bottom: 0; }
.doc-section-text ul, .md-field ul,
.doc-section-text ol, .md-field ol     { margin: 0 0 0.6em 1.5em; }
.doc-section-text li, .md-field li     { margin-bottom: 0.2em; }
.doc-section-text strong, .md-field strong { font-weight: 600; }
.doc-section-text em, .md-field em     { font-style: italic; }
.doc-section-text code, .md-field code {
    font-family: monospace; font-size: 0.9em;
    background: #f3f4f6; border-radius: 3px; padding: 0.1em 0.35em;
}
.doc-section-text table, .md-field table {
    border-collapse: collapse; font-size: 0.875rem; margin: 0.5em 0 0.75em;
}
.doc-section-text th, .md-field th {
    padding: 0.35rem 0.75rem; font-weight: 600; color: #374151;
    background: #f9fafb; border: 1px solid #e5e7eb; text-align: left;
}
.doc-section-text td, .md-field td {
    padding: 0.35rem 0.75rem; color: #374151; border: 1px solid #e5e7eb;
    vertical-align: top;
}

/* ─── Print ─────────────────────────────────────────────────── */
@media print {
    .site-header,
    .sidebar { display: none !important; }
    .app-body { display: block; }
    .app-content { overflow: visible; }
}

/* Product name centered in the header, on every page (the sticky header positions it) */
.site-header .header-product {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    text-decoration: none;
    white-space: nowrap;
}
.site-header .header-product:hover { color: #2563eb; }
@media (max-width: 720px) { .site-header .header-product { display: none; } }

/* Page titles: one size on every page, smaller than the product name, and the same
   distance from the header (pages used to set their own top margins). */
.page-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    align-self: flex-start;      /* in a row with buttons: a taller button must not push it down */
}
a + .page-title, a + div .page-title { margin-top: 0.5rem; }
.site-main > div:first-of-type { margin-top: 0 !important; }

/* Edits made in eDHF that are not yet in Git: the notice by a page title, and a row tag */
.edits-notice {
    display: inline-flex; align-items: center; font-size: 0.8125rem; font-weight: 500; white-space: nowrap;
    padding: 0.2rem 0.75rem; border-radius: 6px; background: #fffbeb; border: 1px solid #fcd34d;
    color: #92400e; text-decoration: none;
}
.edits-notice:hover { background: #fef3c7; }
.edited-tag {
    font-family: inherit; font-size: 0.6875rem; font-weight: 600; padding: 0.05rem 0.35rem; margin-left: 0.375rem;
    border-radius: 3px; background: #fef3c7; color: #92400e; vertical-align: middle;
}

/* Side panel icons: muted next to the label, blue when the item is active */
.sidebar-item { gap: 0.625rem; }
.sidebar-icon { flex-shrink: 0; color: #9ca3af; }
a.sidebar-item:hover .sidebar-icon { color: #6b7280; }
.sidebar-item-active .sidebar-icon { color: currentColor; }

/* ─── Theme: matches the Regression Analysis agent's UI ─────────
   (Agents/regression_analysis ui/templates/base.html): dark navy side
   panel, light grey page, white cards with a soft shadow. Kept here as
   overrides so the layout rules above stay as they are. */
:root {
    --nav-bg: #1a1f2e;          /* side panel */
    --nav-text: #c9d1e0;
    --nav-hover: #2d3347;
    --nav-muted: #5a6480;       /* section labels, dividers' neighbours */
    --accent: #2563eb;          /* active item, buttons, links */
    --page-bg: #e8ecf2;         /* cool blue-grey, so white cards stand out */
    --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --card-head: #dce5f2;       /* card header bar: light blue (the agent's cards use it too) */
    --card-head-line: #cdd9ea;  /* card outline and header divider */
}

body { background: var(--page-bg); }
.site-header { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06); border-bottom-color: #e5e7eb; }

.sidebar {
    width: 220px;               /* the agent's side panel width */
    background: var(--nav-bg);
    border-right: none;
    padding: 0.5rem 0 1rem;
}
body.sidebar-closed .sidebar { width: 0; padding: 0; }
.sidebar { display: flex; flex-direction: column; }
.sidebar-version {
    margin-top: auto;           /* at the bottom, as in the agent */
    padding: 0.75rem 1.25rem 0;
    border-top: 1px solid var(--nav-hover);
    font-size: 0.7rem;
    color: var(--nav-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.page-title { font-size: 1.25rem; }   /* the agent's page title size */
.sidebar-section {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--nav-muted);
    white-space: nowrap;
}
.sidebar-item {
    color: var(--nav-text);
    font-size: 0.875rem;
    padding: 0.45rem 0.75rem;
    margin: 0.0625rem 0.5rem;
    border-radius: 4px;
}
a.sidebar-item:hover { background: var(--nav-hover); color: #fff; }
.sidebar-item-active, a.sidebar-item-active:hover { background: var(--accent); color: #fff; font-weight: 500; }
.sidebar-icon { color: #8b93a8; }
a.sidebar-item:hover .sidebar-icon, .sidebar-item-active .sidebar-icon { color: #fff; }
.sidebar-item-muted { color: var(--nav-muted); }
.sidebar-item-commit { color: var(--nav-text); }
.sidebar-divider { background: var(--nav-hover); margin: 0.5rem 0.75rem; }

/* Cards: the page templates draw them inline (a #e5e7eb border, 8px radius,
   a #f9fafb header bar); on the grey page they become white cards with a
   shadow and an outline in the header's blue; the header bar is light blue with a divider (as the agent's). */
.site-main [style*="border:1px solid #e5e7eb; border-radius:8px"] {
    background-color: #fff;
    border-color: var(--card-head-line) !important;
    box-shadow: var(--card-shadow);
}
.site-main [style*="border-radius:8px"] [style*="background:#f9fafb"] {
    background: var(--card-head) !important;
    border-bottom-color: var(--card-head-line) !important;
}
.auth-card { background: #fff; border-color: var(--card-head-line); box-shadow: var(--card-shadow); }
/* Tables placed straight on the page (not inside a card) get the card look too. */
.site-main table:not([style*="border-radius:8px"] table) {
    background-color: #fff;
    outline: 1px solid var(--card-head-line);
    box-shadow: var(--card-shadow);
    border-radius: 6px;
}

/* Information that can't be edited here (a project's source documents): grey, not a white
   card, so it doesn't read as an input */
.site-main table.readonly-info {
    background-color: #eef1f5 !important;
    outline: 1px solid #d6dce5;
    box-shadow: none;
    color: #4b5563;
}
.site-main table.readonly-info th { color: #6b7280; font-weight: 500; }
.site-main table.readonly-info td,
.site-main table.readonly-info th { background: transparent; }
.site-main table.readonly-info code { background: transparent; color: #374151; }

/* Project selector in the top bar (app/projects.py) */
.project-select select {
    font: inherit; font-size: 0.875rem; font-weight: 600; color: #1f2a30;
    padding: 0.3rem 1.75rem 0.3rem 0.6rem; border: 1px solid #e5e7eb; border-radius: 6px;
    background: #fff; cursor: pointer; margin-right: 0.5rem;
}
.project-select { display: flex; align-items: center; gap: 0.4rem; }
.project-select label { font-size: 0.875rem; font-weight: 500; color: #6b7280; }
.project-select select:hover { border-color: var(--card-head-line); background: #f3f4f6; }

/* Collapsible cards (release page): a <details class="fold-card"> whose <summary> is the card's
   header, with a caret; buttons in the header work without toggling it. */
.fold-card > summary::-webkit-details-marker { display: none; }
.fold-card > summary .fold-caret { color: #6b7280; font-size: 0.75rem; transition: transform 0.15s; }
.fold-card[open] > summary .fold-caret { transform: rotate(90deg); }
.fold-card[open] > summary { border-bottom: 1px solid #e5e7eb; }
.fold-card:not([open]) > summary { border-bottom: none !important; }
