/* MO 科研平台 — portal design system (P3, docs/platform-multitenant-design.md §8.2)
 *
 * Derived from ChemDB's stylesheet so the two properties read as one product
 * (shared gradient header, card shape, button set, colour ramp). Deliberately a
 * *copy* rather than a link to ChemDB's asset: mo-web runs 4 workers and must
 * serve its own static files, and a cross-origin stylesheet would make every MO
 * page depend on ChemDB being up to render at all (§2 — ChemDB down degrades
 * MO to anonymous, never to broken).
 *
 * Sections:
 *   1. Tokens
 *   2. Layout + header/footer
 *   3. Buttons / badges / tables / cards
 *   4. Portal-only: hero, template grid, capability grid, stats
 *   5. Workbench: upload form, mapping table, validation report
 */

/* ── 1. Tokens ───────────────────────────────────────────────────────────── */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --accent: #0ea5e9;
    --light: #f8fafc;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --border-radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -1px rgba(0, 0, 0, .06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -2px rgba(0, 0, 0, .05);
    --transition: all .25s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background-color: var(--light);
    color: var(--gray-800);
    line-height: 1.6;
}

/* ── 2. Layout + header/footer ───────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 1rem 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

.logo {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
}

.logo-subtitle { font-size: .8rem; font-weight: 500; opacity: .85; }

.nav-links { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.nav-links a {
    color: #fff;
    text-decoration: none;
    font-weight: 500;
    font-size: .95rem;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    transition: var(--transition);
    white-space: nowrap;
}

.nav-links a:hover, .nav-links a.active { background-color: rgba(255, 255, 255, .16); }

.nav-user { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.nav-user .who { opacity: .9; max-width: 200px; overflow: hidden; text-overflow: ellipsis;
                 white-space: nowrap; }

.main-content { padding: 2rem 0 4rem; }

h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .35rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: .75rem; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }

.subtitle, .hint, .muted { color: var(--gray-500); font-size: .9rem; }
.hint.warn { color: var(--warning); }
.section-head { margin: 2.5rem 0 1rem; }
.crumbs { font-size: .85rem; color: var(--gray-500); margin-bottom: .75rem; }
.crumbs a { color: var(--primary); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.empty { color: var(--gray-500); padding: 24px 0; }

code {
    background: var(--gray-100);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: .85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

footer {
    background: var(--gray-900);
    color: var(--gray-400);
    padding: 2rem 0;
    font-size: .85rem;
}

footer a { color: var(--gray-300); }
footer .foot-grid { display: flex; flex-wrap: wrap; gap: 32px; justify-content: space-between; }
footer strong { color: #fff; display: block; margin-bottom: .4rem; font-size: .95rem; }

/* ── 3. Buttons / badges / tables / cards ────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 20px;
    background-color: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    font-size: .95rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover { background-color: var(--primary-dark); transform: translateY(-1px); }
.btn:disabled { background-color: var(--gray-300); cursor: not-allowed; transform: none; }

.btn.secondary, .btn-secondary { background-color: var(--secondary); }
.btn.secondary:hover, .btn-secondary:hover { background-color: var(--gray-700); }

.btn.ghost {
    background-color: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn.ghost:hover { background-color: var(--gray-100); color: var(--gray-900); }

.btn-outline { background-color: transparent; border: 1px solid #fff; color: #fff; }
.btn-outline:hover { background-color: #fff; color: var(--primary); }

.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* Text-link button for destructive row actions. Styled as a link so it sits
   inline with the row's other links, coloured to read as dangerous before the
   confirm dialog does. */
button.link-danger {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
    color: var(--danger);
}
button.link-danger:hover { text-decoration: underline; }
button.link-danger:disabled { color: var(--gray-300); cursor: default; text-decoration: none; }

/* Same, in link colour — for non-destructive row actions (查看 / 报告). */
button.link-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
    color: var(--primary);
}
button.link-btn:hover { text-decoration: underline; }

.row-actions { display: inline-flex; gap: 14px; align-items: center; white-space: nowrap; }

