/* BioNäring — Professionell medicinsk stil */

:root {
    --primary: #1a7a5c;
    --primary-dark: #145e47;
    --primary-light: #e8f5f0;
    --accent: #2980b9;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --bg: #fafbfc;
    --white: #ffffff;
    --border: #dce1e6;
    --error: #c0392b;
    --error-bg: #fdf0ef;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Navbar */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
}

.logo-accent { color: var(--primary); }

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

.nav-links a {
    text-decoration: none;
    color: var(--text);
    font-size: 0.95rem;
}

.nav-links a:hover { color: var(--primary); }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 24px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn:hover { background: var(--primary-dark); }
.btn-sm { padding: 6px 16px; font-size: 0.9rem; }
.btn-lg { padding: 14px 36px; font-size: 1.1rem; }
.btn-full { width: 100%; text-align: center; }

/* Hero */
.hero {
    background: linear-gradient(135deg, var(--primary-light), var(--white));
    padding: 80px 0;
    text-align: center;
}

.hero h1 {
    font-size: 2.4rem;
    margin-bottom: 16px;
    line-height: 1.3;
}

.highlight { color: var(--primary); }

.hero-sub {
    font-size: 1.15rem;
    color: var(--text-light);
    max-width: 640px;
    margin: 0 auto 32px;
}

/* Steps */
.steps {
    padding: 60px 0;
    text-align: center;
}

.steps h2 {
    margin-bottom: 40px;
    font-size: 1.8rem;
}

.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 30px;
}

.step-card {
    background: var(--white);
    padding: 32px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.step-number {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 auto 16px;
}

.step-card h3 { margin-bottom: 8px; }

/* Features */
.features {
    padding: 40px 0 60px;
    background: var(--white);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 30px;
}

.feature {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.feature h3 {
    color: var(--primary);
    margin-bottom: 8px;
}

/* Auth pages */
.auth-container {
    display: flex;
    justify-content: center;
    padding: 60px 20px;
}

.auth-card {
    background: var(--white);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
}

.auth-card h1 {
    margin-bottom: 24px;
    text-align: center;
}

.auth-link {
    text-align: center;
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-light);
}

.auth-link a { color: var(--primary); }

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,122,92,0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #e6b0aa;
}

.alert-success {
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid var(--primary);
}

/* Dashboard */
.dashboard {
    padding: 40px 20px;
}

.dashboard h1 { margin-bottom: 8px; }
.dashboard-intro { color: var(--text-light); margin-bottom: 32px; }

.form-section {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.form-section h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--primary);
}

.section-toggle {
    cursor: pointer;
    user-select: none;
}

.section-toggle::after {
    content: " ▼";
    font-size: 0.7rem;
}

.collapsible.collapsed {
    display: none !important;
}

/* Medication autocomplete */
.med-input-wrapper {
    position: relative;
}

.med-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
}

.med-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,122,92,0.1);
}

.med-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 280px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.med-category {
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.med-result-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}

.med-result-item:hover {
    background: var(--primary-light);
}

.med-alias {
    font-size: 0.8rem;
    color: var(--text-light);
}

.med-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.med-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.med-chip-x {
    background: none;
    border: none;
    color: var(--primary-dark);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.7;
}

.med-chip-x:hover {
    opacity: 1;
}

