/* IBM Plex Sans: a neutral UI sans whose tabular figures line money up in columns. */
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #FBFBF7;
  --ink: #1C1C1C;
  --ink-2: #5F5F5A;
  --rule: #D6D6CF;
  --field: #6F6F69;
  --income: #166534;
  --expense: #B42318;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pad: clamp(16px, 4vw, 48px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

a { color: var(--ink); text-underline-offset: 0.18em; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Fields always show the ring on focus; Chrome does not match :focus-visible on every date input state. */
input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: 2px; }
input[type="date"]::-webkit-calendar-picker-indicator { padding: 4px; border-radius: 2px; cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
main:focus { outline: none; }
main:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 10;
  padding: 12px 16px;
  background: var(--ink);
  color: var(--paper);
}
.skip:focus { top: 12px; }

.demo-note {
  padding: 8px var(--pad);
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
  color: var(--ink-2);
}
.demo-note p { margin: 0; }
.demo-note a { display: inline-block; padding: 11px 0; margin: -11px 0; }

.app { max-width: 1200px; margin: 0 auto; padding: 0 var(--pad) 64px; }

.app-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0 16px;
  border-bottom: 3px double var(--ink);
}
h1 { margin: 0; font-size: 2rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1; }
h2 { margin: 0; font-size: 1.125rem; font-weight: 600; }

.currency { display: flex; align-items: center; gap: 8px; }
.currency label { color: var(--ink-2); font-size: 0.9375rem; }

input[type="text"], input[type="date"], select {
  font: inherit;
  color: var(--ink);
  background: #FFFFFF;
  border: 1px solid var(--field);
  border-radius: 4px;
  min-height: 44px;
  padding: 8px 12px;
  width: 100%;
  scroll-margin-bottom: 120px;
}
select { width: auto; }
input[aria-invalid="true"] { border-color: var(--expense); border-width: 2px; padding: 7px 11px; }

.banner {
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 2px solid var(--expense);
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}
.banner[hidden] { display: none; }
.banner p { margin: 0; }

.totals dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 24px;
  margin: 0;
  padding: 24px 0;
  border-bottom: 1px solid var(--rule);
}
.total dt { font-size: 0.875rem; color: var(--ink-2); }
.total dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 600; overflow-wrap: anywhere; }
.total-balance { grid-column: 1 / -1; margin-bottom: 16px; }
.total-balance dd {
  display: inline-block;
  font-size: clamp(2.25rem, 9vw, 3.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  padding-bottom: 4px;
  border-bottom: 3px double var(--ink);
}
.is-income { color: var(--income); }
.is-expense { color: var(--expense); }

.workspace { display: grid; gap: 40px; padding-top: 32px; }

.entry-form h2 { margin-bottom: 16px; }
.field { margin: 0 0 16px; min-width: 0; }
.field label, .field legend { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { margin: 6px 0 0; font-size: 0.875rem; color: var(--ink-2); }
.field-error { margin: 6px 0 0; font-size: 0.9375rem; color: var(--expense); font-weight: 600; }
.field-row { display: grid; gap: 0 16px; }

fieldset.type { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 24px; }
fieldset.type legend { width: 100%; padding: 0; }
.radio { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.radio input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-primary { background: var(--income); color: #FFFFFF; border: 1px solid var(--income); }
.btn-primary:hover { background: #0F4D27; border-color: #0F4D27; }
.btn-quiet { background: transparent; color: var(--ink); border: 1px solid var(--field); }
.btn-quiet:hover { background: #EFEFE8; }
.btn-danger { background: var(--expense); color: #FFFFFF; border: 1px solid var(--expense); }

.entries-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-bottom: 12px;
  border-bottom: 3px double var(--ink);
}
.entries-head .btn[hidden] { display: none; }

.state { margin: 0; padding: 20px 0; color: var(--ink-2); }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "desc amount"
    "meta delete";
  gap: 2px 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.row-desc { grid-area: desc; font-weight: 600; overflow-wrap: anywhere; }
.row-meta { grid-area: meta; font-size: 0.875rem; color: var(--ink-2); }
.row-amount { grid-area: amount; text-align: right; font-weight: 600; white-space: nowrap; }
.row-delete { grid-area: delete; justify-self: end; }
.row-delete .btn { padding: 8px 14px; }

dialog {
  border: 1px solid var(--ink);
  border-radius: 4px;
  padding: 24px;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgba(28, 28, 28, 0.55); }
dialog p { margin: 12px 0 20px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }

@media (min-width: 600px) {
  .field-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .totals dl { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); align-items: end; }
  .total-balance { grid-column: auto; margin-bottom: 0; }
  .row {
    grid-template-columns: 7.5rem minmax(0, 1fr) auto auto;
    grid-template-areas: "meta desc amount delete";
  }
}

@media (min-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 56px; align-items: start; }
}
