/* Parley looks like an accounts ledger: red-spined paper, ruled lines, rubber-stamp statuses.
   Paper is a cool grey-green, ink is blue-black, the double red margin runs down the page,
   and the status of each invoice is a rubber stamp. Everything else stays quiet. */

:root {
  --paper: #ecefe5;
  --rule: #c9d1c0;
  --ink: #18263b;
  --ink-soft: #4c5a70;
  --red: #a3231b;
  --green: #2d6a4f;
  --line: 32px;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: 'Hind', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

/* the two red margin lines */
body::before, body::after {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--red);
  opacity: 0.55;
  pointer-events: none;
}
body::before { left: 44px; }
body::after { left: 50px; }

main {
  max-width: 1200px;
  padding: 36px 28px 72px 84px;
}

h1, h2, p { margin: 0; }

.wordmark {
  font-family: 'Yatra One', 'Hind', serif;
  font-weight: 400;
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: 0.01em;
}
.wordmark span { color: var(--red); font-size: 26px; margin-left: 6px; }

.tagline { margin-top: 6px; color: var(--ink-soft); max-width: 60ch; }
.mode { margin-top: 10px; font-size: 15px; color: var(--ink-soft); }
.mode b { color: var(--ink); font-weight: 600; }

section { margin-top: 44px; }
section > h2 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 14px;
}

.hint { margin-top: 10px; font-size: 15px; color: var(--ink-soft); max-width: 66ch; }

/* ruled writing area, lines match the text baseline */
textarea.ruled {
  display: block;
  width: 100%;
  max-width: 760px;
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background-color: transparent;
  background-image: linear-gradient(transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px));
  background-size: 100% var(--line);
  background-attachment: local;
  color: var(--ink);
  font: inherit;
  line-height: var(--line);
  resize: vertical;
}
textarea.ruled::placeholder { color: #7b879a; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px 22px;
  max-width: 860px;
}
.fields label {
  display: block;
  font-size: 15px;
  color: var(--ink-soft);
}
.fields input, .fields select {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 5px 2px;
  border: 0;
  border-bottom: 1px solid var(--ink-soft);
  border-radius: 0;
  background: transparent;
  font-size: 17px;
}
.fields input:invalid { border-bottom-color: var(--red); }

.notes {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  max-width: 66ch;
}
.notes li {
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--red);
  margin-bottom: 6px;
}
.notes:empty { display: none; }

table.lines {
  width: 100%;
  max-width: 860px;
  margin-top: 22px;
  border-collapse: collapse;
}
table.lines th {
  padding: 4px 8px 4px 0;
  border-bottom: 2px solid var(--ink);
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-soft);
  text-align: left;
}
table.lines td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.lines .num { text-align: right; }
table.lines input {
  width: 100%;
  padding: 4px 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
}
table.lines input.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lines td:nth-child(2) { width: 84px; }
table.lines td:nth-child(3) { width: 116px; }
table.lines td:nth-child(4) { width: 120px; text-align: right; font-variant-numeric: tabular-nums; }
table.lines td:last-child { width: 80px; text-align: right; }

.total { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 16px; }
.actions.spread { justify-content: space-between; max-width: 860px; }

button {
  font: inherit;
  cursor: pointer;
}
button.primary {
  padding: 7px 18px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}
button.primary:hover { background: #0f1a2b; }
button.plain {
  padding: 4px 2px;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: none;
  color: var(--ink);
}
button.plain:hover { color: var(--red); }
button:disabled { opacity: 0.5; cursor: wait; }
button.listening { color: var(--red); border-bottom-width: 2px; }

select#lang {
  padding: 3px 4px;
  border: 1px solid var(--ink-soft);
  border-radius: 3px;
  background: transparent;
}

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

/* totals */
.summary p { font-variant-numeric: tabular-nums; }
.summary p + p { margin-top: 2px; }
.summary .late { color: var(--red); font-weight: 600; }

