/* Part 56 — the signed-in website (/app/*). Loaded after style.css and reuses its tokens; only
   layout and the few components the dashboard needs live here. Colour meaning matches the app:
   green = paid/received, amber = pending, red = overdue (design-system §4.1) — no decorative hue. */

/* Author `display` rules (.btn, the login forms, .login-divider) would otherwise beat the UA
   stylesheet and show elements the scripts mark `hidden`. */
[hidden] { display: none !important; }

body.app-loading main { visibility: hidden; }

.app-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.7);
}
.app-nav-links { display: flex; gap: 4px; flex: 1; }
.app-nav-links a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink2);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}
.app-nav-links a.is-active { background: var(--green-bg); color: var(--green); }
.app-nav-account { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--ink2); }
.app-nav-business { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-link-btn {
  font: inherit;
  font-size: 14px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--green);
  font-weight: 600;
  cursor: pointer;
}
.app-link-btn:hover { text-decoration: underline; }

.app-main { max-width: 1080px; margin: 0 auto; padding: 28px 24px 96px; }
.app-main h1 { font-family: "Outfit", "DM Sans", sans-serif; font-size: 28px; margin: 0 0 4px; line-height: 1.2; }
.app-main h2 { font-size: 16px; margin: 0 0 10px; }
.app-sub { color: var(--muted); margin: 0; }
.app-eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .04em; margin: 0 0 2px; }

.app-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-top: 16px;
}

.app-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.app-stat {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}
.app-stat span { font-size: 13px; color: var(--muted); font-weight: 600; }
.app-stat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.app-stat small { font-size: 12px; color: var(--muted); }
.tone-pending { color: var(--amber); }
.tone-overdue { color: var(--red); }
.tone-paid { color: var(--green); }
.app-stats--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.app-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.app-chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.app-chip {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--ink2);
  cursor: pointer;
}
.app-chip.is-active { background: var(--green); border-color: var(--green); color: #fff; }
.app-search {
  font: inherit;
  font-size: 15px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-width: 240px;
}
.app-search:focus, .app-chip:focus-visible, .app-table tr:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

/* Tables scroll sideways inside their own box on a phone rather than pushing the page wider. */
.app-list, .app-card { overflow-x: auto; }
.app-table { width: 100%; border-collapse: collapse; font-size: 15px; background: var(--white); }
.app-list .app-table { border: 1px solid var(--border); border-radius: var(--radius-md); }
.app-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.app-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table td small { display: block; color: var(--muted); font-size: 13px; }
.app-table a { color: var(--ink); font-weight: 600; text-decoration: none; }
.app-list tbody tr { cursor: pointer; }
.app-list tbody tr:hover { background: var(--pearl); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }

.app-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.app-pill--paid { background: var(--green-bg); color: var(--green); }
.app-pill--pending { background: var(--amber-bg); color: var(--amber); }
.app-pill--overdue { background: var(--red-bg); color: var(--red); }
.app-pill--neutral { background: var(--border); color: var(--muted); }

.app-empty { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--white); border: 1px dashed var(--border); border-radius: var(--radius-md); }
.app-empty a { color: var(--green); font-weight: 600; }