/* Results */
.results-area {
    margin-top: 32px;
    padding: 24px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.results-area h2 { margin-bottom: 16px; color: var(--primary); }

.safety-warning {
    background: var(--error-bg);
    border: 2px solid var(--error);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.safety-warning h3 { color: var(--error); margin-bottom: 8px; }

.rec-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.rec-card h4 { color: var(--primary); margin-bottom: 4px; }
.rec-card .score { color: var(--text-light); font-size: 0.85rem; }

.report-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.report-section:last-child { border-bottom: none; }
.report-section h3 { margin-bottom: 8px; }

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Footer */
.footer {
    background: var(--text);
    color: rgba(255,255,255,0.7);
    padding: 24px 0;
    text-align: center;
    font-size: 0.85rem;
}

.footer-ce {
    margin-top: 4px;
    font-size: 0.75rem;
    opacity: 0.6;
}

/* Admin table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.admin-table th {
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.inline-form { display: inline; }

.btn-secondary {
    background: var(--accent);
}

.btn-secondary:hover { background: #2471a3; }

.btn-danger {
    background: var(--error);
}

.btn-danger:hover { background: #a93226; }

.text-light { color: var(--text-light); font-size: 0.85rem; }

/* Info article (hur-det-fungerar) */
.info-article {
    padding: 40px 0 60px;
    max-width: 800px;
    margin: 0 auto;
}

.info-article h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    line-height: 1.3;
}

.info-article .hero-sub {
    margin-bottom: 40px;
}

.info-section {
    margin-bottom: 48px;
}

.info-section h2 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-light);
}

.info-section h3 {
    font-size: 1.1rem;
    margin-top: 24px;
    margin-bottom: 8px;
}

.info-section ul {
    margin: 8px 0 8px 24px;
}

.info-section li {
    margin-bottom: 6px;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin: 12px 0;
}

.info-table th,
.info-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.info-table th {
    background: var(--primary-light);
    font-weight: 600;
    color: var(--primary-dark);
}

.info-table tr:hover {
    background: var(--bg);
}

.level-critical-low td:first-child,
.level-critical-high td:first-child {
    color: var(--error);
    font-weight: 600;
}

.level-suboptimal-low td:first-child,
.level-suboptimal-high td:first-child {
    color: #d4a017;
    font-weight: 600;
}

.level-optimal td:first-child {
    color: var(--primary);
    font-weight: 600;
}

/* CE Trace section */
.trace-section {
    margin-top: 24px;
    padding: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.trace-toggle {
    cursor: pointer;
    user-select: none;
    color: var(--text-light);
    font-size: 0.95rem;
}

.trace-toggle::after {
    content: " ▼";
    font-size: 0.65rem;
}

.trace-details.collapsed {
    display: none;
}

.trace-table {
    width: 100%;
    margin-top: 12px;
    font-size: 0.85rem;
    border-collapse: collapse;
}

.trace-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}

.trace-label {
    color: var(--text-light);
    font-weight: 500;
    width: 140px;
}

.trace-mono {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.8rem;
    word-break: break-all;
}

