/*
 * Pesa Ledger's web screens. One small stylesheet, written phone-first:
 * the pages are mostly viewed inside the Android app.
 *
 * Colours are named by the job they do and declared once for light and
 * once for dark. The two chart colours are a pair checked for contrast and
 * for colour-blind separation; text never uses them.
 */

:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --surface-raised: #ffffff;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --accent: #006b5e;
  --on-accent: #ffffff;
  --alert: #b3261e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: #1a1a19;
    --surface-raised: #242423;
    --border: #383835;
    --text: #f0efec;
    --text-secondary: #c3c2b7;
    --accent: #82d5c5;
    --on-accent: #00372f;
    --alert: #f2b8b5;
    --series-1: #3987e5;
    --series-2: #d95926;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem;
}

h1 { font-size: 1.5rem; margin: 0.5rem 0; }
h2 { font-size: 1rem; margin: 0 0 0.75rem; }
a { color: var(--accent); }
.muted { color: var(--text-secondary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Navigation: one row that scrolls sideways on a narrow screen. */
.site-nav {
  display: flex;
  gap: 1.25rem;
  overflow-x: auto;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.site-nav a { color: var(--text-secondary); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

.flash {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface-raised);
}
.flash-alert { border-color: var(--alert); color: var(--alert); }

/* Side switch and month stepper. */
.period {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.segmented a {
  padding: 0.4rem 1rem;
  color: var(--text);
  text-decoration: none;
}
.segmented a[aria-current="true"] {
  background: var(--accent);
  color: var(--on-accent);
}
.month-stepper { display: flex; gap: 0.75rem; align-items: center; }
.month-stepper a {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
}

/* Headline figures. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.tile, .card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
}
.tile { display: flex; flex-direction: column; }
.tile strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.card { margin-bottom: 1rem; }
.notice-line { margin: 0 0 1rem; }

/*
 * Bar list: name and value on one line, a thin bar beneath. Bars grow from
 * the left edge, are square there and rounded at the data end.
 */
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.75rem;
  margin-bottom: 0.75rem;
}
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-value { font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 10px; }
.bar {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
}

/* Legend: a swatch beside plain text; the text is never coloured. */
.legend {
  display: flex;
  gap: 1rem;
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}
.swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: 0.35rem;
  border-radius: 2px;
}
.series-1 { background: var(--series-1); }
.series-2 { background: var(--series-2); }

/*
 * Column chart: pairs of thin columns on one shared baseline, with a 2px
 * gap between neighbours and rounded tops. Hovering or focusing a column
 * shows its value.
 */
.columns {
  display: flex;
  gap: 0.5rem;
  height: 11rem;
  padding-top: 1.75rem;
}
.column-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.column-pair {
  flex: 1;
  display: flex;
  gap: 2px;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}
.column {
  position: relative;
  width: 14px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}
.column:hover::after,
.column:focus::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 0.8125rem;
  white-space: nowrap;
  z-index: 1;
}
.column:focus { outline: 2px solid var(--text); outline-offset: 2px; }
.column-label {
  padding-top: 0.25rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-align: center;
}

details { margin-top: 0.75rem; }
summary { color: var(--text-secondary); cursor: pointer; }
table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
th, td { padding: 0.4rem 0; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--text-secondary); font-weight: 500; }
th.num, td.num { text-align: right; }

/* Forms. */
input[type="text"], input[type="search"], input[type="password"],
input[type="number"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
}
input[type="submit"], button, .button-link {
  padding: 0.55rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button-link, button.quiet, .quiet button {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
}
.stack { display: grid; gap: 0.5rem; max-width: 28rem; }
.stack input[type="submit"] { justify-self: start; margin-top: 0.5rem; }
.check { display: flex; gap: 0.5rem; align-items: center; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 0.5rem; }
.inline { display: flex; gap: 0.5rem; flex: 1; }
.add { margin-top: 1.5rem; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.filters input[type="search"] { flex: 1 1 12rem; }

/* Transactions and label lists. */
.entries, .labels { list-style: none; margin: 0; padding: 0; }
.entries li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.entry-main { display: flex; flex-direction: column; min-width: 0; }
.entry-name { color: var(--text); text-decoration: none; font-weight: 500; }
.entry-amount { font-variant-numeric: tabular-nums; }
.entry-amount.money-in { font-weight: 600; }
.entry-category { grid-column: 1 / -1; }
.labels li {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

/* Sub-accounts: figures above the rename form. */
.sub-accounts li { flex-wrap: wrap; }
.sub-account-figures { display: flex; flex-direction: column; flex: 1 1 100%; }

/* A sub-account's Google Sheet settings take the full width. */
.sheet { flex: 1 1 100%; }
.stack.wide { max-width: none; }
textarea.rows, pre.script {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  white-space: pre;
  overflow: auto;
}
pre.script {
  max-height: 16rem;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

/* Contacts: the name above the edit form on narrow screens. */
.contacts li { flex-wrap: wrap; }

/* A conversation: the contact's messages on the left, replies on the right. */
.chat { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.chat li {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-raised);
  overflow-wrap: anywhere;
}
.chat time { display: block; font-size: 0.75rem; }
.chat p { margin: 0.25rem 0 0; }
.chat-out { justify-self: end; border-color: var(--accent); }

/* Suggestions: the payment, the message that explains it, then the form. */
.suggestions { list-style: none; margin: 1rem 0 0; padding: 0; }
.suggestion-payment { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; }
.suggestion-payment .muted { flex-basis: 100%; }
.evidence {
  margin: 0.75rem 0;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--accent);
  overflow-wrap: anywhere;
}
.evidence .muted { display: block; font-size: 0.8125rem; }

/* Printable statement: plain black on white, with the controls left out. */
.statement td .muted { display: block; font-size: 0.8125rem; }
.statement tfoot th { border-top: 2px solid var(--text); }
@media print {
  :root {
    color-scheme: light;
    --surface: #ffffff;
    --border: #999999;
    --text: #000000;
    --text-secondary: #333333;
  }
  .no-print { display: none; }
  main { max-width: none; padding: 0; }
  .statement { font-size: 10pt; }
  .statement tr { break-inside: avoid; }
}
