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

:root {
    --blue:       #0d6efd;
    --blue-dark:  #0a58ca;
    --blue-faint: #e8f0fe;
    --blue-mid:   #4a90e2;
    --text:       #1a1a1a;
    --muted:      #555;
    --border:     #d8d8d8;
    --bg:         #fafafa;
    --card-bg:    #ffffff;
    --code-bg:    #f4f4f4;
    --mono:       'IBM Plex Mono', monospace;
    --sans:       'IBM Plex Sans', sans-serif;
    --radius:     6px;
    --shadow:     0 1px 4px rgba(0,0,0,0.07);
}

html { scroll-behavior: smooth; }
body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Nav ── */
.nav {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.75rem 2rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    font-size: 0.88rem;
}
.nav-brand {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--blue);
    text-decoration: none;
    letter-spacing: -0.01em;
}
.nav-brand:hover { color: var(--blue-dark); }
.nav-sep { color: var(--border); }
.nav-current { color: var(--muted); }
.nav-spacer { flex: 1; }
.nav-link {
    color: var(--muted);
    text-decoration: none;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
    font-size: 0.85rem;
}
.nav-link:hover { background: var(--blue-faint); color: var(--blue); }

/* ── Main content ── */
.main-content {
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    padding: 0 1.5rem;
    flex: 1;
}

/* ── Hero ── */
.hero {
    padding: 3rem 0 2rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}
.hero-label {
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--blue);
    margin-bottom: 0.5rem;
}
.hero-title {
    font-family: var(--mono);
    font-size: 2.4rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--text);
    margin-bottom: 0.4rem;
}
.hero-sub {
    font-size: 1rem;
    color: var(--muted);
    margin-bottom: 0.75rem;
    font-weight: 300;
}
.hero-desc {
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.7;
    max-width: 640px;
}

/* ── Tool cards ── */
.tool-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2.5rem;
}
.tool-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow);
}
.tool-card-icon { font-size: 1.4rem; margin-bottom: 0.5rem; }
.tool-card-name {
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--blue);
    margin-bottom: 0.35rem;
}
.tool-card-desc { font-size: 0.8rem; color: var(--muted); line-height: 1.55; }

/* ── Form section ── */
.form-section { margin-bottom: 3rem; }
.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.error-banner {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.87rem;
    color: #664d03;
}

.input-group { margin-bottom: 1.5rem; }
.input-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--mono);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.3rem;
}
.input-badge {
    font-size: 0.68rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: var(--blue-faint);
    color: var(--blue);
    font-weight: 600;
    letter-spacing: 0.03em;
}
.input-badge.af {
    background: #e8f5e9;
    color: #2e7d32;
}
.input-hint {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
    line-height: 1.5;
}
.input-hint code {
    font-family: var(--mono);
    background: var(--code-bg);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.78rem;
    border: 1px solid #e0e0e0;
}
.input-textarea {
    width: 100%;
    font-family: var(--mono);
    font-size: 0.82rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fdfdfd;
    color: var(--text);
    resize: vertical;
    transition: border-color 0.15s;
    line-height: 1.6;
}
.input-textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-faint);
}
.input-counter {
    font-size: 0.73rem;
    color: var(--muted);
    margin-top: 0.25rem;
    text-align: right;
    font-family: var(--mono);
}

/* ── Matrix selection ── */
.matrix-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.matrix-options { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.matrix-option {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fdfdfd;
    transition: border-color 0.15s, background 0.15s;
}
.matrix-option:hover { border-color: var(--blue); background: var(--blue-faint); }
.matrix-option input[type="radio"] { accent-color: var(--blue); }
.matrix-name { font-family: var(--mono); font-size: 0.8rem; }

.btn-upload-matrix {
    font-size: 0.78rem;
    padding: 0.3rem 0.7rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: #f8f8f8;
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.6;
}

/* ── Taxa counter ── */
.taxa-counter {
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--mono);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.taxa-bar-wrap {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.taxa-bar {
    height: 100%;
    background: var(--blue);
    border-radius: 2px;
    transition: width 0.2s, background 0.2s;
}
.taxa-bar.over { background: #dc3545; }

/* ── Submit button ── */
.btn-submit {
    width: 100%;
    padding: 0.85rem;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: background 0.15s, transform 0.1s;
    margin-bottom: 0.75rem;
}
.btn-submit:hover { background: var(--blue-dark); }
.btn-submit:active { transform: scale(0.99); }
.btn-submit:disabled { background: var(--border); cursor: not-allowed; }

.form-note {
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.6;
    text-align: center;
}
.form-note a { color: var(--blue); text-decoration: none; }
.form-note a:hover { text-decoration: underline; }

/* ── Waiting page ── */
.waiting-main { display: flex; align-items: center; justify-content: center; padding: 3rem 1.5rem; }
.waiting-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow);
    max-width: 520px;
    width: 100%;
    text-align: center;
}
.waiting-spinner { margin-bottom: 1.5rem; }
.spinner-ring {
    width: 44px;
    height: 44px;
    border: 3px solid var(--blue-faint);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-title {
    font-family: var(--mono);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

/* Job ID block */
.job-id-block {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    text-align: left;
}
.job-id-label { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.3rem; }
.job-id-value {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--text);
    word-break: break-all;
    margin-bottom: 0.5rem;
}
.btn-copy {
    font-size: 0.74rem;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    color: var(--muted);
    transition: background 0.15s;
}
.btn-copy:hover { background: var(--blue-faint); color: var(--blue); }

/* Stage progress */
.stages {
    text-align: left;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.stage-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: var(--muted);
}
.stage-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
}
.stage-done .stage-dot  { background: var(--blue); border-color: var(--blue); }
.stage-done .stage-label { color: var(--text); }
.stage-active .stage-dot { background: var(--blue-faint); border-color: var(--blue); animation: pulse 1s infinite; }
.stage-active .stage-label { color: var(--blue); font-weight: 600; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(13,110,253,0.4); }
    50% { box-shadow: 0 0 0 4px rgba(13,110,253,0); }
}