.app-back { display: inline-block; color: var(--green); font-weight: 600; text-decoration: none; margin-bottom: 14px; }
.app-invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.app-invoice-amount { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.app-invoice-amount strong { font-size: 30px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.app-invoice-amount small { color: var(--muted); }
.app-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.app-actions .btn:disabled { opacity: .6; cursor: wait; transform: none; }

.app-notice { border-radius: var(--radius-sm); padding: 10px 14px; margin: 14px 0 0; font-size: 14px; }
.app-notice--info { background: var(--pearl); border: 1px solid var(--border); color: var(--ink2); }
.app-notice--error { background: var(--red-bg); color: var(--red); }
.app-notice--success { background: var(--green-bg); color: var(--green); }
/* Shown above every signed-in page until the profile can produce a PDF (shell.ts). */
.app-notice--setup { background: var(--amber-bg); color: var(--ink); border: 1px solid #F1D9A6; margin: 0 0 18px; }
.app-notice--setup a { color: var(--green); font-weight: 700; white-space: nowrap; }

.app-dates { display: flex; gap: 32px; flex-wrap: wrap; margin: 0; }
.app-dates dt { font-size: 13px; color: var(--muted); }
.app-dates dd { margin: 0; font-weight: 600; }
.app-totals { margin: 12px 0 0 auto; min-width: 280px; border-collapse: collapse; font-size: 15px; }
.app-totals td { padding: 4px 0 4px 24px; color: var(--ink2); }
.app-totals td:first-child { padding-left: 0; }
.app-totals-grand td { font-weight: 700; color: var(--ink); font-size: 17px; border-top: 1px solid var(--border); padding-top: 10px; }

/* Off-screen, not display:none — some browsers won't load (and so can't print) a hidden frame. */
.app-print-frame { position: fixed; right: 0; bottom: 0; width: 1px; height: 1px; border: 0; opacity: 0; }

/* New invoice + record payment */
.app-page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.calc-field textarea { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--ink); width: 100%; resize: vertical; }
.calc-field textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.calc-field select:disabled { background: var(--pearl); color: var(--muted); }
.app-card > .calc-field + .calc-field, .ni-new-client { margin-top: 12px; }
.ni-new-client { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.ni-line {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1.2fr) minmax(0, .7fr) minmax(0, 1.3fr) minmax(0, .9fr) minmax(0, 1.1fr) 32px;
  gap: 10px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.ni-line:first-child { padding-top: 0; }
.ni-amount { display: flex; flex-direction: column; align-items: flex-end; padding-bottom: 10px; }
.ni-amount span { font-size: 13px; color: var(--muted); }
.ni-amount strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ni-remove { font: inherit; font-size: 22px; line-height: 1; width: 32px; height: 40px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: var(--radius-sm); }
.ni-remove:hover { color: var(--red); background: var(--red-bg); }
.ni-add { margin-top: 12px; }
.ni-hint { font-size: 14px; color: var(--ink2); background: var(--pearl); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; margin: 12px 0 0; }
.ni-options { display: flex; flex-direction: column; gap: 14px; }
.ni-check { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.ni-check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--green); flex: none; }
.ni-check span { display: flex; flex-direction: column; }
.ni-check small { color: var(--muted); font-size: 14px; }
.ni-check input:disabled + span { opacity: .55; }
.ni-date { min-width: 0; width: auto; padding: 5px 10px; }
.ni-due { margin: 8px 0 14px; }
.ni-summary .app-totals { margin-top: 0; }
.ni-payment-row { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 12px; margin-top: 12px; }

/* Clients, business details */
.app-main--narrow { max-width: 820px; }
.app-section-title { margin: 28px 0 10px !important; font-size: 18px !important; }
.app-search--wide { flex: 1; max-width: 460px; }
.app-actions--tight { margin-top: 0; }
.app-static { margin: 0; padding: 10px 0; color: var(--ink2); }
.app-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 8px; }
.app-form-wide { grid-column: 1 / -1; }
.app-form-narrow { max-width: 280px; margin-top: 12px; }
.app-form-check { margin-top: 16px; }
.calc-field label small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.app-welcome { background: var(--green-bg); border: 1px solid var(--green-bg-2); border-radius: var(--radius-md); padding: 16px 20px; margin-bottom: 20px; }
.app-welcome h2 { margin: 0 0 4px; font-size: 18px; }
.app-welcome p { margin: 0; color: var(--ink2); }
.app-danger { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; color: var(--ink2); }
.app-danger span { display: inline-flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.app-link-btn--danger { color: var(--red); }

/* Reports */
.rp-toolbar { justify-content: space-between; }
.rp-stepper { display: flex; align-items: center; gap: 10px; }
.rp-stepper strong { min-width: 140px; text-align: center; font-size: 16px; }
.rp-step { font: inherit; font-size: 22px; line-height: 1; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--white); color: var(--ink); cursor: pointer; }
.rp-step:disabled { opacity: .35; cursor: default; }
.rp-gst-note { margin: 6px 0 0; font-size: 14px; }
#report-body { transition: opacity .15s; }
#report-body.is-loading { opacity: .45; }
.rp-chart-card { overflow: visible; }
.rp-chart { position: relative; padding-top: 22px; }
.rp-bars, .rp-axis { display: grid; grid-template-columns: repeat(var(--bars), minmax(0, 1fr)); gap: 2px; }
.rp-bars { height: 180px; align-items: end; border-bottom: 1px solid var(--border); }
.rp-col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; outline: none; }
.rp-col:hover .rp-bar, .rp-col:focus-visible .rp-bar { background: var(--green-bright-2); }
/* Thin mark, rounded only at the data end; the column is the (wider) hit target. */
.rp-bar { display: block; width: min(70%, 28px); background: var(--green); border-radius: 4px 4px 0 0; }
.rp-peak { position: absolute; bottom: 100%; font-size: 12px; font-weight: 700; color: var(--ink2); white-space: nowrap; margin-bottom: 2px; }
.rp-axis span { font-size: 11px; color: var(--muted); text-align: center; padding-top: 6px; white-space: nowrap; }
.rp-tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 8px; white-space: nowrap; pointer-events: none; }
.rp-chart-empty { height: 120px; display: grid; place-items: center; color: var(--muted); }
.rp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 20px; }