.chain-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.chain-ok {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.chain-broken {
    background: var(--error-bg);
    color: var(--error);
}

.trace-layers {
    width: 100%;
    margin-top: 12px;
    font-size: 0.82rem;
    border-collapse: collapse;
}

.trace-layers th {
    text-align: left;
    padding: 4px 8px;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.trace-layers td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}

/* CE Admin */
.ce-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.ce-summary-card {
    background: var(--white);
    padding: 20px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.ce-summary-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.ce-summary-label {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 4px;
}

.hash-cell {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.82rem;
    word-break: break-all;
}

a.hash-cell {
    color: var(--accent);
    text-decoration: none;
}

a.hash-cell:hover {
    text-decoration: underline;
}

.layer-detail-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.layer-detail-title {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 4px;
}

.layer-detail-meta {
    display: flex;
    gap: 16px;
    font-size: 0.82rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

/* Flow diagram */
.flow-diagram {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-top: 1.5rem;
    padding: 32px 0;
    background: linear-gradient(180deg, var(--bg) 0%, var(--white) 50%, var(--bg) 100%);
    border-radius: 12px;
}

/* ── Top/bottom nodes ── */
.flow-node {
    width: 100%;
    max-width: 420px;
    text-align: center;
    padding: 20px 24px;
    border-radius: 12px;
    background: var(--white);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    position: relative;
}

.flow-input {
    border: 2px solid var(--primary);
    background: linear-gradient(135deg, var(--primary-light), var(--white));
}

.flow-ce {
    border: 2px solid var(--text-light);
    background: var(--white);
}

.flow-node-icon {
    color: var(--primary);
    margin-bottom: 6px;
}

.flow-ce-icon {
    color: var(--text-light);
}

.flow-node-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.flow-node-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.flow-chip {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary-dark);
}

.flow-chip-ce {
    background: #f0f2f5;
    color: var(--text-light);
}

/* ── Arrows ── */
.flow-arrow {
    width: 3px;
    height: 32px;
    background: linear-gradient(180deg, var(--text-light), #b0b8c1);
    position: relative;
    border-radius: 2px;
}

.flow-arrow::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 8px solid #b0b8c1;
}

/* ── Layer cards ── */
.flow-layer {
    width: 100%;
    max-width: 520px;
    border-radius: 12px;
    background: var(--white);
    box-shadow: 0 4px 20px rgba(0,0,0,0.07);
    overflow: hidden;
    position: relative;
}

.flow-layer-1 { border-top: 3px solid var(--primary); }
.flow-layer-2 { border-top: 3px solid var(--accent); }
.flow-layer-3 { border-top: 3px solid #8e44ad; }

.flow-layer-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.flow-layer-num {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(26,122,92,0.3);
}

.flow-num-blue {
    background: var(--accent);
    box-shadow: 0 2px 8px rgba(41,128,185,0.3);
}

.flow-num-purple {
    background: #8e44ad;
    box-shadow: 0 2px 8px rgba(142,68,173,0.3);
}

.flow-layer-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.flow-layer-sub {
    font-size: 0.82rem;
    color: var(--text-light);
    margin-top: 1px;
}

/* ── Substeps inside layers ── */
.flow-layer-body {
    padding: 10px 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.flow-substep {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 0.86rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: box-shadow 0.2s;
}

.flow-substep:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.flow-layer-1 .flow-substep { border-left: 3px solid rgba(26,122,92,0.4); }
.flow-layer-2 .flow-substep { border-left: 3px solid rgba(41,128,185,0.4); }
.flow-layer-3 .flow-substep { border-left: 3px solid rgba(142,68,173,0.4); }

.flow-substep-dot,
.flow-dot-blue,
.flow-dot-purple,
.flow-substep-dot-end {
    display: none;
}

.flow-substep-icon {
    flex-shrink: 0;
    color: var(--error);
}

.flow-substep-content {
    flex: 1;
}

.flow-substep-content strong {
    display: block;
    font-size: 0.86rem;
}

.flow-count {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--white);
    color: var(--text-light);
    border: 1px solid var(--border);
    margin-left: 2px;
    vertical-align: middle;
}

/* ── Safety branch (red arrow + stop badge) ── */
.flow-substep-safety {
    background: var(--error-bg);
    border: 1px solid #e6b0aa;
    border-left: 3px solid var(--error);
    grid-column: 1 / -1;
}

.flow-safety-arrow {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.flow-stop-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: var(--error);
    color: var(--white);
    box-shadow: 0 2px 6px rgba(192,57,43,0.3);
}

/* ── Output label between layers ── */
.flow-output-label {
    text-align: center;
    padding: 8px 16px 12px;
    font-size: 0.78rem;
    color: var(--text-light);
    font-family: "SF Mono", "Fira Code", monospace;
    letter-spacing: 0.5px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 600px) {
    .hero h1 { font-size: 1.7rem; }
    .hero { padding: 48px 0; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .auth-card { padding: 24px; }
    .flow-diagram { padding: 20px 8px; }
    .flow-layer-body { grid-template-columns: 1fr; padding: 8px 10px; }
    .flow-substep-safety { flex-wrap: wrap; }
    .flow-safety-arrow { margin-left: 0; margin-top: 6px; }
    .flow-node { padding: 16px; }
    .flow-layer-num { width: 34px; height: 34px; font-size: 0.95rem; }
}
