:root {
  color-scheme: light;
  --ink: #15312b;
  --muted: #65756f;
  --paper: #f4f1e8;
  --card: #fffdf8;
  --brand: #1f6655;
  --brand-dark: #173f35;
  --accent: #e8ae45;
  --line: #d9ddd7;
  --danger: #a6342a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.connection-status {
  position: fixed; z-index: 20; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: calc(100% - 2rem); padding: .7rem 1rem; border-radius: 999px;
  background: var(--brand-dark); color: white; box-shadow: 0 8px 30px rgb(0 0 0 / 25%);
  font-size: .85rem; font-weight: 750;
}
.connection-status.offline { background: #8a4b16; }
.connection-status.sync-error { background: var(--danger); }

.shell { min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) clamp(1rem, 4vw, 3rem) 1rem;
  background: var(--brand-dark); color: white;
}
.brand { display: flex; align-items: center; gap: .8rem; font-weight: 800; font-size: 1.2rem; }
.coin { display: grid; place-items: center; width: 2.3rem; aspect-ratio: 1; border-radius: 50%; background: var(--accent); color: var(--brand-dark); }
.content { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); margin-bottom: .4rem; letter-spacing: -.04em; }
.muted { color: var(--muted); }
.button { border: 0; border-radius: .8rem; padding: .8rem 1rem; background: var(--brand); color: white; font-weight: 700; }
.button.secondary { background: transparent; border: 1px solid currentColor; }
.button.secondary.dark { color: var(--brand-dark); }
.button:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent), transparent 30%); outline-offset: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 1.2rem; padding: 1.2rem; box-shadow: 0 10px 30px rgb(21 49 43 / 5%); }
.event-card { transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.event-card:hover { transform: translateY(-2px); border-color: var(--brand); box-shadow: 0 14px 35px rgb(21 49 43 / 10%); }
.card-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.event-date { color: var(--brand); font-weight: 700; }
.registers { display: grid; gap: .45rem; padding: 0; list-style: none; margin-bottom: 0; }
.registers li { padding: .6rem .7rem; border-radius: .6rem; background: #edf3ef; }
.register-manager { margin-bottom: 1.2rem; }
.managed-registers { display: grid; gap: .7rem; }
.managed-register { display: grid; grid-template-columns: 1fr auto auto; gap: .7rem; align-items: end; padding-bottom: .7rem; border-bottom: 1px solid var(--line); }
.managed-register .field, .new-register-form .field, .template-form .field { margin-bottom: 0; }
.managed-register .register-error { grid-column: 1 / -1; }
.new-register-form, .template-form { display: grid; grid-template-columns: 1fr auto; gap: .7rem; align-items: end; margin-top: 1rem; padding: 1rem; border-radius: .8rem; background: #edf3ef; }
.new-register-form .register-error, .template-form .template-error { grid-column: 1 / -1; }
.template-list { display: grid; gap: .6rem; margin-top: 1rem; }
.template-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem; border: 1px solid var(--line); border-radius: .8rem; }
.template-item small { display: block; margin-top: .25rem; color: var(--muted); }
.template-badge { padding: .3rem .55rem; border-radius: 999px; background: #edf3ef; color: var(--brand); font-size: .75rem; font-weight: 800; }
.empty { text-align: center; padding: 3rem 1rem; }
.eyebrow { margin-bottom: .3rem; color: var(--brand); font-size: .78rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.balance-list { display: grid; gap: 1.2rem; }
.balance-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1rem; }
.balance-header h2 { margin-bottom: 0; }
.balance-total { color: var(--brand-dark); font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 850; white-space: nowrap; }
.denomination-grid { display: grid; grid-template-columns: repeat(7, minmax(90px, 1fr)); gap: .65rem; }
.denomination { display: grid; gap: .35rem; padding: .7rem; border: 1px solid var(--line); border-radius: .8rem; background: #faf9f4; font-weight: 750; }
.denomination input { min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: .55rem; padding: .65rem; font-size: 1.05rem; background: white; }
.line-total { color: var(--muted); font-weight: 600; }
.save-row { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; margin-top: 1rem; }
.save-status { margin-right: auto; }
.settlement-list { display: grid; gap: 1.2rem; }
.event-revenue, .revenue { display: grid; text-align: right; }
.event-revenue span, .revenue span { color: var(--muted); font-size: .82rem; font-weight: 700; }
.event-revenue strong { font-size: clamp(1.8rem, 4vw, 2.8rem); }
.revenue strong { color: var(--brand); font-size: 1.5rem; }
.formula { display: flex; align-items: center; gap: .7rem; padding: 1rem; overflow-x: auto; border-radius: .8rem; background: #edf3ef; }
.formula span { display: grid; min-width: max-content; }
.formula small { color: var(--muted); }
.settlement-section { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.settlement-section summary { cursor: pointer; font-weight: 800; }
.closing-form, .movement-form { margin-top: 1rem; }
.closing-grid { grid-template-columns: repeat(7, minmax(82px, 1fr)); }
.movement-fields { display: grid; grid-template-columns: 1fr 1fr 1.3fr 2fr; gap: .7rem; }
.field select { width: 100%; border: 1px solid var(--line); border-radius: .7rem; padding: .85rem; background: white; }
.movement-list { display: grid; gap: .5rem; padding: 0; list-style: none; }
.movement-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem; border-radius: .7rem; background: #f4f3ed; }
.movement-list small { display: block; color: var(--muted); }
.icon-button { display: grid; place-items: center; width: 2rem; height: 2rem; border: 0; border-radius: 50%; background: #eadbd7; color: var(--danger); font-size: 1.3rem; }
.article-registers { display: grid; gap: 1.2rem; }
.article-fields, .article-row { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(100px, .7fr) minmax(130px, .8fr) auto; gap: .7rem; align-items: end; }
.article-fields { padding: 1rem; border-radius: .8rem; background: #edf3ef; }
.article-fields .field, .article-row .field { margin-bottom: 0; }
.article-error { grid-column: 1 / -1; min-height: 0; }
.article-list { display: grid; gap: .7rem; margin-top: 1rem; }
.article-row { grid-template-columns: minmax(180px, 2fr) minmax(100px, .7fr) minmax(130px, .8fr) auto auto; padding-top: .7rem; border-top: 1px solid var(--line); }
.active-toggle { display: flex; align-items: center; gap: .4rem; min-height: 2.9rem; font-weight: 700; }
.article-actions { display: flex; align-items: center; gap: .5rem; }
.planning-assumptions { border-left: 5px solid var(--accent); }
.planning-assumptions p { margin-bottom: 0; line-height: 1.55; }
.plan-config { margin: 1.2rem 0; }
.safety-field { width: min(220px, 100%); margin-bottom: 0; }
.shortage { margin-bottom: 1.2rem; border-color: #d78877; background: #fff4f0; }
.shortage p { margin-bottom: 0; }
.plan-registers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; }
.plan-table { display: grid; }
.plan-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.plan-head { color: var(--muted); font-size: .78rem; font-weight: 750; text-transform: uppercase; }
.allocation { color: var(--brand); font-weight: 800; }
.plan-demand { margin: 1rem 0 0; }
.reserve-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1.2rem; }
.reserve-grid { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .7rem; }
.reserve-grid span { display: grid; min-width: 70px; padding: .6rem; text-align: center; border-radius: .7rem; background: #edf3ef; }
.reserve-grid small { color: var(--muted); }
.apply-plan { display: grid; justify-items: end; margin-top: 1.2rem; }
.narrow-content { width: min(760px, calc(100% - 2rem)); }
.import-privacy { margin-bottom: 1.2rem; border-left: 5px solid var(--brand); }
.import-privacy p { margin-bottom: 0; line-height: 1.55; }
.file-drop { display: grid; gap: .5rem; padding: 2rem; text-align: center; border: 2px dashed var(--line); border-radius: 1rem; background: #faf9f4; }
.file-drop span { font-size: 1.2rem; font-weight: 800; }
.file-drop strong { color: var(--muted); font-size: .85rem; }
.file-drop input { margin: .5rem auto 0; max-width: 100%; }
.import-table { display: grid; gap: .8rem; }
.import-row { display: grid; grid-template-columns: auto minmax(170px, 2fr) minmax(150px, 1.4fr) minmax(100px, .8fr) minmax(120px, .9fr) auto; gap: .7rem; align-items: end; }
.import-row .field { margin-bottom: 0; }
.import-row.needs-review { border-color: #d78877; background: #fffaf7; }
.include-check { display: flex; align-items: center; gap: .4rem; min-height: 2.9rem; font-size: .82rem; font-weight: 700; }
.confidence { display: grid; min-height: 2.9rem; align-content: center; }
.confidence span { color: var(--muted); font-size: .78rem; }
.review-notes { display: flex; flex-wrap: wrap; gap: .35rem; grid-column: 2 / -1; }
.review-notes span { padding: .3rem .5rem; border-radius: 999px; background: #f2dfd8; color: #7d2e26; font-size: .75rem; font-weight: 700; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top, #2c7c68, var(--brand-dark) 55%); }
.auth-card { width: min(440px, 100%); background: var(--card); padding: clamp(1.5rem, 5vw, 2.5rem); border-radius: 1.5rem; box-shadow: 0 25px 70px rgb(0 0 0 / 25%); }
.auth-logo { display: flex; align-items: center; gap: .8rem; margin-bottom: 2rem; font-size: 1.35rem; font-weight: 800; }
.field { display: grid; gap: .4rem; margin-bottom: 1rem; }
.field label { font-weight: 700; }
.field input { width: 100%; border: 1px solid var(--line); border-radius: .7rem; padding: .85rem; background: white; }
.error { color: var(--danger); min-height: 1.4em; }
.auth-card .button { width: 100%; }

dialog { width: min(480px, calc(100% - 2rem)); border: 0; border-radius: 1.2rem; padding: 0; box-shadow: 0 20px 70px rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(10 31 26 / 60%); backdrop-filter: blur(3px); }
.dialog-body { padding: 1.5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1.5rem; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

@media (max-width: 640px) {
  .hero { align-items: stretch; flex-direction: column; }
  .hero .button { width: 100%; }
  .topbar { align-items: flex-start; }
  .denomination-grid { grid-template-columns: repeat(2, 1fr); }
  .balance-header, .save-row { align-items: stretch; flex-direction: column; }
  .save-row .button { width: 100%; }
  .card-actions { flex-direction: column; }
  .managed-register, .new-register-form, .template-form { grid-template-columns: 1fr; }
  .managed-register .register-error, .new-register-form .register-error, .template-form .template-error { grid-column: 1; }
  .event-revenue, .revenue { text-align: left; }
  .movement-fields { grid-template-columns: 1fr; }
  .article-fields, .article-row { grid-template-columns: 1fr; }
  .article-error { grid-column: 1; }
  .article-actions .button { flex: 1; }
  .plan-registers { grid-template-columns: 1fr; }
  .reserve-card { align-items: stretch; flex-direction: column; }
  .reserve-grid { justify-content: flex-start; }
  .apply-plan { justify-items: stretch; }
  .import-row { grid-template-columns: 1fr; }
  .review-notes { grid-column: 1; }
}

@media (min-width: 641px) and (max-width: 980px) {
  .denomination-grid { grid-template-columns: repeat(4, 1fr); }
  .movement-fields { grid-template-columns: repeat(2, 1fr); }
  .article-fields, .article-row { grid-template-columns: repeat(2, 1fr); }
  .article-error { grid-column: 1 / -1; }
  .import-row { grid-template-columns: repeat(2, 1fr); }
  .review-notes { grid-column: 1 / -1; }
}
