/* === Variables & base === */
:root {
    color-scheme: dark light;
    --bg: #020617;
    --bg-card: #020617;
    --bg-card-soft: #020617;
    --accent: #38bdf8;
    --accent-soft: rgba(56, 189, 248, 0.18);
    --accent-strong: rgba(56, 189, 248, 0.45);
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --border-soft: rgba(148, 163, 184, 0.5);
    --border-strong: rgba(148, 163, 184, 0.8);
    --input-bg: rgba(15, 23, 42, 0.9);
    --danger: #f97373;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top, #0b1120, #020617 55%),
        radial-gradient(circle at bottom, #020617, #020617 70%);
    color: var(--text-main);
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 32px 12px;
}

/* === Layout & shell === */
.shell {
    width: 100%;
    max-width: 1160px;
    display: grid;
    grid-template-columns: minmax(0, 2.15fr) minmax(0, 1.4fr);
    gap: 20px;
    align-items: start;
}

.shell > .card {
    min-width: 0;
}

@media (max-width: 768px) {
    body {
        padding: 22px 10px 28px;
    }
    .shell {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* === Cards === */
.card {
    position: relative;
    border-radius: 22px;
    padding: 24px 22px 22px;
    background:
        radial-gradient(circle at top left, rgba(56, 189, 248, 0.14), transparent 60%),
        radial-gradient(circle at bottom right, rgba(129, 140, 248, 0.13), transparent 65%),
        radial-gradient(circle at top right, rgba(34, 197, 94, 0.08), transparent 65%),
        #020617;
    box-shadow:
        0 30px 80px -24px rgba(15, 23, 42, 0.95),
        0 0 0 1px rgba(148, 163, 184, 0.25);
    overflow: hidden;
}

.card::before {
    content: "";
    position: absolute;
    inset: -40%;
    background:
        radial-gradient(circle at 0% 10%, rgba(56, 189, 248, 0.25), transparent 65%),
        radial-gradient(circle at 100% 90%, rgba(52, 211, 153, 0.18), transparent 60%);
    opacity: 0.7;
    mix-blend-mode: screen;
    pointer-events: none;
}

.card-inner {
    position: relative;
    z-index: 1;
}

.card-secondary {
    position: sticky;
    top: 20px;
    border-radius: 22px;
    padding: 22px 20px 18px;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.22), transparent 65%),
        radial-gradient(circle at bottom right, rgba(8, 47, 73, 0.9), #020617);
    box-shadow:
        0 24px 70px -24px rgba(15, 23, 42, 0.95),
        0 0 0 1px rgba(129, 140, 248, 0.4);
    overflow: hidden;
}

.card-secondary::before {
    content: "";
    position: absolute;
    inset: -40%;
    background:
        radial-gradient(circle at 10% 0%, rgba(96, 165, 250, 0.3), transparent 60%),
        radial-gradient(circle at 100% 100%, rgba(147, 51, 234, 0.36), transparent 60%);
    opacity: 0.85;
    mix-blend-mode: screen;
    pointer-events: none;
}

.card-secondary-inner {
    position: relative;
    z-index: 1;
}

h1 {
    margin: 0 0 6px;
    font-size: 1.6rem;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 0 0 18px;
    color: var(--text-muted);
    font-size: 0.94rem;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.9));
    color: var(--text-main);
    font-size: 0.8rem;
    white-space: nowrap;
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.35);
}

.badge-soft {
    border-style: dashed;
    border-color: rgba(148, 163, 184, 0.7);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.8));
    color: var(--text-muted);
}

.badge-link {
    text-decoration: none;
    color: var(--accent);
    font-size: 0.8rem;
    padding: 4px 11px;
    border-radius: 999px;
    white-space: nowrap;
}
.badge-link:hover {
    color: var(--text-main);
    background: var(--accent-soft);
}

form {
    margin-top: 6px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
}

