/* Profit First. One stylesheet, no build step. Colours follow the design canvas. */

:root {
  --ground: #F7F7F5;
  --surface: #FFFFFF;
  --ink: #15211C;
  --muted: #5A6760;
  --soft: #4C5952;
  --line: #E6E9E4;
  --line-soft: #EEF0EC;
  --border: #D5DAD3;
  --pill: #E9EAE6;
  --warn-bg: #FDF3E7;
  --warn-ink: #8A4208;
  --error-bg: #FBE9E7;
  --error-ink: #9A2B1E;
}

/* Each account carries its own tint (background) and tone (text on that background). */
.income      { --tint: #E4EDFB; --tone: #2A55A8; }
.profit      { --tint: #E1F2E7; --tone: #1F6B45; }
.owners-comp { --tint: #EDE8FA; --tone: #5B3FA6; }
.tax         { --tint: #FBEDD9; --tone: #8A5208; }
.opex        { --tint: #E8EBEE; --tone: #46535F; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, p { margin: 0; }

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

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 32px) 56px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ------------------------------------------------------------ header */

.top, .brand-nav, .top-right, .actions, .top nav {
  display: flex;
  align-items: center;
}
.top { flex-wrap: wrap; justify-content: space-between; gap: 12px; }
.brand-nav { flex-wrap: wrap; gap: 24px; }
.top-right { gap: 10px; }
.actions { gap: 10px; }
.top nav { gap: 4px; }

.brand { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }

.tab {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--soft);
  font-size: 14px;
  font-weight: 500;
}
.tab.active { background: var(--pill); color: var(--ink); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.btn.solid { background: var(--tone, var(--ink)); border-color: var(--tone, var(--ink)); color: #FFFFFF; }
.btn.big { height: 52px; width: 100%; font-size: 15px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--soft);
}

/* ------------------------------------------------------------ balances */

.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }

.card {
  position: relative;
  overflow: hidden;
  container-type: inline-size;
  min-width: 0;
  min-height: 208px;
  padding: 24px;
  border-radius: 28px;
  background: var(--tint);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

/* A soft disc in the corner, in the account's own colour. Decoration only. */
.card::before, .card::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: var(--tone);
  pointer-events: none;
}
.card::before { top: -56px; right: -40px; width: 168px; height: 168px; opacity: 0.06; }
.card::after { top: -28px; right: -64px; width: 132px; height: 132px; opacity: 0.07; }

.card > * { position: relative; }

.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px -18px var(--tone);
}

/* PROFIT and TAX are kept locked away: quieter, with a lock, no decoration. */
.card.locked {
  background: color-mix(in srgb, var(--tint) 45%, var(--ground));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 22%, transparent);
}
.card.locked::before, .card.locked::after { display: none; }
.card.locked:hover, .card.locked:focus-visible {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 40%, transparent);
}
.card .lock { position: absolute; top: 22px; right: 22px; color: var(--tone); }
.card.locked .whole { color: color-mix(in srgb, var(--ink) 62%, var(--tone)); }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover, .card:focus-visible { transform: none; }
}

.label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--tone, var(--muted));
}

.balance {
  margin-top: auto;
  display: flex;
  align-items: baseline;
  gap: 0.16em;
  font-size: clamp(22px, 17cqi, 40px);
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.035em;
  white-space: nowrap;
}
.cur, .cents { font-size: 0.58em; font-weight: 500; letter-spacing: -0.01em; color: var(--tone); }
.cents { margin-left: -0.1em; }

.extra { min-height: 36px; font-size: 13px; line-height: 18px; color: var(--tone, var(--muted)); }

/* ------------------------------------------------------------ one account */

.account-view { display: flex; flex-direction: column; gap: 16px; }

.hero {
  padding: 28px;
  border-radius: 24px;
  background: var(--tint);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 24px 64px;
}
.hero-main { flex: 1 1 260px; display: flex; flex-direction: column; gap: 10px; }
.hero-note { flex: 1.4 1 320px; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  height: 44px;
  margin-top: -12px;
  color: var(--tone);
  font-size: 13px;
  font-weight: 500;
}

