* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa; min-height: 100vh; color: #333;
}
.topbar {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    color: white; padding: 14px 24px;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.topbar-title { font-weight: 600; font-size: 1em; letter-spacing: 0.5px; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 0.9em; }
.badge { padding: 3px 10px; border-radius: 12px; font-size: 0.8em; font-weight: 500; }
.badge-ok { background: #e8f5e9; color: #2e7d32; }
.badge-warn { background: #fff3e0; color: #e65100; }
.badge-err { background: #ffcdd2; color: #c62828; }
.main { max-width: 800px; margin: 0 auto; padding: 24px 16px; }

/* === CARDS === */
.card {
    background: white; border-radius: 14px; padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06); margin-bottom: 16px;
    border: 2px solid transparent; transition: border-color 0.3s;
}
.card:focus-within { border-color: #667eea; }
.card-label { font-size: 1.1em; font-weight: 600; color: #1a237e; margin-bottom: 4px; }
.card-hint { font-size: 0.85em; color: #999; margin-bottom: 14px; }
.card h3 { font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.6px; color: #999; margin-bottom: 10px; }

/* === INPUT === */
.input-textarea {
    width: 100%; padding: 14px 16px; font-size: 1.05em;
    border: 1px solid #e0e0e0; border-radius: 10px;
    resize: none; font-family: inherit; line-height: 1.5; transition: border-color 0.2s;
}
.input-textarea:focus { outline: none; border-color: #667eea; }
.input-textarea::placeholder { color: #bbb; }
.input-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

/* === BUTTONS === */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; border: none; padding: 12px 32px; font-size: 1em;
    border-radius: 10px; cursor: pointer; font-weight: 600;
    transition: all 0.2s; min-height: 48px;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(102,126,234,0.4); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
    background: white; color: #667eea; border: 1.5px solid #667eea;
    padding: 8px 20px; font-size: 0.9em; border-radius: 8px;
    cursor: pointer; font-weight: 500; transition: all 0.2s;
}
.btn-secondary:hover { background: #f0f4ff; }
.btn-ghost {
    background: none; border: none; color: #667eea;
    cursor: pointer; font-size: 0.85em; padding: 4px 8px; text-decoration: underline;
}

/* === PROGRESS === */
.progress { display: flex; align-items: center; gap: 10px; font-size: 0.9em; color: #667eea; }
.spinner {
    width: 20px; height: 20px; border: 2.5px solid #e0e0e0;
    border-top-color: #667eea; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === ANIMATIONS === */
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* === INTERPRETATION BAR === */
.interp-bar {
    background: #f0f4ff; border-radius: 10px; padding: 14px 18px;
    display: flex; flex-wrap: wrap; gap: 12px 20px; font-size: 0.92em; margin-bottom: 16px;
}
.interp-item strong { color: #1a237e; }
.interp-actions { display: flex; gap: 8px; margin-top: 10px; width: 100%; }

/* === CODE LIST === */
.code-list { display: flex; flex-direction: column; gap: 6px; }
.code-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 8px; background: #fafbff; border: 1px solid #e8ecf4;
    cursor: pointer; transition: background 0.15s;
}
.code-item:hover { background: #f0f4ff; }
.code-item.selected { background: #e8f0fe; border-color: #667eea; }
.code-item:first-child { background: #f0f4ff; border-color: #c8d4f0; }
.code-badge {
    font-family: 'SF Mono', 'Courier New', monospace; font-weight: 700;
    font-size: 0.9em; color: #1a237e; min-width: 60px;
}
.code-text { font-size: 0.9em; color: #555; flex: 1; }
.code-group { font-size: 0.75em; color: #999; background: #f0f0f0; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.code-role { font-size: 0.78em; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.role-hd { background: #e3f2fd; color: #1565c0; }
.role-tillegg { background: #f3e5f5; color: #7b1fa2; }
.code-note { font-size: 0.78em; color: #888; }
.dagger-hint { background: #fff8e1 !important; border-color: #ffe082 !important; border-left: 3px solid #ffa000 !important; }
.dagger-hint .code-badge { color: #e65100; }

/* === DRG SECTION === */
.drg-card {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8ecff 100%);
    border-radius: 14px; padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06); margin-bottom: 16px;
}
.drg-header { font-size: 1.1em; font-weight: 600; color: #1a237e; margin-bottom: 16px; }
.drg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.drg-box { background: white; border-radius: 10px; padding: 16px; text-align: center; border: 1px solid #d0d8f0; }
.drg-box.cc { border-color: #667eea; border-width: 2px; }
.drg-label { font-size: 0.8em; color: #888; margin-bottom: 4px; }
.drg-code { font-size: 1.4em; font-weight: 700; color: #1a237e; }
.drg-weight { font-size: 0.85em; color: #666; margin-top: 2px; }
.drg-price { font-size: 1.1em; font-weight: 600; color: #333; margin-top: 4px; }
.drg-active {
    text-align: center; padding: 20px; border-radius: 12px;
    background: #f5f5f5; border: 2px solid #e0e0e0; margin-bottom: 12px;
}
.drg-active.drg-active-cc {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    border-color: #4caf50;
}
.drg-active .drg-active-label { font-size: 0.8em; color: #666; margin-bottom: 4px; }
.drg-active .drg-code { font-size: 2em; }
.drg-active .drg-price { font-size: 1.4em; }
.drg-box-current { border-color: #667eea; border-width: 2px; }
.drg-diff { text-align: center; font-size: 1.2em; font-weight: 700; color: #27ae60; padding: 8px; background: rgba(39,174,96,0.08); border-radius: 8px; }
.drg-diff-hint { color: #e65100; background: rgba(230,81,0,0.06); font-size: 0.9em; font-weight: 500; }

/* === CC QUESTIONS === */
.cc-question {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; border-radius: 10px; background: #fafbff;
    border: 1.5px solid #e8ecf4; margin-bottom: 8px; transition: all 0.2s;
}
.cc-question:hover { border-color: #c8d4f0; }
.cc-question.active { background: #e8f5e9; border-color: #4caf50; }
.cc-question.excluded { opacity: 0.5; text-decoration: line-through; }
.cc-q-label { flex: 1; font-size: 0.95em; }
.cc-q-label small { display: block; color: #999; font-size: 0.85em; margin-top: 2px; }
.cc-q-toggle {
    width: 52px; height: 28px; border-radius: 14px; border: none;
    background: #e0e0e0; cursor: pointer; position: relative; transition: background 0.2s;
    flex-shrink: 0;
}
.cc-q-toggle.on { background: #4caf50; }
.cc-q-toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%; background: white;
    transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.cc-q-toggle.on::after { transform: translateX(24px); }

/* === CC ICD PICKER === */
.cc-icd-picker {
    margin: 8px 0 8px 20px; padding: 10px 14px;
    background: #f9fbe7; border-radius: 8px; border: 1px solid #e6ee9c;
    display: none;
}
.cc-icd-picker.visible { display: block; }
.cc-icd-option {
    display: flex; align-items: center; gap: 8px; padding: 6px 0;
    font-size: 0.88em; cursor: pointer;
}
.cc-icd-option:hover { color: #1a237e; }
.cc-icd-option input { accent-color: #4caf50; }
.cc-icd-option .icd-code { font-family: monospace; font-weight: 600; }
.cc-icd-option.excluded { opacity: 0.4; text-decoration: line-through; }

/* === DETECTED CC (from text) === */
#cc-detected { border: 2px solid #c8e6c9; background: #f9fff9; }
#cc-detected .card-label { color: #2e7d32; }

/* === DIRECT CC SUGGESTIONS === */
.cc-suggest {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: 10px; background: #fafbff;
    border: 1.5px solid #e8ecf4; margin-bottom: 6px;
    cursor: pointer; transition: all 0.2s; user-select: none;
}
.cc-suggest:hover { border-color: #a5d6a7; background: #f1f8f1; }
.cc-suggest.added { background: #e8f5e9; border-color: #4caf50; }
.cc-suggest-btn {
    width: 32px; height: 32px; border-radius: 50%; border: 2px solid #bbb;
    background: white; font-size: 1.2em; line-height: 28px; text-align: center;
    cursor: pointer; transition: all 0.2s; flex-shrink: 0; color: #bbb;
}
.cc-suggest.added .cc-suggest-btn { background: #4caf50; border-color: #4caf50; color: white; }
.cc-suggest-code {
    font-family: 'SF Mono', 'Courier New', monospace; font-weight: 700;
    font-size: 0.9em; color: #1a237e; min-width: 55px;
}
.cc-suggest-text { flex: 1; font-size: 0.9em; color: #555; }
.cc-suggest-sev {
    font-size: 0.72em; font-weight: 600; padding: 2px 8px; border-radius: 10px;
    white-space: nowrap; flex-shrink: 0;
}
.cc-suggest-sev.major { background: #fce4ec; color: #c62828; }
.cc-suggest-sev.cc { background: #e8f5e9; color: #2e7d32; }
.cc-suggest-keyword {
    font-size: 0.78em; color: #888; margin-bottom: 8px; margin-top: 12px;
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.cc-suggest-keyword:first-child { margin-top: 0; }
.cc-suggest-alt-btn {
    background: none; border: none; color: #667eea; cursor: pointer;
    font-size: 0.8em; padding: 4px 8px; text-decoration: underline; flex-shrink: 0;
}
.cc-suggest-alts {
    margin: 0 0 8px 42px; padding: 8px 12px;
    background: #f9fbe7; border-radius: 8px; border: 1px solid #e6ee9c;
    display: none;
}
.cc-suggest-alts.visible { display: block; }
.cc-suggest-alt-item {
    display: flex; align-items: center; gap: 8px; padding: 5px 0;
    font-size: 0.85em; cursor: pointer; transition: background 0.1s;
}
.cc-suggest-alt-item:hover { color: #1a237e; }
.cc-suggest-alt-item .icd-code { font-family: monospace; font-weight: 600; min-width: 55px; }

/* === NEGATIVE FINDINGS === */
.negative-card {
    background: #fff8f0; border-radius: 14px; padding: 20px 24px;
    border: 1px solid #ffe0b2; margin-bottom: 16px;
}
.negative-card h3 { color: #e65100; margin-bottom: 12px; }
.neg-item {
    padding: 8px 0; border-bottom: 1px solid #fff3e0;
    font-size: 0.9em; color: #666;
}
.neg-item:last-child { border-bottom: none; }
.neg-item strong { color: #bf360c; }

/* === REASONING === */
.reasoning {
    font-size: 0.85em; color: #888; font-style: italic;
    padding: 10px 14px; background: #fafafa; border-radius: 8px; margin-top: 12px;
}

/* === MANUAL SEARCH FALLBACK === */
.manual-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid #eee; }
.search-input {
    width: 100%; padding: 10px 14px; font-size: 0.95em;
    border: 1px solid #e0e0e0; border-radius: 8px; font-family: inherit;
}
.search-input:focus { outline: none; border-color: #667eea; }
.search-results { max-height: 300px; overflow-y: auto; margin-top: 8px; }
.search-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px;
    border-radius: 6px; cursor: pointer; font-size: 0.9em;
}
.search-item:hover { background: #f0f4ff; }
.search-item .s-code { font-family: monospace; font-weight: 600; color: #1a237e; min-width: 55px; }
.search-item .s-region { font-size: 0.8em; color: #999; margin-left: auto; }

/* === MODAL === */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 200;
    align-items: center; justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: white; border-radius: 14px; padding: 28px;
    max-width: 420px; width: 90%;
}
.modal h3 { margin-bottom: 16px; color: #1a237e; }
.modal label { font-size: 0.85em; color: #666; }
.modal input[type="password"], .modal input[type="text"] {
    width: 100%; padding: 10px; border: 1px solid #ddd;
    border-radius: 8px; margin: 6px 0 16px; font-family: inherit;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* === ERROR === */
.error-msg {
    background: #fff3f3; color: #c62828; padding: 14px 18px;
    border-radius: 10px; border: 1px solid #ffcdd2; font-size: 0.95em; margin-bottom: 16px;
}

/* === SECTION TOGGLE === */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; padding: 4px 0;
}
.section-header .toggle-icon { transition: transform 0.2s; font-size: 0.8em; color: #999; }
.section-header.open .toggle-icon { transform: rotate(90deg); }
.section-body { overflow: hidden; transition: max-height 0.3s ease; }
.section-body.collapsed { max-height: 0 !important; }

/* === INTERPRETATION PILLS === */
.interp-pill {
    display: inline-block; padding: 4px 12px; border-radius: 16px;
    background: #e8ecff; color: #1a237e; font-size: 0.85em; font-weight: 500;
    white-space: nowrap;
}
.interp-pill-trauma { background: #fce4ec; color: #c62828; }
.interp-pill-elective { background: #e8f5e9; color: #2e7d32; }
.interp-pill-cc { background: #fff3e0; color: #e65100; }

/* === MANUAL SEARCH TOGGLE === */
.manual-toggle {
    display: inline-block; font-size: 0.85em; color: #667eea;
    text-decoration: none; cursor: pointer; margin-top: 12px;
}
.manual-toggle:hover { text-decoration: underline; }
.manual-content { margin-top: 10px; }

/* === REASONING TOGGLE === */
.reasoning-toggle {
    display: inline-block; font-size: 0.85em; color: #667eea;
    text-decoration: none; cursor: pointer; margin-top: 8px;
}
.reasoning-toggle:hover { text-decoration: underline; }


/* === RESPONSIVE === */
@media (max-width: 600px) {
    .main { padding: 12px 8px; }
    .card, .drg-card, .negative-card { padding: 18px; }
    .drg-grid { grid-template-columns: 1fr; }
    .interp-bar { flex-direction: column; gap: 6px; }
}
