:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #15383b;
  background: #eff8f1;
  --muted: #4e6964;
  --border: #cfe3da;
  --accent: #a8ce61;
  --dark: #104850;
  --teal: #117461;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 100% 0%, #d7ece1, transparent 62%); }
header { background: #eff8f1; color: var(--dark); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top, 0px); }
.topbar, main, #account-panel { width: min(1120px, calc(100% - 36px)); margin-inline: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 70px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--dark); text-decoration: none; font-size: clamp(1.05rem, 4vw, 1.4rem); font-weight: 780; letter-spacing: .035em; text-transform: uppercase; white-space: nowrap; }
.brand-app { color: #537629; font-weight: 550; }
#offline-status { font-size: .82rem; color: var(--muted); text-align: right; }
.topbar .actions { justify-content: flex-end; }
.login-link { color: var(--teal); padding: 8px 2px; font-weight: 650; }
#account-menu { position: relative; }
#account-menu > summary { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 2px; color: var(--teal); font-size: .88rem; font-weight: 650; cursor: pointer; }
#account-menu > summary::-webkit-details-marker { display: none; }
#account-menu > summary::after { content: ''; width: .42em; height: .42em; border-right: 1.5px solid; border-bottom: 1.5px solid; transform: translateY(-2px) rotate(45deg); }
.account-popover { position: absolute; z-index: 5; top: 100%; right: 0; width: min(285px, calc(100vw - 36px)); padding: 12px; background: white; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px #10485020; }
.account-popover p { margin: 0 0 8px; font-size: .84rem; }
.account-popover .actions { justify-content: flex-start; gap: 8px; }
.account-popover button { padding-inline: 10px; font-size: .85rem; }
main { padding-block: 38px; }
.page-heading, .section-heading, .actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-heading, .section-heading { justify-content: space-between; }
.page-heading { margin-bottom: 32px; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: clamp(1.75rem, 5vw, 2.6rem); letter-spacing: -.055em; }
h2 { font-size: 1.23rem; letter-spacing: -.025em; }
h3 { font-size: 1rem; overflow-wrap: anywhere; }
p { color: var(--muted); margin-top: 6px; line-height: 1.5; overflow-wrap: anywhere; }
button, input, select { font: inherit; }
button, input, select { border: 1px solid #b5cec1; border-radius: 9px; background: white; color: inherit; padding: 9px 12px; min-height: 42px; }
input[type=checkbox] { min-height: auto; accent-color: var(--dark); }
button { font-weight: 650; cursor: pointer; }
button:hover { background: #e6f3eb; }
button:disabled { opacity: .6; cursor: wait; }
.primary { color: white; background: var(--teal); border-color: var(--teal); }
.primary:hover { background: var(--dark); }
.with-icon { display: inline-flex; align-items: center; gap: 8px; }
.with-icon svg { width: 18px; height: 18px; flex: none; color: var(--teal); }
.primary.with-icon svg { color: #dcf2ab; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-block: 12px 8px; }
#cash-definition { margin-bottom: 26px; font-size: .86rem; }
.metrics > div, .history { background: white; border: 1px solid var(--border); border-radius: 14px; padding: 17px; }
.metrics > div { border-top: 3px solid var(--accent); }
.metrics dt { color: var(--muted); font-size: .86rem; }
.metrics dd { margin-top: 8px; font-weight: 750; font-size: clamp(1rem, 2vw, 1.45rem); overflow-wrap: anywhere; }
.history .section-heading { margin-bottom: 9px; }
#feedback { margin-bottom: 12px; }
#receivables { margin-bottom: 18px; }
#receivables summary { cursor: pointer; }
#receivables-summary { color: var(--muted); font-size: .88rem; }
#receivables[open] #receivables-entries { margin-top: 12px; }
.overdue { color: #9d2525; font-weight: 650; }
.entry { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding-block: 13px; border-top: 1px solid var(--border); }
.entry p { font-size: .86rem; }
.empty { padding-block: 20px 12px; }
label { display: grid; gap: 5px; font-size: .89rem; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; }
input { width: 100%; min-width: 0; }
label.inline input { width: auto; }
dialog { width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 22px; border: 1px solid var(--border); border-radius: 15px; color: inherit; }
dialog::backdrop { background: #10485088; }
form { display: grid; gap: 15px; }
form .actions { justify-content: flex-end; }
fieldset { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border: 1px solid var(--border); border-radius: 10px; margin: 0; padding: 12px; }
#expense-fields, #expense-fields label, #expense-fields select { min-inline-size: 0; }
#expense-fields label { grid-template-columns: minmax(0, 1fr); }
#expense-fields select { inline-size: 100%; }
#expense-fields .expense-wide { grid-column: 1 / -1; }
#expense-fields select[name="tripId"] { text-overflow: ellipsis; }
legend { font-size: .88rem; padding-inline: 5px; color: var(--muted); }
.danger, #form-feedback { color: #9d2525; }
#account-panel { margin-top: 22px; padding: 14px 17px; background: white; border: 1px solid var(--border); border-radius: 14px; }
#account-panel:not(:has(> :not([hidden]))) { display: none; }
#login-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
#login-form label { flex: 1 1 200px; }
#import-device { margin-top: 12px; }
#conflicts > article { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
#conflicts .actions { margin-top: 10px; }
#csv-preview ul { margin: 8px 0 0; padding-inline-start: 22px; }
#csv-preview li { margin-block: 4px; overflow-wrap: anywhere; }
#entry-source dt { margin-top: 8px; font-weight: 650; }
#entry-source dd { overflow-wrap: anywhere; }

#mobile-nav { display: none; }

@media (max-width: 760px) {
  .with-mobile-nav { padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  #mobile-nav {
    position: fixed;
    z-index: 4;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 6px max(3px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(3px, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 -4px 18px #10485012;
  }
  #mobile-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 54px;
    padding: 4px 1px;
    border: 0;
    color: var(--muted);
    font-size: clamp(.52rem, 2.55vw, .73rem);
    line-height: 1.12;
    overflow-wrap: anywhere;
  }
  #mobile-nav button[aria-current="page"] { color: var(--dark); background: #e6f3eb; }
  #mobile-nav button:focus-visible { outline-offset: -2px; }
  #mobile-nav svg { width: 21px; height: 21px; flex: none; color: var(--teal); }
}

@media (max-width: 670px) {
  main { padding-block: 24px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .entry { grid-template-columns: minmax(0, 1fr) auto; }
  .entry > div { grid-column: 1 / -1; }
  .entry button { justify-self: end; }
}

@media (max-width: 390px) {
  fieldset { grid-template-columns: 1fr; }
}