/* Print: just the report — the header bar, buttons and period controls drop out. */
@media print {
  .app-nav, .rp-downloads, .rp-step, .app-chips, .app-notice--setup, .rp-gst-note { display: none !important; }
  body { background: #fff; }
  .app-main { padding: 0; max-width: none; }
  .app-card, .app-stat, .app-list .app-table { box-shadow: none; break-inside: avoid; }
  .rp-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Login */
.login-wrap { max-width: 400px; margin: 48px auto 96px; padding: 0 20px; }
.login-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 24px; }
.login-card h1, .login-card h2 { font-family: "Outfit", "DM Sans", sans-serif; font-size: 26px; margin: 0 0 4px; }
.login-card p { color: var(--ink2); margin: 0 0 18px; font-size: 15px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .btn { width: 100%; }
.login-links { display: flex; justify-content: space-between; font-size: 14px; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-social { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.login-apple { background: #000; color: #fff; }
.login-foot { text-align: center; font-size: 14px; color: var(--muted); margin-top: 18px; }
.login-foot a { color: var(--green); font-weight: 600; }
.login-card h1 + p, .login-card h2 + p { margin-bottom: 18px; }
.login-terms { font-size: 13px !important; color: var(--muted) !important; margin: 0 !important; text-align: center; }
.login-terms a { color: var(--ink2); }

@media (max-width: 640px) {
  .ni-line { grid-template-columns: 1fr 1fr; }
  .ni-line .ni-desc { grid-column: 1 / -1; }
  .ni-amount { align-items: flex-start; }
  .ni-remove { justify-self: end; }
  .ni-new-client, .ni-payment-row { grid-template-columns: 1fr; }
  .app-nav { padding: 12px 16px; gap: 12px; }
  .app-main { padding: 20px 16px 72px; }
  .app-stats { grid-template-columns: 1fr 1fr; }
  .app-stats .app-stat:last-child { grid-column: 1 / -1; }
  .app-search { min-width: 0; width: 100%; }
  .app-form-grid { grid-template-columns: 1fr; }
  .rp-grid { grid-template-columns: 1fr; }
  .rp-stepper { width: 100%; justify-content: space-between; }
  .rp-downloads .btn { flex: 1 1 100%; }
  .app-stats--two { grid-template-columns: 1fr 1fr; }
  .app-stats--two .app-stat:last-child { grid-column: auto; }
  .app-nav-links { order: 3; flex-basis: 100%; overflow-x: auto; }
  .app-invoice-amount { align-items: flex-start; text-align: left; }
  .app-actions .btn { flex: 1; }
}
