:root {
  --bg: #F6F8F6;
  --surface: #FFFFFF;
  --ink: #17211B;
  --ink-2: #5A6A5F;
  --line: #D9E2DB;
  --accent: #1E8E5A;
  --accent-dark: #14663F;
  --red: #C0392B;
  --sheet-head: #E7F1EA;
  --sheet-total: #F0F6F1;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }

/* ------------------------------------------------------------ login */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: 0 8px 30px rgba(23,33,27,.08);
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card p { margin: 0 0 16px; color: var(--ink-2); font-size: 14px; }
.login-card input {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 10px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; border: none; border-radius: 8px; cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.err { color: var(--red); font-size: 14px; }

/* -------------------------------------------------------------- top */
.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.top h1 { margin: 0; font-size: 20px; }
.top h1 span { color: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tab {
  font-size: 15px; font-weight: 600; color: var(--ink-2);
  background: transparent; border: none; border-bottom: 3px solid transparent;
  padding: 8px 12px; cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-pressed="true"] { color: var(--accent-dark); border-bottom-color: var(--accent); }

main { max-width: 1080px; margin: 0 auto; padding: 22px; }

.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 14px; font-size: 15px;
}
.toolbar select {
  font-size: 15px; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface);
}
.hint { color: var(--ink-2); font-size: 13.5px; }

/* ----------------------------------------------- spreadsheet look */
.sheet-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(23,33,27,.05);
}
.sheet { border-collapse: collapse; width: 100%; min-width: 900px; font-size: 13.5px; }
.sheet th, .sheet td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  white-space: nowrap;
}
.sheet thead th {
  background: var(--sheet-head);
  font-weight: 700;
  text-align: right;
  position: sticky; top: 0;
}
.sheet thead th:first-child { text-align: left; }
.sheet td { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.sheet td.label {
  text-align: left; font-family: inherit; font-size: 13.5px;
  position: sticky; left: 0; background: var(--surface);
}
.sheet .section td { background: var(--sheet-head); font-weight: 700; font-family: inherit; text-align: left; }
.sheet .total td { background: var(--sheet-total); font-weight: 700; }
.sheet .net td { background: var(--sheet-head); font-weight: 800; border-top: 2px solid var(--accent-dark); }
.sheet .neg { color: var(--red); }
.sheet .zero { color: #B4BFB7; }

/* -------------------------------------------------------------- drop */
.drop {
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 34px;
  text-align: center;
  margin-bottom: 18px;
}
.drop.over { border-color: var(--accent); background: #F0F9F3; }
.drop p { margin: 0 0 10px; }
.btn {
  display: inline-block;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600;
  border: none; border-radius: 8px;
  padding: 9px 18px; cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }

#upload-status .row {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; margin-bottom: 8px; font-size: 14px;
}
#upload-status .row.err { border-color: var(--red); color: var(--red); }

/* ---------------------------------------------------------- invoices */
.invoice {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.invoice-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.invoice-head strong { font-size: 16px; }
.invoice-head .date { color: var(--ink-2); font-size: 14px; }
.invoice-head .total { margin-left: auto; font-family: var(--mono); font-weight: 700; }
.invoice-head .income { color: var(--accent-dark); }
.invoice-actions { display: flex; gap: 12px; font-size: 13.5px; }
.invoice-actions a, .invoice-actions button {
  color: var(--ink-2); background: none; border: none; cursor: pointer;
  font-size: 13.5px; padding: 0; text-decoration: underline;
}
.invoice-actions .del:hover { color: var(--red); }
.items { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 14px; }
.items td { padding: 5px 8px; border-top: 1px solid var(--line); }
.items td.amt { text-align: right; font-family: var(--mono); white-space: nowrap; }
.items select {
  font-size: 13.5px; padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}

/* ------------------------------------------------------------- notes */
.notes-intro h2 { margin: 0 0 6px; }
.notes-intro p { color: var(--ink-2); max-width: 60ch; }
#note-form textarea {
  width: 100%; font: inherit; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  resize: vertical; margin-bottom: 10px;
}
#note-list { margin-top: 22px; }
.note {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 10px;
}
.note .when { color: var(--ink-2); font-size: 12.5px; margin-bottom: 4px; }
.note .body { white-space: pre-wrap; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .top { gap: 10px; }
}

/* ================================================== PnL additions */
.top .add { margin-left: auto; }
.spacer { flex: 1; }
.btn.small { font-size: 13.5px; padding: 6px 12px; }
.btn.ghost { background: var(--surface); color: var(--accent-dark); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--sheet-head); }

.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: rgba(20, 40, 28, .55);
  backdrop-filter: blur(2px);
  pointer-events: none;
  text-align: center; color: #fff;
}
.overlay strong { font-size: 30px; display: block; margin-bottom: 6px; }
.overlay p { margin: 0; font-size: 15px; opacity: .9; }

#toasts {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  background: var(--ink); color: var(--bg);
  border-radius: 8px; padding: 10px 14px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); color: #fff; }

.alert {
  background: var(--sheet-head);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 9px 14px; margin-bottom: 8px; font-size: 14.5px;
}
.alert.warn { border-left-color: var(--red); }

.sheet .pct td { color: var(--ink-2); font-style: italic; border-top: 1px dashed var(--line); }
.sheet .pct td.neg { color: var(--red); }

.chip {
  font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent-dark); background: var(--sheet-head);
  border-radius: 999px; padding: 2px 9px;
}

.ask-intro h2 { margin: 0 0 6px; }
.ask-intro p { color: var(--ink-2); max-width: 60ch; }
#ask-form { display: flex; gap: 10px; margin: 14px 0; }
#ask-form input {
  flex: 1; font: inherit; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
#ask-answer {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; max-width: 66ch; white-space: pre-wrap;
}

.foot {
  max-width: 1080px; margin: 30px auto 0; padding: 16px 22px 40px;
  color: var(--ink-2); font-size: 13.5px;
  border-top: 1px solid var(--line);
}
.foot a { color: var(--accent-dark); }