.hero-balance {
  font-size: 44px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.note-title { font-size: 13px; font-weight: 600; color: var(--tone); }
.note { font-size: 15px; line-height: 1.5; white-space: pre-line; }

details { width: 100%; }
summary {
  display: inline-flex;
  align-items: center;
  height: 44px;
  color: var(--tone);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
details form { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding-top: 4px; }
details .field { width: 100%; }

/* ------------------------------------------------------------ history rows */

.rows {
  padding: 8px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
}
.rows.plain { padding: 0; border: 0; border-radius: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
}
.row:first-child { border-top: 0; }

.date { flex: 0 0 56px; font-size: 13px; color: var(--muted); }
.what { flex: 1 1 0; min-width: 0; font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.tag {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--tone);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.amt { flex: 0 0 auto; min-width: 112px; text-align: right; font-size: 15px; font-weight: 600; white-space: nowrap; }
.del {
  flex: 0 0 44px;
  height: 44px;
  margin-right: -12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--muted);
}
.account-view .tag { display: none; }

.empty {
  padding: 48px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

/* ------------------------------------------------------------ sheets (forms) */

.sheet-page { display: flex; justify-content: center; }
.sheet-page.login { min-height: 100vh; align-items: center; padding: 16px; }

.sheet {
  width: 100%;
  max-width: 480px;
  padding: 24px 28px 28px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

dialog {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: transparent;
  color: inherit;
  overflow: auto;
}
dialog::backdrop { background: rgba(21, 33, 28, 0.38); }
dialog .sheet { border: 0; }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head .icon-btn { margin-right: -12px; }
.sheet h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.015em; }
.sheet h2 { font-size: 15px; font-weight: 600; }
.sheet form { display: flex; flex-direction: column; gap: 22px; }
.section-head { display: flex; flex-direction: column; gap: 2px; }
.section-head p, .hint { font-size: 13px; line-height: 1.45; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span:first-child, legend { font-size: 13px; font-weight: 500; color: var(--muted); }

.amount, .percent {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 14px;
}
.amount { height: 60px; padding: 0 16px; border: 1.5px solid var(--ink); }
.amount > span { font-size: 26px; font-weight: 600; color: var(--muted); }
.amount input {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 26px;
  line-height: 1;
  font-family: inherit;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.percent:focus-within { border-color: var(--ink); }

.percent { height: 48px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; }
.percent > span { font-size: 14px; color: var(--muted); }
.percent input {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

input.text, textarea {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.4;
  font-family: inherit;
}
input.text { height: 48px; }
textarea { padding: 12px 14px; resize: vertical; }

fieldset.chips { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
legend { padding: 0; margin-bottom: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  position: relative;
  flex: 1 1 140px;
  min-height: 56px;
  padding: 9px 14px;
  border-radius: 14px;
  background: var(--tint);
  color: var(--tone);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip-name { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; white-space: nowrap; }
.chip-balance { font-size: 13px; font-weight: 500; }
.chip:has(input:checked) { background: var(--tone); color: #FFFFFF; }
/* The explanation of the selected account, under the chips. */
.chip-hint { display: none; margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.chips:has(input[value="income"]:checked) .chip-hint[data-for="income"],
.chips:has(input[value="opex"]:checked) .chip-hint[data-for="opex"],
.chips:has(input[value="tax"]:checked) .chip-hint[data-for="tax"] { display: block; }
.chip:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.warning, .error { border-radius: 14px; padding: 14px 16px; font-size: 13px; line-height: 1.45; }
.warning { background: var(--warn-bg); color: var(--warn-ink); display: flex; flex-direction: column; gap: 3px; }
.warning strong { font-size: 14px; font-weight: 600; }
.error { background: var(--error-bg); color: var(--error-ink); font-weight: 500; }

/* Five in a row needs room. Below that: INCOME on top, the other four two by two. */
@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card.income { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------ phone */

@media (max-width: 640px) {
  .page { padding-top: 12px; padding-bottom: 112px; gap: 16px; }
  .brand { display: none; }
  .top nav { margin-left: -4px; }

  /* The three actions move to the bottom of the screen, within reach of a thumb. */
  .top .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    background: var(--ground);
    border-top: 1px solid var(--line);
  }
  .actions .btn { height: 52px; padding: 0 8px; font-size: 15px; }

  .card { min-height: 132px; padding: 18px; border-radius: 22px; }

  .hero { padding: 20px; border-radius: 22px; }
  .hero-balance { font-size: 36px; }

  .rows { padding: 4px 16px; border-radius: 20px; }
  .row { flex-wrap: wrap; gap: 4px 10px; padding: 12px 0; }
  .date { flex-basis: 48px; }
  .what { flex-basis: calc(100% - 110px); }
  .amt { min-width: 0; margin-left: auto; }
  .del { margin: -8px -12px -8px 0; }

  .sheet { padding: 20px; border-radius: 22px; }
}
