:root {
    color-scheme: light;
    --canvas: #f3f6f7;
    --paper: #ffffff;
    --ink: #172b37;
    --muted: #526671;
    --line: #dbe4e7;
    --line-strong: #b3c2c9;
    --nav: #142c38;
    --nav-deep: #102530;
    --nav-text: #d6e3e8;
    --primary: #146b60;
    --primary-dark: #0d554c;
    --primary-soft: #e4f2ee;
    --danger: #922d36;
    --danger-soft: #fcf0f1;
    --focus: #006ba8;
    font-family: 'Segoe UI', system-ui, sans-serif;
    line-height: 1.5;
    font-size: 16px;
    color: var(--ink);
    background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
a { color: var(--primary-dark); text-underline-offset: 0.2em; }
a:hover { color: var(--primary); }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 4vw, 2.55rem); line-height: 1.12; font-weight: 700; letter-spacing: -0.035em; overflow-wrap: anywhere; }
h2 { font-size: 1.20rem; line-height: 1.3; font-weight: 690; }
h3 { font-size: 1.05rem; line-height: 1.4; font-weight: 680; }
h4 { font-size: 0.95rem; margin-bottom: 0.44rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
img { max-width: 100%; }
code { font-family: Consolas, ui-monospace, monospace; }

.sr-only, .visually-hidden, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link:focus { position: fixed; z-index: 5; inset: 0.8rem auto auto 0.8rem; padding: 0.55rem 0.9rem; background: var(--paper); border-radius: 0.45rem; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 14.25rem minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 2rem; padding: 1.9rem 1rem 1rem; color: var(--nav-text); background: var(--nav); }
.sidebar :focus-visible { outline-color: #8ed8d1; }
.brand { display: flex; align-items: center; gap: 0.7rem; width: fit-content; margin-left: 0.4rem; text-decoration: none; color: var(--paper); }
.brand:hover { color: var(--paper); }
.brand-mark { display: grid; place-items: center; flex: none; width: 2.65rem; height: 2.65rem; border: 1px solid #5d877f; border-radius: 0.7rem; color: #a5e1d4; background: #1e443f; }
.brand strong, .brand small, .account strong, .account small { display: block; }
.brand strong { font-size: 1.14rem; line-height: 1.18; letter-spacing: -0.015em; }
.brand small { color: #b6ccd4; font-size: 0.80rem; line-height: 1.25; }
.main-nav { display: flex; flex-direction: column; gap: 0.3rem; }
.main-nav a { display: flex; align-items: center; gap: 0.65rem; min-height: 2.65rem; padding: 0.56rem 0.7rem; border-radius: 0.5rem; color: var(--nav-text); text-decoration: none; font-size: 0.9rem; font-weight: 620; }
.main-nav a:hover { color: white; background: #294751; }
.main-nav a[aria-current] { color: white; background: #2b4d53; box-shadow: inset 0.2rem 0 #82c7b9; }
.main-nav svg, .logout svg { width: 1.2rem; height: 1.2rem; flex: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.account { display: flex; align-items: center; gap: 0.55rem; margin-top: auto; padding: 0.75rem 0.53rem 0.75rem 0.65rem; border-radius: 0.65rem; background: var(--nav-deep); }
.account-icon { display: grid; place-items: center; flex: none; width: 1.95rem; height: 1.95rem; border-radius: 50%; background: #32525c; color: white; font-size: 0.82rem; font-weight: 700; }
.account-label { min-width: 0; flex: 1 1 auto; }
.account strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: white; font-size: 0.8rem; }
.account small { color: #b6cbd5; font-size: 0.75rem; }
.logout { display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: 0.37rem; color: var(--nav-text); background: transparent; }
.logout:hover { color: white; background: #32525c; }
.main { min-width: 0; }
.main:focus { outline: 0; }
.main-inner { width: min(100%, 92rem); margin: 0 auto; padding: 2.35rem clamp(1.15rem, 3.5vw, 3.45rem) 3.5rem; display: flex; flex-direction: column; gap: 1.3rem; }

.guest .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
.guest .sidebar { position: static; display: block; height: auto; padding: 1.15rem clamp(1rem, 4vw, 3rem); }
.guest .brand { margin: 0; }
.guest .main { display: grid; align-items: start; }
.guest .main-inner { width: min(100%, 32rem); padding-top: clamp(2rem, 8vh, 5.5rem); }
.auth-panel { background: var(--paper); padding: clamp(1.25rem, 4vw, 2.25rem); border: 1px solid var(--line); border-radius: 1rem; box-shadow: 0 9px 26px #172b3709; }
.auth-panel header { display: grid; gap: 0.45rem; margin-bottom: 1.45rem; }
.auth-panel > h1, .auth-panel > .notice { margin-bottom: 1rem; }
.card:not(.auth-panel) { min-width: 0; padding: 1.15rem; border: 1px solid var(--line); border-radius: 0.9rem; background: var(--paper); }
.card:not(.auth-panel) > .actions { justify-content: space-between; }
.card:not(.auth-panel) > :not(:last-child) { margin-bottom: 0.85rem; }
.table-wrap { max-width: 100%; overflow-x: auto; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 0.9rem 1.5rem; padding: 0.15rem 0 0.15rem; }
.page-heading p { margin-top: 0.46rem; color: var(--muted); }
.study-heading > div { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem 0.95rem; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 0.9rem; background: var(--paper); box-shadow: 0 1px 2px #172b3707; scroll-margin-top: 1rem; }
.panel-heading { min-height: 3.7rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.8rem; padding: 0.94rem 1.2rem; border-bottom: 1px solid var(--line); }
.panel-heading > a { font-size: 0.89rem; font-weight: 600; }
.panel-body, .panel-footer { padding: 1.2rem; }
.panel-footer { border-top: 1px solid var(--line); background: #f9fbfb; border-radius: 0 0 0.85rem 0.85rem; }
.panel > .notice { margin: 1.2rem 1.2rem 0; }
.panel-footer + .panel-footer { border-radius: 0 0 0.85rem 0.85rem; }
.breadcrumbs { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 0.86rem; }
.breadcrumbs + .page-heading { margin-top: -0.55rem; }
.section-nav { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.section-nav a { display: inline-flex; min-height: 2.3rem; align-items: center; padding: 0.3rem 0.7rem; border: 1px solid var(--line); border-radius: 0.42rem; background: var(--paper); text-decoration: none; font-size: 0.86rem; font-weight: 650; }
.section-nav a:hover { border-color: var(--primary); background: var(--primary-soft); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.35rem, 1fr)); gap: 0.65rem; }
.summary-card { display: flex; flex-direction: column; justify-content: space-between; gap: 0.55rem; min-height: 6.1rem; padding: 0.78rem 0.85rem; color: var(--ink); border: 1px solid var(--line); border-radius: 0.7rem; background: var(--paper); text-decoration: none; }
.summary-card:hover, .summary-card.is-current { color: var(--ink); border-color: #62948a; background: #f4faf8; }
.summary-card.is-current { box-shadow: inset 0 -0.19rem var(--primary); }
.summary-label { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.79rem; font-weight: 650; }
.summary-card strong { font-size: 1.65rem; line-height: 1; font-variant-numeric: tabular-nums; }
.status-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; background: var(--status-dot, #637985); }
.status-badge { display: inline-flex; align-items: center; width: fit-content; min-height: 1.6rem; padding: 0.15rem 0.57rem; border-radius: 10rem; background: var(--status-surface, #edf2f4); color: var(--status-ink, #344e5b); font-size: 0.76rem; font-weight: 670; white-space: nowrap; }
.status-waiting { --status-dot: #876930; --status-surface: #fbf3dd; --status-ink: #614912; }
.status-in_progress { --status-dot: #316c95; --status-surface: #e6f2fa; --status-ink: #215575; }
.status-in_review { --status-dot: #7160a6; --status-surface: #f0eafa; --status-ink: #51417e; }
.status-approved { --status-dot: #a25b30; --status-surface: #fceee5; --status-ink: #823d15; }
.status-published { --status-dot: #237763; --status-surface: #e4f3eb; --status-ink: #155d49; }
.status-cancelled { --status-dot: #7d6266; --status-surface: #f4ecee; --status-ink: #6f4148; }
.identity { display: flex; flex-wrap: wrap; gap: 1rem 1.8rem; align-items: center; padding: 1rem 1.2rem; border: 1px solid #c0ded7; border-radius: 0.9rem; background: #ecf6f3; }
.identity-name { display: flex; flex-direction: column; gap: 0.14rem; }
.identity-name strong { font-size: 1.18rem; }
.identity-name > span, .identity dt { color: #3b6058; font-size: 0.77rem; font-weight: 680; }
.identity-name small { font-size: 0.84rem; color: #305750; }
.identity dl { display: flex; gap: 0.72rem 1.35rem; flex-wrap: wrap; margin: 0; }
.identity dd { margin: 0.16rem 0 0; font-size: 0.9rem; font-weight: 600; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.63rem; padding: 0.48rem 0.85rem; border: 1px solid transparent; border-radius: 0.45rem; text-decoration: none; text-align: center; font-size: 0.89rem; line-height: 1.25; font-weight: 670; }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-dark); color: white; }
.button.secondary { background: var(--paper); border-color: var(--line-strong); color: var(--ink); }
.button.secondary:hover { background: #edf5f4; border-color: var(--primary); color: var(--primary-dark); }
.button.quiet { color: var(--primary-dark); background: transparent; }
.button.quiet:hover { background: var(--primary-soft); }
.button.danger-button { background: var(--paper); border-color: #ecc9cd; color: var(--danger); }
.button.danger-button:hover { background: var(--danger-soft); border-color: #bd7580; }
.button.compact { min-height: 2.13rem; padding: 0.35rem 0.6rem; font-size: 0.82rem; }
.button:disabled { opacity: 0.56; }
.button:disabled:hover { pointer-events: none; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; }
.stack { display: grid; gap: 1rem; }
.compact-stack { gap: 0.5rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.split-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; gap: 1.2rem; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.7rem; padding: 0.95rem 1.2rem; border-bottom: 1px solid var(--line); }
.field { display: grid; align-content: start; gap: 0.35rem; min-width: 0; font-size: 0.89rem; }
.field > span, fieldset > legend { color: var(--ink); font-weight: 670; }
.field small { font-size: 0.79rem; color: var(--muted); font-weight: 400; }
.field > span > small { margin-left: 0.3rem; }
.field :is(input, select, textarea), input:not([type]), input:is([type='text'],[type='password'],[type='email']) { width: 100%; min-height: 2.62rem; min-width: 0; padding: 0.42rem 0.55rem; border: 1px solid var(--line-strong); border-radius: 0.42rem; background: var(--paper); color: var(--ink); }
.field textarea { resize: vertical; line-height: 1.5; }
.field textarea[readonly] { background: #f7f9fa; }
#hallazgos textarea {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
    scrollbar-gutter: stable;
}
.field input[type='file'] { padding: 0.3rem; }
.field input[type='file']::file-selector-button { margin-right: 0.55rem; padding: 0.35rem 0.55rem; border: 1px solid var(--line-strong); border-radius: 0.28rem; background: var(--canvas); color: var(--ink); font: inherit; cursor: pointer; }
.search-field { flex: 0 1 23rem; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; font-size: 0.88rem; color: var(--ink); cursor: pointer; }
.check input { width: 1.08rem; height: 1.08rem; margin: 0.13rem 0 0; flex: none; accent-color: var(--primary); }
.check-group, .report-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.check-group legend, .report-group legend { padding: 0; margin-bottom: 0.42rem; font-size: 0.92rem; }
.check-card { padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: 0.4rem; margin-bottom: 0.35rem; }
.check-card:has(input:checked) { background: var(--primary-soft); border-color: #8fbaaf; }
.report-group { display: grid; gap: 0.65rem; }
.report-meta { align-items: start; }
.transducer-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem 0.65rem; }
.transducer-group .field { grid-column: 1 / -1; }
.report-details { padding: 0.7rem; border: 1px solid var(--line); border-radius: 0.48rem; }
.report-details summary { cursor: pointer; font-weight: 650; }
.report-details[open] > summary { margin-bottom: 0.75rem; }
.report-details summary .muted { overflow-wrap: anywhere; font-weight: 400; }
.section-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(7.5rem, 13rem); align-items: start; gap: 0.75rem; padding: 0.7rem; background: #f7f9fa; border: 1px solid #e6edef; border-radius: 0.48rem; }

.notice { padding: 0.72rem 0.9rem; border: 1px solid #c1dad4; border-radius: 0.52rem; background: #eff8f5; color: #285b50; font-size: 0.89rem; }
.notice.danger, .notice.error { border-color: #eac5c9; color: #822834; background: var(--danger-soft); }
.notice.warning { border-color: #e8d5aa; color: #694a1e; background: #fcf5e7; }
.notice ul { margin: 0; padding-left: 1.2rem; }
.muted { font-size: 0.89rem; color: var(--muted); }
.save-status.is-error { color: var(--danger); }
.nowrap { white-space: nowrap; }
.table-scroll { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.89rem; }
th { background: #f7f9fa; color: var(--muted); font-size: 0.77rem; font-weight: 710; letter-spacing: 0.012em; white-space: nowrap; }
th, td { vertical-align: top; padding: 0.79rem 0.75rem; border-bottom: 1px solid var(--line); }
tr > :first-child { padding-left: 1.2rem; }
tr > :last-child { padding-right: 1.2rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
.table-subline { display: block; margin-top: 0.16rem; color: var(--muted); font-size: 0.82rem; }
.table-action { text-align: right; }
.table-action a { white-space: nowrap; margin-bottom: 0.22rem; }
.empty-state { color: var(--muted); padding: 1.5rem 1.2rem; font-size: 0.92rem; }
.event-list { padding: 0; margin: 0; list-style: none; }
.event-list li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 1.2rem; font-size: 0.83rem; border-bottom: 1px solid var(--line); }
.event-list li:last-child { border: 0; }
.event-list small { display: block; color: var(--muted); }
.event-list li > :last-child { color: var(--muted); text-align: right; }

.nested-section { display: grid; gap: 0.75rem; }
.nested-section + .nested-section { padding-top: 1rem; border-top: 1px solid var(--line); }
.nested-section > .button { justify-self: start; }
.record-status { font-size: 0.88rem; color: var(--muted); }
.record-status.is-recording { color: #912b37; font-weight: 670; }
.record-status.is-error { color: var(--danger); }
audio { width: min(100%, 28rem); }
.clinical-text { padding: 0.68rem 0.75rem; border: 1px solid var(--line); border-radius: 0.45rem; background: #f7f9fa; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.89rem; }
.report-passage { grid-template-columns: minmax(0, 1fr); }
.report-passage textarea { field-sizing: content; min-height: 3.25rem; max-height: 24rem; }
.report-passage .status-badge { justify-self: start; }
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; list-style: none; padding: 0; margin: 0; }
.photo-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 0.62rem; }
.photo-card.is-dragging { opacity: 0.45; }
.photo-card.is-drop-target { box-shadow: 0 0 0 2px var(--primary); }
.photo-preview { display: block; position: relative; aspect-ratio: 4/3; min-height: 8rem; max-height: 22rem; background: #152834; }
.photo-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center; }
.photo-preview:focus-visible { outline-offset: -3px; }
.photo-tools { padding: 0.55rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; font-size: 0.83rem; }
.revision { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; padding: 1rem 1.2rem; }
.revision + .revision, .panel-body + .revision-list { border-top: 1px solid var(--line); }
.revision h3 { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
.revision p, .revision details { color: var(--muted); margin-top: 0.2rem; font-size: 0.84rem; }
.revision summary { cursor: pointer; }
.hash { overflow-wrap: anywhere; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 11.4rem minmax(0, 1fr); }
    .sidebar { padding-left: 0.6rem; padding-right: 0.6rem; }
    .main-inner { padding-left: 1.15rem; padding-right: 1.15rem; }
    .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); align-items: center; gap: 0.7rem; padding: 0.7rem 0.72rem; }
    .brand { margin-left: 0; }
    .brand-mark { width: 2.25rem; height: 2.25rem; }
    .brand-mark svg { width: 1.7rem; height: 1.7rem; }
    .brand strong { font-size: 1rem; }
    .main-nav { grid-row: 2; grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 0.25rem; }
    .main-nav a { min-height: 2.18rem; padding: 0.35rem 0.45rem; gap: 0.35rem; font-size: 0.78rem; }
    .main-nav svg { width: 1rem; height: 1rem; }
    .account { grid-column: 2; grid-row: 1; margin: 0; padding: 0.3rem 0.35rem 0.3rem 0.5rem; }
    .account-icon { display: none; }
    .account-label { max-width: 6.7rem; }
    .main-inner { padding: 1.3rem 0.72rem 2.1rem; gap: 0.92rem; }
    .summary-grid { gap: 0.45rem; }
    .summary-card { min-height: 4.8rem; padding: 0.65rem; }
    .summary-card strong { font-size: 1.35rem; }
    .panel-heading, .panel-body, .panel-footer, .filters, .identity, .revision { padding-left: 0.82rem; padding-right: 0.82rem; }
    tr > :first-child { padding-left: 0.82rem; }
    tr > :last-child { padding-right: 0.82rem; }
}

@media (max-width: 420px) {
    .form-grid, .section-fields, .photo-grid { grid-template-columns: 1fr; }
    .filters .field { flex: 1 1 auto; }
}

@media (max-width: 600px) {
    .report-meta, .section-fields { grid-template-columns: minmax(0, 1fr); }
    :is(.study-exam, #dictado, #hallazgos) .field :is(input, select, textarea) { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; }
}