@media (max-width: 720px) {
    form {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* === Form & field groups === */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group.full {
    grid-column: 1 / -1;
}

label {
    font-size: 0.83rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.required-dot::after {
    content: " *";
    color: var(--accent);
}

.required-asterisk {
    color: var(--accent);
}

.inline-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* === Chips & template list === */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.7);
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-main);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.16s ease-out;
}

.chip input {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}

.chip:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
    transform: translateY(-0.5px);
}

.template-chip-wrap {
    display: inline-flex;
}

.template-chip-delete {
    margin-left: 4px;
    padding: 0 4px;
    min-width: 22px;
    height: 22px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.template-chip-delete:hover {
    color: var(--danger);
    background: rgba(249, 115, 115, 0.15);
}

.template-chip-grip {
    display: inline-block;
    margin-right: 2px;
    color: var(--text-muted);
    cursor: grab;
    font-size: 0.85em;
    vertical-align: middle;
}

.template-chip-wrap:active .template-chip-grip {
    cursor: grabbing;
}

.template-chip-wrap.template-dragging {
    opacity: 0.6;
}

.template-chip-wrap.template-drag-over {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 999px;
}

select,
input[type="text"] {
    width: 100%;
    border-radius: 11px;
    border: 1px solid var(--border-soft);
    background: var(--input-bg);
    color: var(--text-main);
    padding: 8px 11px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.16s ease-out;
}

select:focus,
input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow:
        0 0 0 1px var(--accent-soft),
        0 14px 36px -22px rgba(56, 189, 248, 0.9);
}

.hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.section-label {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 4px 0 8px;
}

.pill-section {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px dashed rgba(148, 163, 184, 0.8);
    background: rgba(15, 23, 42, 0.88);
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* === Procedure / CPT / ICD / group boxes === */
.procedure-master {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.procedure-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
}
@media (max-width: 900px) {
    .procedure-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}
.model-section {
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 14px 16px;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.88));
    margin-bottom: 12px;
}
.model-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.group-box {
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 10px 11px 9px;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.92));
}
.group-title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}
details.icd-expandable summary {
    list-style: none;
}
details.icd-expandable summary::-webkit-details-marker {
    display: none;
}
details.icd-expandable summary::before {
    content: '▸ ';
    font-size: 0.75em;
}
details.icd-expandable[open] summary::before {
    content: '▾ ';
}

.medications-other-details summary {
    list-style: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.medications-other-details summary::-webkit-details-marker {
    display: none;
}
.medications-other-details summary::before {
    content: '▸ ';
    font-size: 0.75em;
}
.medications-other-details[open] summary::before {
    content: '▾ ';
}

.comorbidities-details summary {
    list-style: none;
    cursor: pointer;
}
.comorbidities-details summary::-webkit-details-marker {
    display: none;
}
.comorbidities-details summary::before {
    content: '▸ ';
    font-size: 0.75em;
    margin-right: 4px;
}
.comorbidities-details[open] summary::before {
    content: '▾ ';
}

.group-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.group-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.7);
    background: rgba(15, 23, 42, 0.96);
    color: var(--text-main);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.16s ease-out;
}

.group-chip input {
    width: 13px;
    height: 13px;
    accent-color: var(--accent);
}

.group-chip:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
    transform: translateY(-0.5px);
}

.pill-diopter {
    margin-top: 4px;
}

.laterality-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 9px;
}

/* When Lasik is selected, Laterality is hidden and value OU is submitted */
.field-laterality.laterality-hidden-for-lasik {
    display: none;
}

/* === Submit row === */
.submit-row {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}

.submit-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

button[type="submit"] {
    border-radius: 999px;
    border: 0;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    background: radial-gradient(circle at 0% 0%, #38bdf8, #0ea5e9);
    color: #0b1120;
    box-shadow:
        0 18px 45px -18px rgba(56, 189, 248, 0.9),
        0 0 0 1px rgba(8, 47, 73, 0.8);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease-out;
}

button[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow:
        0 22px 56px -22px rgba(56, 189, 248, 1),
        0 0 0 1px rgba(8, 47, 73, 1);
}

.submit-icon {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 2px solid #0b1120;
    box-shadow: 0 0 0 2px rgba(8, 47, 73, 0.8);
    position: relative;
}

.submit-icon::after {
    content: "";
    position: absolute;
    inset: 2px 3px 5px 3px;
    border-left: 2px solid #0b1120;
    border-bottom: 2px solid #0b1120;
    transform: rotate(-40deg);
}

.submit-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.submit-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot-soft {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.4);
}