ol.steps { padding-left: 1.25em; margin: .5rem 0 0; }
ol.steps li { margin: .45rem 0; }

/* Editable data grid (project detail). table-layout:fixed + a colgroup of
   per-column pixel widths keeps the header and its cells exactly aligned; the
   header sticks to the top and the row-number / ID / action columns freeze at
   the edges so a 40+ column table stays navigable in both directions.
   border-collapse stays `separate`: collapsed borders detach from sticky cells
   in Chrome, which reads as the header drifting off its columns.
   Named .datagrid, NOT .grid — `.grid` further down is the portal card layout,
   and its `display: grid` on a <table> drops the colgroup (treated as
   display:none in a grid container), so header and body size their columns
   independently and drift apart. */
.datagrid-scroll { max-height: 62vh; overflow: auto; scroll-behavior: smooth; }
.datagrid {
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 100%;
    font-size: .85rem;
}
.datagrid thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f4f6fa;
    padding: 6px 8px;
    font-size: .76rem;
    font-weight: 600;
    color: var(--gray-600);
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    vertical-align: bottom;
    border-bottom: 1px solid var(--gray-200);
    letter-spacing: 0;
}
.datagrid thead th.jumped { background: #e0e7ff; }
.datagrid tbody td {
    background: #fff;
    padding: 2px 4px;
    border-bottom: 1px solid var(--gray-100);
}
.datagrid tbody tr:nth-child(even) td { background: #fafbfd; }
.datagrid tbody tr:hover td { background: #f2f7ff; }
.datagrid td.rownum {
    color: var(--gray-500);
    font-size: .78rem;
    text-align: right;
    white-space: nowrap;
    padding: 4px 8px;
}
/* Frozen edges. left offset of .col-sticky-2 = the row-number column width —
   renderGrid() sets both from the same COL_ROWNUM constant. */
.datagrid .col-sticky-1 { position: sticky; left: 0; z-index: 2; }
.datagrid .col-sticky-2 { position: sticky; z-index: 2; box-shadow: inset -1px 0 0 var(--gray-200); }
.datagrid .col-act { position: sticky; right: 0; z-index: 2; box-shadow: inset 1px 0 0 var(--gray-200); text-align: center; }
.datagrid thead th.col-sticky-1, .datagrid thead th.col-sticky-2, .datagrid thead th.col-act { z-index: 4; }
.datagrid input {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    font: inherit;
    font-size: .85rem;
    padding: 4px 6px;
}
.datagrid input:hover { border-color: var(--gray-300); }
.datagrid input:focus { border-color: var(--primary); outline: none; background: #fff; }
.datagrid input.changed { background: #fffbeb; }
.datagrid input.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn-row .status { margin-top: 0; }
.btn-row select { max-width: 180px; }
.btn-row input[type="number"] { width: 72px; }
#origin-filter { margin: 6px 0 10px; }
#origin-filter .origin-choice { margin-right: 16px; white-space: nowrap; }
#origin-filter input[type="checkbox"] { vertical-align: -2px; margin-right: 2px; }

/* 特征列设置 (project detail): collapsible checkbox grid over spec fields. */
.feature-settings {
    margin: 6px 0 12px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 8px 12px;
    background: var(--gray-50, #f9fafb);
}
.feature-settings summary {
    cursor: pointer;
    font-weight: 600;
    font-size: .9rem;
}
.feature-settings summary .muted { font-weight: 400; margin-left: 6px; }
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 2px 16px;
    margin: 8px 0 4px;
}
.feature-grid .origin-choice {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .85rem;
}
.feature-grid input[type="checkbox"] { vertical-align: -2px; margin-right: 4px; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-600);
    white-space: nowrap;
}

.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.green { background: #d1fae5; color: #065f46; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.gray { background: var(--gray-200); color: var(--gray-700); }

.card {
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.card-title { font-size: 1.15rem; font-weight: 600; color: var(--gray-800); margin: 0; }

.table-container { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }

th, td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: top;
}

th { font-weight: 600; color: var(--gray-500); font-size: .82rem; letter-spacing: .01em;
     background: var(--gray-100); white-space: nowrap; }

tbody tr:hover td { background: #fafcff; }
td.num { font-variant-numeric: tabular-nums; }

/* ── 4. Portal-only ──────────────────────────────────────────────────────── */
.hero {
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 60%, #ecfeff 100%);
    border-bottom: 1px solid var(--gray-200);
    padding: 3.5rem 0 3rem;
}

.hero h1 { font-size: 2.1rem; line-height: 1.3; margin-bottom: .75rem; }
.hero .lede { font-size: 1.05rem; color: var(--gray-600); max-width: 62ch; margin-bottom: 1.5rem; }
.hero .kicker {
    display: inline-block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--primary-dark);
    background: #dbeafe;
    padding: 4px 12px;
    border-radius: 999px;
    margin-bottom: 1rem;
}

.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 992px) {
    .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
    .navbar { flex-direction: column; align-items: flex-start; }
    .hero h1 { font-size: 1.6rem; }
}

/* Template card — the portal's main affordance, so it gets the lift on hover
   and a footer row pinned to the bottom regardless of description length. */
.template-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    padding: 22px;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.template-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px);
                       border-color: var(--gray-300); }
.template-card h3 { font-size: 1.1rem; margin-bottom: .2rem; }
.template-card .tpl-id { font-size: .78rem; color: var(--gray-400); margin-bottom: .75rem; }
.template-card .tpl-desc { font-size: .9rem; color: var(--gray-600); flex-grow: 1;
                           margin-bottom: 1rem; }
.template-card .tpl-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 1rem; }
.template-card .tpl-actions { display: flex; gap: 10px; align-items: center; }

.stat-tile {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    padding: 18px 20px;
}

.stat-tile .stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--primary-dark);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-tile .stat-label { font-size: .82rem; color: var(--gray-500); margin-top: .2rem; }