/* the grid, restyled to sit on the ledger */
#grid { margin-top: 20px; }
.ag-theme-quartz {
  --ag-font-family: 'Hind', system-ui, sans-serif;
  --ag-font-size: 16px;
  --ag-background-color: transparent;
  --ag-foreground-color: var(--ink);
  --ag-header-background-color: transparent;
  --ag-header-foreground-color: var(--ink-soft);
  --ag-header-font-weight: 600;
  --ag-border-color: transparent;
  --ag-row-border-color: var(--rule);
  --ag-odd-row-background-color: transparent;
  --ag-row-hover-color: rgba(24, 38, 59, 0.05);
  --ag-selected-row-background-color: rgba(163, 35, 27, 0.07);
  --ag-wrapper-border-radius: 0;
  --ag-row-height: 48px;
  --ag-header-height: 38px;
  --ag-cell-horizontal-padding: 10px;
}
.ag-theme-quartz .ag-root-wrapper { border: 0; border-top: 2px solid var(--ink); border-radius: 0; background: transparent; }
.ag-theme-quartz .ag-root, .ag-theme-quartz .ag-header, .ag-theme-quartz .ag-row, .ag-theme-quartz .ag-body-viewport { background: transparent; }
.ag-theme-quartz .ag-header-cell-text { font-family: inherit; }
.ag-theme-quartz .ag-header { border-bottom: 1px solid var(--ink); }
.ag-theme-quartz .ag-header-cell-resize { display: none; }
.ag-theme-quartz .num-cell { font-variant-numeric: tabular-nums; text-align: right; }
.ag-theme-quartz .ag-right-aligned-header .ag-header-cell-label { justify-content: flex-end; }
.ag-theme-quartz .fresh-row { animation: fresh 2.4s ease-out 1; }
@keyframes fresh { from { background: rgba(163, 35, 27, 0.16); } to { background: transparent; } }
.ag-theme-quartz .row-actions { display: flex; gap: 14px; align-items: center; height: 100%; }
.ag-theme-quartz .row-actions button { font-size: 15px; white-space: nowrap; }

/* rubber stamps */
.stamp {
  display: inline-block;
  padding: 0 9px;
  border: 2px solid currentColor;
  border-radius: 3px;
  font-family: 'Yatra One', 'Hind', serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transform: rotate(-3deg);
  opacity: 0.9;
}
.stamp.late { color: var(--red); transform: rotate(-4deg); }
.stamp.paid { color: var(--green); transform: rotate(2deg); }
.stamp.open { color: var(--ink); }
.stamp.draft, .stamp.closed { color: var(--ink-soft); border-style: dashed; }

/* reminders */
.reminder {
  max-width: 800px;
  padding: 18px 0 20px;
  border-top: 1px solid var(--rule);
}
.reminder:first-child { border-top: 2px solid var(--ink); }
.reminder h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.reminder h3 span { font-weight: 400; color: var(--ink-soft); }
.reminder input[type=text] {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 5px 2px;
  border: 0;
  border-bottom: 1px solid var(--ink-soft);
  background: transparent;
  font-weight: 600;
}
.reminder textarea {
  display: block;
  width: 100%;
  min-height: 190px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.35);
  line-height: 1.55;
  resize: vertical;
}
.reminder.done textarea, .reminder.done input { opacity: 0.55; }
.reminder .after { margin-top: 10px; }

footer { margin-top: 64px; font-size: 14px; color: var(--ink-soft); }

.toast {
  position: fixed;
  left: 84px;
  bottom: 22px;
  max-width: min(560px, calc(100vw - 110px));
  padding: 10px 16px;
  border-left: 4px solid var(--red);
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}
.toast.good { border-left-color: #7fc4a0; }

.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;
}

@media (max-width: 720px) {
  body::before { left: 12px; }
  body::after { left: 17px; }
  main { padding: 24px 14px 56px 34px; }
  .wordmark { font-size: 34px; }
  .toast { left: 34px; max-width: calc(100vw - 50px); }
  .ag-theme-quartz { overflow-x: auto; }
  #grid { overflow-x: auto; }
  #grid .ag-root-wrapper { min-width: 760px; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-theme-quartz .fresh-row { animation: none; }
}
