:root {
  color-scheme: light;
  --brand: #365e60;
  --brand-deep: #28494b;
  --ink: #192e30;
  --muted: #4e6463;
  --page: #f3f6f4;
  --paper: #fff;
  --line: #d4e1dc;
  --wash: #e8f0ed;
  --focus: #126a78;
  --radius: 16px;
  font: 16px/1.5 "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); }
h1, h2, h3, p { margin: 0; }
h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); letter-spacing: -.025em; }
h3 { font-size: 1rem; }
button, input, select { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
button, .file-action {
  min-height: 46px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--brand);
  color: white;
  font-weight: 650;
  cursor: pointer;
}
button:hover { background: var(--brand-deep); }
button:disabled { opacity: .6; cursor: wait; }
button.secondary, .file-action { border-color: var(--line); background: var(--paper); color: var(--brand-deep); }
button.secondary:hover, .file-action:hover { background: var(--wash); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.masthead { background: var(--paper); border-bottom: 1px solid var(--line); }
.masthead-inner, main { max-width: 1180px; margin-inline: auto; padding-inline: clamp(14px, 4vw, 34px); }
.masthead-inner { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding-block: 12px; }
.brand, .identity { display: flex; align-items: center; gap: 18px; min-width: 0; }
.brand img { width: clamp(72px, 10vw, 106px); height: auto; flex: none; }
.brand h1 { padding-inline-start: 18px; border-inline-start: 1px solid var(--line); font-size: clamp(.95rem, 2.1vw, 1.15rem); font-weight: 650; }
#profile { font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
#logout { white-space: nowrap; }
main { padding-block: 16px 36px; }
#message:not(:empty) { background: var(--wash); color: var(--brand-deep); padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; overflow-wrap: anywhere; }
#tabs {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 10px 0 14px; background: var(--page);
}
#tabs button { background: var(--paper); color: var(--brand-deep); border-color: var(--line); white-space: nowrap; }
#tabs button:hover { background: var(--wash); }
#tabs button[aria-current] { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.entry-layout { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.entry-layout:has(.entry-side[hidden]) { grid-template-columns: minmax(0, 720px); }
section.panel, form, .quick-links, .access-forms {
  min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
section.panel, #expense, .quick-links, .access-forms { padding: clamp(16px, 3vw, 28px); }
form { padding: 16px; margin: 0; }
form h2, section.panel > h2 { margin-bottom: 16px; }
section.panel > p { margin-bottom: 14px; color: var(--muted); }
#expense { box-shadow: 0 8px 24px #2446420a; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.span-all { grid-column: 1 / -1; }
label { display: block; min-width: 0; font-size: .93rem; font-weight: 650; }
form > label + label { margin-top: 14px; }
label input, label select {
  display: block; width: 100%; min-width: 0; min-height: 47px; margin: 6px 0 0;
  padding: 10px 12px; border-radius: 9px; border: 1px solid #b8cbc4;
  background: #fcfefd; color: var(--ink); font-size: 1rem;
}
input::placeholder { color: #687d7a; }
.unit, small { color: var(--muted); }
fieldset { min-width: 0; margin: 20px 0; padding: 12px 14px 14px; border: 1px dashed #a9c2b9; border-radius: 11px; background: #f5f9f7; }
legend { padding-inline: 6px; color: var(--brand-deep); font-size: .9rem; font-weight: 650; }
.file-action { display: inline-flex; align-items: center; position: relative; font-size: 1rem; overflow: hidden; }
.file-action input { cursor: pointer; opacity: 0; position: absolute; inset: 0; height: 100%; margin: 0; padding: 0; }
.file-action:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
form > button { margin-top: 16px; }
.entry-actions > button:first-child { padding-inline: 22px; }
.entry-side { display: grid; gap: 14px; }
.balance-card, .access-brand {
  position: relative; isolation: isolate; overflow: hidden;
  background: var(--brand-deep); color: #fff; border-radius: var(--radius);
  padding: 20px;
}
.balance-card::after, .access-brand::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: url("/nest-pattern.webp") right bottom / auto 78px no-repeat;
  opacity: .12;
}
.balance-card h3, .quick-links h3 { margin-bottom: 10px; }
.balance-card p { font-weight: 600; font-variant-numeric: tabular-nums; }
.quick-links button { display: block; width: 100%; text-align: left; margin-top: 8px; }
#access { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; max-width: 880px; margin: 22px auto 0; }
.access-brand { min-height: 215px; display: grid; align-content: center; gap: 8px; padding: 26px; }
.access-brand p { color: #eff7f4; }
.access-forms form { padding: 0; border: 0; }
.access-forms details { margin-top: 18px; }
.access-forms details form { margin-top: 14px; }
details { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin: 10px 0; }
summary { font-weight: 650; cursor: pointer; padding-block: 5px; }
.record { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; border-top: 1px solid var(--line); padding: 13px 0; }
.record > div { min-width: 0; overflow-wrap: anywhere; }
.record small { display: block; margin-top: 4px; }
#total { color: var(--brand-deep); background: var(--wash); border-radius: 9px; padding: 12px 14px; margin: 14px 0; font-weight: 650; }
.records { overflow: auto; max-height: 62vh; }
.finance-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; margin: 16px 0; }
.finance-totals div { padding: 12px; background: var(--wash); border-radius: 9px; }
.finance-totals strong, .finance-totals span { display: block; }
.finance-totals strong { margin-top: 3px; font-variant-numeric: tabular-nums; }
#finance-detail h3 { margin-top: 20px; }
#finance-project { max-width: 420px; }
#debts summary { display: flex; justify-content: space-between; gap: 12px; }
#debts dl { margin: 6px 0 0; }
#debts dl > div { display: grid; grid-template-columns: minmax(90px,1fr) minmax(0,2fr); gap: 10px; border-top: 1px solid var(--line); padding: 12px 0; }
#debts dd { margin: 0; }
#debts dd small { display: block; margin-bottom: 6px; }
#panel-imports form { margin-top: 14px; }
#receipt-preview, #camera-stream { display: block; max-width: 100%; max-height: 230px; margin: 10px 0; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; max-width: 94vw; color: var(--ink); }
dialog::backdrop { background: #101d23b0; }
dialog img { display: block; max-width: 85vw; max-height: 68vh; object-fit: contain; }
dialog form { border: 0; padding: 0; margin-top: 10px; }
#movement-dialog { width: min(460px, 94vw); }
#movement-dialog .actions { margin-top: 14px; }
#movement-error { color: #9b302a; }
@media (max-width: 720px) {
  .entry-layout, #access { grid-template-columns: 1fr; }
  #access { margin-top: 0; gap: 12px; }
  .access-brand { min-height: 115px; padding: 17px 20px; }
  .brand { gap: 9px; }
  .brand h1 { padding-inline-start: 9px; }
  .identity { flex-direction: column; align-items: flex-end; gap: 2px; }
  #profile { font-size: .78rem; }
  #logout { padding-inline: 9px; font-size: .85rem; }
  #tabs { gap: 7px; }
  #tabs button { padding-inline: 8px; font-size: .87rem; }
  #tabs button[data-manager]:not([hidden]) { flex: 1 1 auto; }
  .records { max-height: none; }
}
@media (max-width: 370px) {
  .brand h1 { max-width: 98px; }
  .expense-fields { gap: 12px 10px; }
}