.capability {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-left: 3px solid var(--primary);
    border-radius: var(--border-radius);
    padding: 20px;
}

.capability h3 { color: var(--gray-800); }
.capability p { font-size: .9rem; color: var(--gray-600); }

.cta {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    margin-top: 2.5rem;
}

.cta h2 { color: #fff; }
.cta p { opacity: .9; margin-bottom: 1.25rem; font-size: .95rem; }
.cta .btn { background: #fff; color: var(--primary-dark); }
.cta .btn:hover { background: var(--gray-100); }

/* ── 5. Workbench (P2 upload flow — class names unchanged) ───────────────── */
.status { font-size: .9rem; margin-top: 10px; }
.status.ok { color: var(--success); }
.status.error { color: var(--danger); }
.status.warn { color: var(--warning); }
.status.pending { color: var(--gray-500); }

.summary { display: flex; flex-wrap: wrap; gap: 24px; margin-bottom: 16px; }
.summary dt { color: var(--gray-500); font-size: .8rem; }
.summary dd { margin: 0; font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Validation report rows. Warnings are advisory (out-of-range, unlisted choice)
   and errors drop the row — see mo_ml/tabular.py — so the two need to be
   distinguishable at a glance, not just by the text in the severity column. */
tr.sev-error td { background: #fef2f2; }
tr.sev-warning td { background: #fffbeb; }
tr.sev-error:hover td { background: #fee2e2; }
tr.sev-warning:hover td { background: #fef3c7; }

select, input[type="text"], input[type="file"] {
    max-width: 340px;
    padding: 7px 9px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: .9rem;
    font-family: inherit;
    background: #fff;
    color: var(--gray-800);
}

select:focus, input[type="text"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

label { font-size: .9rem; font-weight: 500; display: inline-block; margin-bottom: 4px; }
.field-row { margin-bottom: 14px; }

pre {
    background: var(--gray-900);
    color: var(--gray-200);
    padding: 12px 14px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: .8rem;
    max-height: 420px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    line-height: 1.5;
}