.error-text {
    display: none;
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 2px;
}

.field-group.has-error select,
.field-group.has-error input[type="text"] {
    border-color: var(--danger);
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.35);
}

.field-group.has-error .error-text {
    display: block;
}

.procedure-category-box.has-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.35);
}

.mini-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.7);
    background: rgba(15, 23, 42, 0.95);
    font-size: 0.74rem;
    color: var(--text-muted);
}

.mini-swatch {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    background: linear-gradient(135deg, #38bdf8, #22c55e);
}

/* === Selected options pane === */
.summary-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 10px 18px;
    margin-top: 10px;
}

#selected-options-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}

#selected-options-content .summary-row {
    display: block;
}

#selected-options-content .summary-row .summary-label {
    display: block;
    margin-bottom: 2px;
}

#selected-options-content .summary-row .summary-value {
    display: block;
    min-height: 1.2em;
}

#selected-options-content .summary-value-multiline {
    word-break: break-word;
    white-space: pre-wrap;
}

.summary-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.summary-value {
    font-size: 0.95rem;
    color: #e5e7eb;
}

.summary-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.7);
    font-size: 0.78rem;
    color: var(--text-muted);
}

.surgeon-pill {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.8);
    font-size: 0.78rem;
}

.surgeon-color {
    width: 7px;
    height: 18px;
    border-radius: 999px;
    background: linear-gradient(180deg, #38bdf8, #22c55e);
}

.summary-divider {
    margin: 12px 0 10px;
    height: 1px;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0), rgba(148, 163, 184, 0.65), rgba(148, 163, 184, 0));
    opacity: 0.8;
}

.summary-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.summary-footer span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.summary-badge {
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px dashed rgba(148, 163, 184, 0.9);
    background: rgba(15, 23, 42, 0.95);
}

/* Routing flowchart */
.flow-title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.flowchart {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}
.flowchart svg {
    display: block;
    width: 100%;
    height: auto;
}
.flow-node {
    fill: rgba(15, 23, 42, 0.95);
    stroke: rgba(148, 163, 184, 0.6);
    stroke-width: 1.2;
    rx: 8;
    ry: 8;
}
.flow-node.start { fill: rgba(56, 189, 248, 0.25); stroke: rgba(56, 189, 248, 0.7); }
.flow-node.end { fill: rgba(34, 197, 94, 0.2); stroke: rgba(34, 197, 94, 0.7); }
.flow-node.decision { fill: rgba(129, 140, 248, 0.2); stroke: rgba(129, 140, 248, 0.7); }
.flow-edge {
    fill: none;
    stroke: rgba(148, 163, 184, 0.5);
    stroke-width: 1.5;
    marker-end: url(#flow-arrow);
}
.flow-label {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 11px;
    fill: var(--text-main);
    text-anchor: middle;
    dominant-baseline: middle;
}
.flow-label.small {
    font-size: 9px;
    fill: var(--text-muted);
}
.flow-note {
    font-size: 9px;
    fill: var(--text-muted);
    font-style: italic;
}

/* Submit overlay: full-screen status while posting */
.submit-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(6px);
}
.submit-overlay[hidden] {
    display: none !important;
}
.submit-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 28px 40px;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(148, 163, 184, 0.2);
}
.submit-overlay-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(148, 163, 184, 0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: submit-spin 0.7s linear infinite;
}
@keyframes submit-spin {
    to { transform: rotate(360deg); }
}
.submit-overlay-text {
    margin: 0;
    font-size: 1rem;
    color: var(--text-main);
}
