:root {
  --structural: #0f3d4a;
  --action: #156677;
  --text: #17272b;
  --muted: #586d73;
  --background: #f6f4f1;
  --surface: #fff;
  --border: #d6d8d3;
  --accent: #d95016; /* solo foco */
  --petroleo-hondo: #0a2c36;
  --cobre: #a8552a;
  --cobre-claro: #e0a77d;
  --papel: #f6f4f1;
  --success: #1e6b48;
  --warning: #8a5a00;
  --danger: #a52a2a;
  --info: #15647a;
  --radius: 7px;
  --shadow: 0 1px 2px rgb(15 61 74 / 8%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
  font-size: 16px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--background); }
a { color: var(--action); text-decoration-thickness: .08em; text-underline-offset: .16em; }
a:visited { color: var(--action); }
a:hover { text-decoration-thickness: .14em; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 3px;
}

.topbar a:focus-visible, .topbar button:focus-visible { outline-color: #fff; }
.skip-link { position: fixed; left: -9999px; top: 8px; z-index: 100; padding: .65rem 1rem; background: var(--surface); color: var(--text); }
.skip-link:focus { left: 1rem; }
.topbar { min-height: 60px; padding: 0 clamp(1rem, 3vw, 2.5rem); background: var(--structural); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { min-height: 44px; display: inline-flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; font-size: 1.25rem; font-weight: 600; letter-spacing: .02em; }
.brand:visited { color: #fff; }
.brand-mark { width: 34px; height: 34px; flex: 0 0 34px; object-fit: contain; }
.user-menu { display: flex; align-items: center; gap: 1rem; }
.user-menu form { margin: 0; }
.user-copy { display: grid; text-align: right; line-height: 1.25; }
.user-copy small { color: #d6e6eb; }

.organization-context { min-height: 92px; padding: .65rem clamp(1rem, 3vw, 2.5rem); background: #fbfaf8; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); display: grid; grid-template-columns: minmax(220px, 1fr) minmax(560px, 720px) auto; align-items: center; gap: clamp(1rem, 2vw, 2rem); }
.organization-context > div { display: grid; }
.organization-context strong { font-size: 1.02rem; }
.eyebrow { color: var(--muted); font-size: .78rem; font-weight: 720; letter-spacing: .06em; text-transform: uppercase; }
.context-rut { color: var(--muted); font-variant-numeric: tabular-nums; }
.context-period { padding-left: 1.25rem; border-left: 3px solid var(--action); }
.context-change { min-height: 44px; display: inline-flex; align-items: center; }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.app-shell-single { grid-template-columns: minmax(0, 1fr); }
.sidebar { min-height: calc(100vh - 136px); padding: 1.5rem 1rem; border-right: 1px solid var(--border); background: #f1efea; }
.local-nav { display: grid; gap: .2rem; }
.local-nav a { min-height: 44px; padding: .65rem .75rem; border-radius: var(--radius); display: flex; align-items: center; gap: .7rem; color: #294952; text-decoration: none; font-weight: 620; }
.local-nav a span { width: 1.1rem; color: var(--muted); text-align: center; }
.local-nav a:hover { background: #e8e6df; }
.local-nav a[aria-current="page"] { background: #dceef3; color: var(--structural); box-shadow: inset 3px 0 var(--structural); }
.mobile-section-menu { display: none; }
.content-column { min-width: 0; }
.breadcrumb { padding: 1rem clamp(1rem, 3vw, 2rem) 0; }
.breadcrumb ol { display: flex; flex-wrap: wrap; gap: .45rem; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: .9rem; }
.breadcrumb li:not(:last-child)::after { content: "/"; margin-left: .45rem; color: #81959a; }
.breadcrumb a { color: var(--muted); }
main { padding: 1.25rem clamp(1rem, 3vw, 2rem) 3rem; }

h1, h2, h3 { color: var(--structural); line-height: 1.2; }
h1 { margin: .25rem 0 .45rem; font-size: clamp(1.75rem, 3vw, 2.25rem); font-weight: 650; letter-spacing: -.01em; }
h2 { margin: 0 0 .35rem; font-size: 1.25rem; }
p { margin-top: .35rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; margin-bottom: 1.5rem; }
.page-heading p, .section-heading p { color: var(--muted); margin-bottom: 0; }
.page-actions, .form-actions { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
.page-actions { justify-content: flex-end; }

.period-navigation { min-width: 0; padding: 0 clamp(.75rem, 1.5vw, 1.25rem); display: grid; grid-template-columns: minmax(140px, .9fr) minmax(230px, 1.25fr) minmax(140px, .9fr); align-items: stretch; gap: .35rem; border-left: 1px solid #cfe0e5; border-right: 1px solid #cfe0e5; }
.period-step { min-height: 58px; padding: .35rem .5rem; display: flex; align-items: center; gap: .55rem; color: var(--structural); border-radius: 5px; text-decoration: none; transition: background-color .15s ease, box-shadow .15s ease; }
.period-step:visited { color: var(--structural); }
.period-step:hover { background: #f1efea; box-shadow: inset 0 0 0 1px var(--border); }
.period-step > span:not(.period-step-icon) { min-width: 0; display: grid; }
.period-step small { color: var(--muted); font-size: .76rem; line-height: 1.25; }
.period-step strong { overflow: hidden; font-size: .95rem; text-overflow: ellipsis; white-space: nowrap; }
.period-step-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; color: var(--action); border: 1px solid #b7d3db; border-radius: 50%; font-size: 1.08rem; line-height: 1; }
.period-step-next { justify-content: flex-end; text-align: right; }
.period-step-previous { grid-column: 1; grid-row: 1; }
.period-step-next { grid-column: 3; grid-row: 1; }
.period-selector { grid-column: 2; grid-row: 1; position: relative; min-width: 0; padding: .25rem .55rem .4rem; background: #eeece6; border-radius: 5px; }
.period-selector summary { list-style: none; display: grid; gap: .2rem; cursor: pointer; }
.period-selector summary::-webkit-details-marker { display: none; }
.period-selector-label, .period-picker-year label { color: var(--muted); font-size: .76rem; font-weight: 720; }
.period-selector-value { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 44px; padding: .55rem .75rem; color: var(--structural); border: 1px solid #82a0a8; border-radius: 5px; background: var(--surface); }
.period-selector-value::after { content: ""; width: .45rem; height: .45rem; flex: 0 0 .45rem; border: solid var(--action); border-width: 0 2px 2px 0; transform: rotate(45deg); margin: -.2rem .15rem 0 0; }
.period-selector[open] .period-selector-value::after { transform: rotate(225deg); margin-top: .2rem; }
.period-selector summary:hover .period-selector-value { border-color: var(--action); }
.period-picker-panel { position: absolute; z-index: 5; top: calc(100% + .4rem); left: 50%; transform: translateX(-50%); width: min(26rem, calc(100vw - 2rem)); padding: .85rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.period-picker-year { display: flex; align-items: flex-end; justify-content: center; gap: .5rem; margin-bottom: .75rem; }
.period-picker-year label { display: block; margin-bottom: .2rem; }
.period-picker-year select { width: 7rem; min-height: 44px; padding: .45rem .65rem; text-align: center; font: inherit; font-weight: 700; color: var(--structural); border: 1px solid #82a0a8; border-radius: 5px; }
.period-picker-months { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; overflow: hidden; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); }
.period-picker-panel button { padding: .4rem .25rem; color: var(--structural); background: var(--surface); border-color: var(--border); }
.period-picker-panel button[hidden] { display: none; }
.period-picker-year button { min-width: 44px; }
.period-picker-panel button:hover:not(:disabled) { border-color: var(--action); }
.period-picker-months button { width: 100%; border: 0; border-radius: 0; }
.period-picker-months button:hover:not(:disabled) { background: #e7f0f2; }
.period-picker-months button:focus-visible { outline-offset: -3px; }
.period-picker-months button:disabled { color: var(--muted); background: #eeece6; cursor: default; }
.period-picker-months button.period-month-before-history { background: var(--surface); }
.period-month-before-history span { visibility: hidden; }
.period-month-short { display: none; }
.period-picker-empty { text-align: center; color: var(--muted); }
.period-picker-months button[aria-current]:not(:disabled) { color: #fff; background: var(--action); border-color: var(--action); }
.period-picker-year button:disabled { opacity: .45; cursor: default; }

.button, button { min-height: 44px; padding: .62rem 1rem; border: 1px solid transparent; border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; font-weight: 680; cursor: pointer; text-decoration: none; }
.button-primary { background: var(--action); color: #fff; }
.button-primary:visited { color: #fff; }
.button-primary:hover { background: #0f5866; }
.button-secondary { background: var(--surface); color: var(--action); border-color: var(--action); }
.button-secondary:visited { color: var(--action); }
.button-tertiary { background: transparent; color: var(--action); border-color: var(--border); }
.button-tertiary:visited { color: var(--action); }
.button-on-dark { color: #fff; border-color: #8caeb8; }
.button-on-dark:visited { color: #fff; }
button:disabled, .button[aria-disabled="true"] { opacity: .58; cursor: wait; }

.primary-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.primary-metrics article { min-height: 130px; padding: 1.15rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; align-content: center; }
.primary-metrics span, .tax-band span { color: var(--muted); font-weight: 650; }
.primary-metrics strong { margin: .2rem 0; color: var(--structural); font-size: clamp(1.65rem, 3vw, 2.15rem); font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums lining-nums; }
.primary-metrics small { color: var(--muted); }
.metric-difference { border-top: 3px solid var(--structural) !important; }
.inline-guidance { padding: .75rem 1rem; color: var(--info); background: #eef8fb; border-radius: var(--radius); }
.tax-band { margin-top: 1rem; padding: .8rem 1.25rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; background: #eeece6; border-radius: var(--radius); }
.tax-band div { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.tax-band strong, .amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.section-block { margin-top: 2rem; }
.section-heading { margin-bottom: .85rem; display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.record-count { color: var(--muted); font-size: .9rem; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.status-card { min-height: 80px; padding: .85rem; border-radius: var(--radius); display: flex; align-items: center; gap: .75rem; }
.status-card > span { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center; border: 2px solid currentColor; border-radius: 50%; font-weight: 800; }
.status-card div { display: grid; }
.status-card small { color: var(--muted); }
.status-card-link { color: inherit; text-decoration: none; transition: box-shadow .15s ease, transform .15s ease; }
.status-card-link:hover { box-shadow: inset 0 0 0 2px currentColor; transform: translateY(-1px); }
.status-card-link:focus-visible { outline: 3px solid var(--action); outline-offset: 3px; }
.status-card-link.is-active { box-shadow: inset 0 0 0 2px currentColor; }
.status-warning { background: #fff8e8; color: var(--warning); }
.status-danger { background: #fff0f0; color: var(--danger); }
.status-neutral { background: #edf2f3; color: #4f6368; }
.status-info { background: #edf8fb; color: var(--info); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .78rem .85rem; border-bottom: 1px solid #dce5e7; text-align: left; vertical-align: top; }
th { color: #344f56; background: #f3f1ec; font-size: .88rem; letter-spacing: .015em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #faf9f6; }
.detail-cell { min-width: 250px; }
.badge { width: fit-content; padding: .22rem .5rem; border-radius: 999px; display: inline-flex; gap: .25rem; align-items: center; font-size: .86rem; font-weight: 680; white-space: nowrap; }
.badge-success { color: var(--success); background: #e7f5ed; }
.badge-warning { color: var(--warning); background: #fff4d6; }
.badge-danger { color: var(--danger); background: #ffe8e8; }
.badge-info { color: var(--info); background: #e5f4f8; }
.empty-state { min-height: 160px; display: grid; place-content: center; justify-items: center; gap: .3rem; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--structural); font-size: 1.08rem; }

.functional-panels { margin-top: 2rem; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.action-panel { padding: 1.15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.action-panel p { color: var(--muted); min-height: 3rem; }
.notice, .errors { margin: 0 0 1rem; padding: .9rem 1rem; border-left: 4px solid var(--action); border-radius: 0 var(--radius) var(--radius) 0; background: #eaf7fa; }
.notice-error, .errors { border-color: var(--danger); background: #fff0f0; }
.notice-success { border-color: var(--success); background: #eaf7ef; }
.errors h2 { font-size: 1.05rem; }

.form-card { max-width: 850px; padding: clamp(1rem, 3vw, 1.5rem); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card fieldset { margin: 0 0 1.6rem; padding: 0 0 1.5rem; border: 0; border-bottom: 1px solid var(--border); }
.form-card fieldset:last-of-type { border-bottom: 0; }
.form-card legend { margin-bottom: .9rem; color: var(--structural); font-size: 1.12rem; font-weight: 730; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.field { display: grid; gap: .35rem; }
.field label, .form-card > p > label { display: block; margin-bottom: .3rem; font-weight: 680; }
.field input, .form-card input:not([type="checkbox"]), .form-card select, .form-card textarea { width: 100%; min-height: 44px; padding: .62rem .7rem; color: var(--text); border: 1px solid #82969b; border-radius: 6px; background: #fff; }
.form-card textarea { min-height: 100px; }
.form-card > p { max-width: 650px; margin-bottom: 1rem; }
.help-text { display: block; color: var(--muted); font-size: .88rem; }
.field-error-text { color: var(--danger); }
.field-error input { border-color: var(--danger); }
.choice-stack { display: grid; gap: .7rem; }
.choice-control { min-height: 58px; padding: .75rem; display: flex; align-items: flex-start; gap: .8rem; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.choice-control:hover { background: #f8fbfc; }
.choice-control input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--action); }
.choice-control span { display: grid; }
.choice-control small { color: var(--muted); }
.form-actions { margin-top: 1.25rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.cards article { padding: 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.cards h2 { font-size: 1.12rem; }
.state { display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .5rem; border-radius: 999px; font-size: .88rem; font-weight: 680; }
.ok { color: var(--success); background: #e7f5ed; }
.bad { color: var(--danger); background: #ffe8e8; }

.import-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin: 1rem 0; }
.import-summary div { padding: .85rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: grid; }
.import-summary strong { font-size: 1.35rem; color: var(--structural); font-variant-numeric: tabular-nums; }
.warning-list, .error-list { margin: .4rem 0 0; padding-left: 1.2rem; }
.preview-groups { display: grid; gap: 1.5rem; }
.filename { overflow-wrap: anywhere; }

.export-dialog { width: min(1450px, calc(100vw - 2rem)); height: min(900px, calc(100vh - 2rem)); max-width: none; max-height: none; padding: 0; color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 20px 70px rgb(15 61 74 / 24%); }
.export-dialog [hidden] { display: none !important; }
.export-dialog::backdrop { background: rgb(7 35 43 / 58%); }
.export-dialog[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.export-dialog-header, .export-dialog-footer { padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--surface); }
.export-dialog-header { border-bottom: 1px solid var(--border); }
.export-dialog-header h2 { margin-bottom: 0; }
.export-dialog-footer { justify-content: flex-end; border-top: 1px solid var(--border); }
.dialog-close { width: 44px; min-width: 44px; padding: 0; color: var(--structural); border-color: var(--border); background: transparent; font-size: 1.7rem; line-height: 1; }
.export-dialog-body { min-height: 0; padding: 1rem 1.25rem; overflow: auto; background: var(--background); }
.export-loading { min-height: 180px; display: grid; place-items: center; color: var(--muted); }
.export-context { margin: 0 0 1rem; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.export-context div { padding: .7rem .8rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.export-context dt { color: var(--muted); font-size: .82rem; font-weight: 680; }
.export-context dd { margin: .15rem 0 0; color: var(--structural); font-weight: 720; }
.export-excluded { color: var(--warning); font-weight: 650; }
.export-actions { margin: 1rem 0 .7rem; display: flex; flex-wrap: wrap; gap: .55rem; }
.export-feedback { min-height: 1.5rem; margin: .4rem 0; color: var(--muted); }
.export-grid-wrap { max-height: min(55vh, 560px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.export-grid { min-width: 1450px; user-select: none; outline: none; }
.export-grid th { position: sticky; top: 0; z-index: 2; }
.export-grid th, .export-grid td { cursor: cell; }
.export-grid td:nth-child(8) { min-width: 300px; white-space: normal; }
.export-grid .is-selected { background: #d9f1f7; box-shadow: inset 0 0 0 1px #78b8ca; }
.export-grid .is-active { position: relative; box-shadow: inset 0 0 0 3px var(--action); }
.export-grid:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.export-empty { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.button.is-disabled { opacity: .58; pointer-events: none; }
.clipboard-fallback { position: fixed; left: -9999px; top: 0; }

@media (max-width: 1050px) {
  .organization-context { grid-template-columns: minmax(220px, 1fr) auto; }
  .period-navigation { grid-column: 1 / -1; grid-row: 2; border: 0; border-top: 1px solid var(--border); padding: .55rem 0 0; }
  .context-change { grid-column: 2; grid-row: 1; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .functional-panels { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 800px) {
  .user-copy { display: none; }
  .organization-context { grid-template-columns: 1fr auto; gap: .75rem; }
  .context-period { grid-column: 1; grid-row: 2; padding: 0; border: 0; }
  .context-change { grid-column: 2; grid-row: 1 / span 2; }
  .sidebar { display: none; }
  .app-shell { display: block; }
  .mobile-section-menu { display: block; padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
  .mobile-section-menu summary { min-height: 44px; display: flex; align-items: center; font-weight: 680; cursor: pointer; }
  .mobile-section-menu .local-nav { padding: .5rem 0; }
  .page-heading { display: grid; }
  .page-actions { justify-content: start; }
  .period-navigation { grid-column: 1 / -1; grid-row: 2; grid-template-columns: 1fr 1fr; }
  .period-selector { grid-column: 1 / -1; grid-row: 1; }
  .period-step-previous, .period-step-next { grid-row: 2; }
  .period-step-next { grid-column: 2; }
  .primary-metrics { grid-template-columns: 1fr; }
  .primary-metrics article { min-height: 105px; }
  .tax-band { grid-template-columns: 1fr; }
  .tax-band div { border-bottom: 1px solid #cadbe0; padding-bottom: .45rem; }
  .tax-band div:last-child { border: 0; padding-bottom: 0; }
  .import-summary { grid-template-columns: repeat(2, 1fr); }
  .export-context { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .export-dialog { width: 100%; height: 100vh; border: 0; border-radius: 0; }
}

@media (max-width: 560px) {
  .organization-context { display: grid; grid-template-columns: 1fr; }
  .context-change, .context-period { grid-column: 1; grid-row: auto; }
  .context-change { min-height: 44px; }
  .status-grid, .functional-panels, .form-grid, .import-summary { grid-template-columns: 1fr; }
  .page-actions .button, .form-actions .button { width: 100%; }
  .period-navigation { grid-column: 1; grid-row: auto; grid-template-columns: 1fr; }
  .period-selector { grid-column: 1; }
  .period-step-previous, .period-step-next { grid-row: auto; }
  .period-step-next { grid-column: 1; text-align: left; }
  .period-picker-panel { width: min(100%, 26rem); padding: .65rem; }
  .period-month-full { display: none; }
  .period-month-short { display: inline; }
  .period-picker-months button { padding-inline: .15rem; font-size: .875rem; }
  .period-step-next > span:first-child { order: 2; }
  .period-step-next .period-step-icon { order: 1; }
  th, td { min-width: 120px; white-space: normal; }
  .amount { min-width: 120px; }
  .export-context { grid-template-columns: 1fr; }
  .export-actions .button { width: 100%; }
}

/* Consulta de contribuyente por RUT (ADR 0007) */
.rut-lookup { margin-top: 1rem; }
.rut-lookup-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.rut-lookup-bar .help-text { flex: 1 1 18rem; margin: 0; }
.rut-lookup [data-tone="error"] { color: var(--danger); }
.rut-lookup [data-tone="warning"] { color: var(--warning); }
.rut-lookup [data-tone="success"] { color: var(--success); }
.lookup-preview { margin-top: 1rem; padding: 1rem; border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: 0 var(--radius) var(--radius) 0; background: #f7fbfc; }
.lookup-preview:focus { outline: 3px solid var(--accent); outline-offset: 3px; }
.lookup-preview-heading h3 { margin: 0; color: var(--structural); font-size: 1.02rem; }
.lookup-provenance { margin: .2rem 0 .6rem; color: var(--muted); font-size: .82rem; }
.lookup-reference { margin: 1rem 0 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; }
.lookup-reference > p { grid-column: 1 / -1; margin: 0; }
.lookup-reference dt { color: var(--muted); font-size: .82rem; font-weight: 680; }
.lookup-reference dd { margin: .1rem 0 0; overflow-wrap: anywhere; white-space: pre-line; }
.rut-update { margin-top: 2rem; }
.rut-update h2 { margin: 0 0 .35rem; font-size: 1.12rem; color: var(--structural); }
.lookup-diff th[scope="row"] { font-weight: 680; }
.lookup-diff .is-different { color: var(--structural); font-weight: 650; }
.lookup-action { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.lookup-action label { display: inline-flex; align-items: center; gap: .35rem; min-height: 44px; cursor: pointer; }
.lookup-confirm { margin-top: 1rem; padding: .9rem 1rem; border-left: 4px solid var(--warning); background: #fff8eb; border-radius: 0 var(--radius) var(--radius) 0; }
.lookup-confirm p { margin: 0 0 .5rem; }
.lookup-collection { margin: 1rem 0 0; padding: 0; border: 0; }
.lookup-collection legend, .lookup-collection h4 { margin: 0 0 .35rem; color: var(--structural); font-size: .98rem; font-weight: 700; }
.lookup-choices { display: grid; gap: .35rem; }
.lookup-choices-scroll { max-height: 22rem; overflow: auto; }
.choice-inline { display: flex; align-items: flex-start; gap: .5rem; min-height: 44px; cursor: pointer; }
.choice-inline input { margin-top: .3rem; }
.button-link { padding: 0; border: 0; background: none; color: var(--action); text-decoration: underline; cursor: pointer; font: inherit; min-height: 0; }
.public-data { margin-top: 1rem; display: grid; gap: .5rem; }
.public-data summary { cursor: pointer; font-weight: 680; color: var(--structural); }
.public-data-list { margin: .4rem 0 0; padding-left: 1.2rem; display: grid; gap: .25rem; }
@media (max-width: 560px) {
  .lookup-reference { grid-template-columns: 1fr; }
  .rut-lookup-bar .button { width: 100%; }
}

/* Interior · iteración 2 de identidad (mesa BPO 2026-11-04) */
.topbar { border-bottom: 2px solid var(--cobre-claro); }
td, .amount, .context-rut, .period-step strong, .import-summary strong { font-variant-numeric: tabular-nums lining-nums; }
td.amount { font-weight: 600; }
.primary-metrics .currency { margin-right: .15em; color: var(--muted); font-size: .7em; font-weight: 600; }
/* El cuadre: único lugar del motivo en el interior, junto a estados vacíos. */
.empty-state::before { content: ""; width: 48px; height: 48px; margin-bottom: .5rem; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%23d6d8d3' stroke-width='1.5'%3E%3Crect x='1' y='1' width='14' height='14'/%3E%3Crect x='18' y='2' width='14' height='14'/%3E%3Crect x='34' y='0' width='14' height='14'/%3E%3Crect x='0' y='18' width='14' height='14'/%3E%3Crect x='19' y='17' width='14' height='14'/%3E%3Crect x='1' y='34' width='14' height='14'/%3E%3Crect x='17' y='33' width='14' height='14'/%3E%3Crect x='33' y='34' width='14' height='14'/%3E%3C/g%3E%3Crect x='33.75' y='16.75' width='13.5' height='13.5' fill='none' stroke='%23e0a77d' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat center / contain; }
.table-scroll-hint { display: none; margin: 0 0 .4rem; color: var(--muted); font-size: .875rem; }
.table-scroll-hint.is-visible { display: block; }
.table-wrap:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (max-width: 560px) {
  .table-wrap.is-scrollable th:first-child, .table-wrap.is-scrollable td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
  .table-wrap.is-scrollable th:first-child { background: #f3f1ec; }
}

/* Login · iteración 1: "El orden tiene una forma" */
.login-body {
  --petroleo: var(--structural);
  --petroleo-hondo: #0a2c36;
  --cobre: #a8552a;
  --cobre-claro: #e0a77d;
  --papel: #f6f4f1;
  --panel-text: #d6e3e6;
  background: var(--papel);
}
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 5fr 7fr; }
.login-identity { position: relative; overflow: hidden; padding: clamp(2rem, 5vw, 4rem); display: flex; flex-direction: column; color: #fff; background: linear-gradient(180deg, var(--petroleo) 0%, var(--petroleo) 45%, var(--petroleo-hondo) 100%); }
.login-wordmark { position: relative; z-index: 1; margin: 0 0 .35rem; font-size: clamp(2.5rem, 3.6vw, 3.25rem); font-weight: 650; line-height: 1.05; letter-spacing: .01em; }
.login-message { position: relative; z-index: 1; margin-top: 18vh; max-width: 26rem; }
.login-balance-line { display: block; width: 48px; height: 2px; margin-bottom: 1.25rem; background: var(--cobre-claro); }
.login-motto { margin: 0 0 .75rem; font-size: clamp(1.35rem, 2vw, 1.75rem); font-weight: 600; line-height: 1.2; letter-spacing: -.005em; }
.login-description { margin: 0; color: var(--panel-text); font-size: 1.05rem; }
.login-pattern { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 38%; }
.login-pattern-square { fill: rgb(224 167 125 / 10%); stroke: var(--cobre-claro); stroke-width: 1.5; }

.login-main { display: flex; align-items: center; justify-content: center; padding: clamp(2rem, 5vw, 4rem) 1.25rem; }
.login-main:focus { outline: none; }
.login-panel { width: 100%; max-width: 22rem; }
.login-mark { display: block; width: 38%; height: auto; margin: 0 auto 1.5rem; }
.login-panel h1 { margin: 0 0 1.5rem; color: var(--petroleo); font-size: 1.75rem; font-weight: 650; letter-spacing: -.01em; }
.login-form { display: grid; gap: 1.25rem; }
.login-field label { display: block; margin-bottom: .35rem; font-size: .9rem; font-weight: 600; }
.login-field input::placeholder { color: #6b7d82; opacity: 1; }
.login-field input { width: 100%; min-height: 48px; padding: .7rem .8rem; color: var(--text); font-size: 1rem; border: 1px solid #82919b; border-radius: 6px; background: #fff; }
.login-field input[aria-invalid="true"] { border-color: var(--danger); }
.login-help { margin: .35rem 0 0; color: var(--muted); font-size: .875rem; }
.login-password { position: relative; }
.login-password input { padding-right: 5.5rem; }
.login-reveal { position: absolute; top: 2px; right: 2px; bottom: 2px; min-height: 0; padding: 0 .85rem; color: var(--action); font-size: .9rem; font-weight: 600; border: 0; border-radius: 0 4px 4px 0; background: transparent; }
.login-reveal:hover { text-decoration: underline; }
.login-reveal[hidden] { display: none; }
.login-submit { width: 100%; min-height: 48px; margin-top: .25rem; font-size: 1rem; }
.login-error { margin: 0 0 1.25rem; padding: .8rem 1rem; border-left: 4px solid var(--danger); border-radius: 0 var(--radius) var(--radius) 0; background: #fff0f0; color: var(--text); }
.login-error p { margin: 0; }
.login-error p + p { margin-top: .35rem; }

@media (max-width: 960px) {
  .login { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-identity { min-height: 64px; padding: 0 1.25rem; justify-content: center; border-bottom: 2px solid var(--cobre-claro); }
  .login-wordmark { font-size: 1.25rem; }
  .login-message { margin-top: 0; }
  .login-balance-line, .login-motto, .login-description, .login-pattern { display: none; }
  .login-main { align-items: flex-start; padding-top: clamp(2rem, 8vh, 4rem); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Eliminación (archivado) de contribuyente */
.button-danger { background: var(--danger); color: #fff; }
.button-danger:visited { color: #fff; }
.button-danger:hover { background: #8a2222; }
.danger-zone { max-width: 850px; margin-top: 2rem; padding: clamp(1rem, 3vw, 1.5rem); border: 1px solid #e3b5b5; border-radius: var(--radius); background: #fffafa; }
.danger-zone h2 { margin: 0 0 .35rem; color: var(--danger); font-size: 1.12rem; }
.danger-zone p { margin: 0 0 1rem; color: var(--muted); }
.danger-summary { max-width: 850px; margin: 0 0 1.25rem; padding: .9rem 1.1rem; border-left: 4px solid var(--danger); border-radius: 0 var(--radius) var(--radius) 0; background: #fff0f0; }
.danger-summary h2 { margin: 0 0 .4rem; font-size: 1.05rem; }
.danger-summary ul { margin: 0; padding-left: 1.2rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.archive-back { margin-top: 1.5rem; }

.pdf-review.has-pdf-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 1rem;
}
.pdf-review-form { min-width: 0; }
.pdf-review.has-pdf-preview .pdf-review-form { width: 100%; max-width: none; }
.pdf-review-preview:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 28rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pdf-review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .35rem 1rem;
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--border);
}
.pdf-review-toolbar h2 { margin: 0; font-size: 1rem; }
.pdf-review-toolbar a { display: inline-flex; align-items: center; min-height: 44px; }
.pdf-review-document { flex: 1; position: relative; background: var(--background); }
.pdf-review-document iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

@media (max-width: 900px) {
  .pdf-review.has-pdf-preview { grid-template-columns: minmax(0, 1fr); }
  .pdf-review-preview:not([hidden]) { grid-row: 1; min-height: 0; height: min(65svh, 34rem); }
}

@media (width > 900px) {
  .app-shell main {
    padding-inline: 0;
  }
  .app-shell .form-card,
  .app-shell .form-card > p,
  .app-shell .danger-zone,
  .app-shell .danger-summary {
    max-width: none;
  }
  .export-dialog {
    width: 100%;
  }
  .app-shell:has(.pdf-review.has-pdf-preview) {
    grid-template-columns: minmax(0, 1fr);
  }
  .app-shell:has(.pdf-review.has-pdf-preview) > .sidebar {
    display: none;
  }
  main:has(.pdf-review.has-pdf-preview) > .notice,
  main:has(.pdf-review.has-pdf-preview) [data-pdf-request-status],
  main:has(.pdf-review.has-pdf-preview) [data-pdf-stage] > :not(.pdf-review) {
    margin-inline: clamp(1rem, 3vw, 2rem);
  }
}


@media (width > 960px) {
  .login-message, .login-panel { max-width: none; }
  .login-mark { width: min(38%, 8.4rem); }
}