.waiting-msg { font-size: 0.82rem; color: var(--muted); margin-bottom: 1.25rem; font-family: var(--mono); }
.msg-error { color: #dc3545; }
.waiting-return { font-size: 0.8rem; }
.waiting-return a { color: var(--blue); text-decoration: none; }

/* ── Results page ── */
.results-main { padding: 1.5rem; }
.results-jobbar {
    font-size: 0.78rem;
    color: var(--muted);
    font-family: var(--mono);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.results-joblabel { color: var(--muted); }
.results-jobid { color: var(--text); font-weight: 600; }
.results-runtime { color: var(--muted); }

/* Metrics strip */
.metrics-strip {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1.5rem;
}
.metric-cell {
    background: var(--card-bg);
    padding: 0.75rem 1rem;
    text-align: center;
}
.metric-val {
    display: block;
    font-family: var(--mono);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--blue);
}
.metric-label {
    display: block;
    font-size: 0.67rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

/* Results grid */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.results-col { display: flex; flex-direction: column; gap: 1.25rem; }

.results-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.section-title {
    font-family: var(--mono);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.85rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.82rem;
    padding: 0.28rem 0;
    border-bottom: 1px solid #f0f0f0;
}
.stat-row:last-of-type { border-bottom: none; }
.stat-label { color: var(--muted); }
.stat-val { font-family: var(--mono); font-size: 0.82rem; color: var(--text); }
.stat-val.mono { font-family: var(--mono); }
.stat-pct { color: var(--muted); font-size: 0.75rem; }
.tag-nmr { color: #856404; }
.tag-warn { color: #dc3545; }

/* Charts */
.length-chart-wrap { margin-top: 1rem; }
.chart-label { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.4rem; font-family: var(--mono); }

/* Bootstrap bars */
.bootstrap-bars { margin: 1rem 0; display: flex; flex-direction: column; gap: 0.5rem; }
.bs-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; }
.bs-label { font-family: var(--mono); width: 38px; color: var(--muted); text-align: right; flex-shrink: 0; }
.bs-bar-wrap { flex: 1; height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden; }
.bs-bar { height: 100%; border-radius: 4px; transition: width 0.4s; min-width: 2px; }
.bs-100 { background: #0d6efd; }
.bs-95  { background: #4a90e2; }
.bs-70  { background: #fd7e14; }
.bs-low { background: #dc3545; }
.bs-count { font-family: var(--mono); font-size: 0.75rem; color: var(--text); width: 20px; }

/* Tree placeholder */
.tree-placeholder {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    margin: 1rem 0;
    background: #fafafa;
}
.tree-placeholder-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.tree-placeholder-title { font-family: var(--mono); font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.tree-placeholder-sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

/* Newick */
.newick-block { margin-top: 0.75rem; }
.newick-label { font-size: 0.72rem; color: var(--muted); font-family: var(--mono); margin-bottom: 0.3rem; }
.newick-text {
    width: 100%;
    font-family: var(--mono);
    font-size: 0.72rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--code-bg);
    color: var(--text);
    resize: vertical;
    height: 80px;
    line-height: 1.4;
}

/* Downloads */
.download-list { display: flex; flex-direction: column; gap: 0.5rem; }
.download-btn {
    display: block;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.82rem;
    color: var(--text);
    background: #fdfdfd;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.download-btn:hover { background: var(--blue-faint); border-color: var(--blue); color: var(--blue); }

/* ── Footer ── */
.footer {
    text-align: center;
    padding: 1.25rem;
    font-size: 0.82rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
    background: #fff;
    margin-top: auto;
}
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--blue); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .tool-cards { grid-template-columns: 1fr; }
    .metrics-strip { grid-template-columns: repeat(3, 1fr); }
    .results-grid { grid-template-columns: 1fr; }
    .nav { padding: 0.75rem 1rem; }
    .main-content { padding: 0 1rem; }
}

/* ── Chart search + scroll ── */
.chart-search {
    width: 100%;
    font-family: var(--mono);
    font-size: 0.78rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fdfdfd;
    color: var(--text);
    margin-bottom: 0.5rem;
    transition: border-color 0.15s;
}
.chart-search:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-faint);
}
.chart-scroll-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 4px;
}
.chart-scroll-wrap canvas {
    display: block;
    height: 140px !important;
}

/* ── View tree button ── */
.btn-view-tree {
    width: 100%;
    padding: 0.75rem;
    background: var(--blue-faint);
    color: var(--blue);
    border: 1px solid var(--blue);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: background 0.15s, color 0.15s;
    margin: 0.75rem 0;
}
.btn-view-tree:hover {
    background: var(--blue);
    color: #fff;
}

/* ── Tree modal ── */
.tree-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.tree-modal-overlay.open {
    display: flex;
}
.tree-modal-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 90vw;
    height: 88vh;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tree-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.tree-modal-title {
    font-family: var(--mono);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
}
.tree-modal-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.btn-modal-action {
    font-size: 0.78rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fdfdfd;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-modal-action:hover {
    background: var(--blue-faint);
    color: var(--blue);
    border-color: var(--blue);
}
.btn-modal-close {
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.btn-modal-close:hover { background: #f0f0f0; color: var(--text); }

.tree-modal-body {
    flex: 1;
    overflow: hidden;
    padding: 0.5rem;
}
.tree-modal-body svg {
    width: 100%;
    height: 100%;
}
.tree-error {
    padding: 2rem;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    line-height: 1.7;
}
