/* Willow Tree — admin area (prototype). Brand colors, calmer SaaS layout. */
:root {
  --cream: #f8f0e1; --cream-deep: #f1e5cf; --paper: #fffdf8; --sage-tint: #e3e6d6;
  --forest: #1c3b2b; --forest-2: #24493a; --forest-soft: #3e5647; --mute: #6b7a6c;
  --leaf: #4f8048; --leaf-hover: #3f6b39; --leaf-light: #8fb27e; --leaf-pale: #d6e4c8;
  --gold: #d6b468; --gold-pale: #f3e6c4; --rust: #a5492f; --rust-pale: #f4dcd3;
  --line: rgba(28, 59, 43, 0.14);
  --display: "Fraunces", Georgia, serif; --body: "Source Serif 4", Georgia, serif;
  --r: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--cream); color: var(--forest-soft); font-family: var(--body); font-size: 15.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--display); color: var(--forest); margin: 0; letter-spacing: -0.01em; }
a { color: var(--forest); }
button, input, select, textarea { font: inherit; }
svg { display: block; }
:focus-visible { outline: 3px solid var(--leaf-light); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--forest); color: #d9e3d2; display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 12px; color: var(--cream); text-decoration: none; padding: 0 8px 26px; }
.side-brand svg { width: 42px; height: 42px; flex-shrink: 0; }
.side-brand strong { display: block; font-family: var(--display); font-size: 1.25rem; line-height: 1.1; }
.side-brand small { display: block; font-size: 0.68rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--leaf-light); font-weight: 700; margin-top: 3px; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r); color: #d9e3d2; text-decoration: none; font-weight: 600; }
.sidebar nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar nav a:hover { background: var(--forest-2); color: #fff; }
.sidebar nav a.active { background: var(--cream); color: var(--forest); }
.side-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,0.12); font-size: 0.82rem; color: #b8c7b3; }
.side-foot p { margin: 8px 0 10px; }
.side-foot a { color: var(--leaf-light); }
.proto-tag { display: inline-block; background: var(--gold); color: var(--forest); font-weight: 700; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; padding: 2px 10px; border-radius: 999px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 18px 32px; border-bottom: 1px solid var(--line); background: rgba(248, 240, 225, 0.92); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px); }
.topbar-title { font-family: var(--display); font-weight: 800; font-size: 1.6rem; color: var(--forest); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.side-toggle { display: none; }
.view { padding: 28px 32px 60px; max-width: 1280px; width: 100%; outline: none; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid transparent; border-radius: var(--r); padding: 9px 16px; font-weight: 700; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-primary { background: var(--leaf); color: #fff; }
.btn-primary:hover { background: var(--leaf-hover); }
.btn-secondary { background: var(--paper); color: var(--forest); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--forest); }
.btn-ghost { background: transparent; color: var(--forest); padding: 6px 10px; }
.btn-ghost:hover { background: var(--sage-tint); }
.btn-danger { background: transparent; color: var(--rust); border-color: rgba(165,73,47,.35); }
.btn-danger:hover { background: var(--rust-pale); }
.btn-sm { padding: 6px 11px; font-size: 0.88rem; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--forest); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn:hover { background: var(--sage-tint); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 700; color: var(--forest); font-size: 0.9rem; }
.field .hint { font-size: 0.82rem; color: var(--mute); }
.field input, .field select, .field textarea, .search {
  border: 1.5px solid rgba(28,59,43,.25); border-radius: var(--r); padding: 9px 12px; background: #fff; color: var(--forest);
}
.field input:focus, .field select:focus, .field textarea:focus, .search:focus { outline: none; border-color: var(--leaf); box-shadow: 0 0 0 3px var(--leaf-pale); }
.field textarea { min-height: 110px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--mute); }
.money-input input { padding-left: 26px; width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.error { color: var(--rust); font-size: 0.85rem; }

/* ---------- Cards, metrics ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; }
.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 1.2rem; }
.metrics { display: grid; grid-template-columns: 1.5fr repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.metric { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; }
.metric .label { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--mute); }
.metric .value { font-family: var(--display); font-weight: 800; font-size: 2rem; color: var(--forest); line-height: 1.15; margin-top: 6px; }
.metric .sub { font-size: 0.85rem; color: var(--mute); margin-top: 4px; }
.metric--hero { background: var(--forest); border-color: var(--forest); }
.metric--hero .label { color: var(--leaf-light); }
.metric--hero .value { color: var(--cream); font-size: 2.6rem; }
.metric--hero .sub { color: #c9d6c3; }
.grid-2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; align-items: start; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--mute); font-weight: 700; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fbf6ea; }
td.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td .strong { font-weight: 700; color: var(--forest); }
td .muted, .muted { color: var(--mute); font-size: 0.88rem; }
.actions-cell { text-align: right; white-space: nowrap; }

.pill { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill--paid { background: var(--leaf-pale); color: #2c5527; }
.pill--outstanding { background: var(--gold-pale); color: #6e5418; }
.pill--overdue { background: var(--rust-pale); color: var(--rust); }
.pill--void { background: #ece8de; color: var(--mute); text-decoration: line-through; }
.pill--neutral { background: var(--sage-tint); color: var(--forest-soft); }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; background: var(--cream-deep); padding: 4px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; cursor: pointer; font-weight: 700; color: var(--forest-soft); }
.tabs button.active { background: var(--paper); color: var(--forest); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.search { min-width: 240px; flex: 1; max-width: 360px; }

.empty { text-align: center; padding: 40px 20px; color: var(--mute); }
.empty h3 { font-size: 1.2rem; margin-bottom: 6px; }

/* Outstanding-by-client bars */
.owed-list { list-style: none; padding: 0; margin: 0; }
.owed-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.owed-list li:last-child { border-bottom: 0; }
.owed-top { display: flex; justify-content: space-between; gap: 12px; }
.owed-top a { font-weight: 700; text-decoration: none; }
.owed-bar { height: 6px; border-radius: 3px; background: var(--cream-deep); margin-top: 8px; overflow: hidden; }
.owed-bar span { display: block; height: 100%; background: var(--gold); border-radius: 3px; }

/* ---------- Client detail ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 700; margin-bottom: 14px; font-size: 0.92rem; }
.detail-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.facts { display: grid; gap: 14px; margin: 0; }
.facts dt { font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--mute); font-weight: 700; }
.facts dd { margin: 2px 0 0; color: var(--forest); }
.client-summary { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.client-summary div span { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); font-weight: 700; }
.client-summary div strong { font-family: var(--display); font-size: 1.4rem; color: var(--forest); }
.notes-area { width: 100%; min-height: 140px; border: 1.5px solid rgba(28,59,43,.2); border-radius: var(--r); padding: 12px; background: #fff; color: var(--forest); resize: vertical; }
.saved-note { font-size: 0.8rem; color: var(--mute); }
.docs { list-style: none; padding: 0; margin: 0 0 12px; }
.docs li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.docs li svg { width: 22px; height: 22px; fill: none; stroke: var(--leaf); stroke-width: 1.7; flex-shrink: 0; }
.docs .doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--forest); font-weight: 600; }
.upload { display: inline-flex; }
.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.notice { background: var(--gold-pale); border-left: 4px solid var(--gold); padding: 12px 16px; border-radius: 0 var(--r) var(--r) 0; font-size: 0.9rem; color: #5c4714; margin: 0 0 16px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 35, 27, 0.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--paper); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); }
.modal-head h2 { font-size: 1.3rem; }
.modal-body { padding: 22px; }

/* ---------- Invoice document ---------- */
.invoice-doc { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 40px; color: #2b2b2b; }
.inv-top { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 2px solid var(--forest); padding-bottom: 20px; margin-bottom: 24px; }
.inv-brand { display: flex; align-items: center; gap: 12px; color: var(--forest); }
.inv-brand svg { width: 46px; height: 46px; }
.inv-brand strong { font-family: var(--display); font-size: 1.4rem; display: block; line-height: 1.1; }
.inv-brand small { font-size: 0.7rem; letter-spacing: .18em; text-transform: uppercase; color: var(--leaf); font-weight: 700; }
.inv-title { text-align: right; }
.inv-title h3 { font-size: 1.8rem; }
.inv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 26px; font-size: 0.92rem; }
.inv-meta h4 { margin: 0 0 4px; font-size: 0.75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); }
.inv-lines td, .inv-lines th { padding: 10px 0; }
.inv-total { display: flex; justify-content: flex-end; gap: 30px; margin-top: 12px; padding-top: 14px; border-top: 2px solid var(--forest); font-family: var(--display); font-size: 1.3rem; color: var(--forest); }
.inv-foot { margin-top: 28px; font-size: 0.85rem; color: var(--mute); }
.doc-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; gap: 20px; max-width: 760px; }
.connect { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.connect:last-child { border-bottom: 0; }
.connect .logo { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0; }
.connect div { flex: 1; }
.connect strong { color: var(--forest); display: block; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--forest); color: var(--cream); padding: 12px 20px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 60; font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .grid-2, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(20,35,27,.4); }
  .side-toggle { display: inline-flex; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--forest); }
  .side-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  .topbar-title { font-size: 1.3rem; }
  .view { padding: 20px 16px 48px; }
  .metrics { grid-template-columns: 1fr; }
  .row2, .inv-meta { grid-template-columns: 1fr; }
  .invoice-doc { padding: 22px; }
  .hide-sm { display: none; }
  .search { min-width: 0; max-width: none; width: 100%; }
}

/* ---------- Print: only the invoice document ---------- */
@media print {
  body * { visibility: hidden; }
  .invoice-doc, .invoice-doc * { visibility: visible; }
  .invoice-doc { position: absolute; inset: 0 auto auto 0; width: 100%; border: 0; }
  .modal-backdrop { background: none; }
}

/* ---------- Sign-in pages (login, setup, invite) ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: radial-gradient(ellipse at top, var(--leaf-pale) 0%, var(--cream) 55%); }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--forest); text-decoration: none; margin-bottom: 22px; }
.auth-brand svg { width: 46px; height: 46px; }
.auth-brand strong { display: block; font-family: var(--display); font-size: 1.4rem; line-height: 1.1; }
.auth-brand small { display: block; font-size: 0.68rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--leaf); font-weight: 700; margin-top: 3px; }
.auth-card { background: var(--paper); border: 2px solid var(--forest); border-radius: 12px; box-shadow: 6px 6px 0 var(--forest); padding: 30px 28px 26px; }
.auth-card h1 { font-size: 1.8rem; margin-bottom: 4px; }
.auth-card > .muted { margin: 0 0 22px; }
.auth-msg { border-radius: var(--r); padding: 10px 14px; margin-bottom: 18px; font-size: 0.92rem; }
.auth-msg--error { background: var(--rust-pale); color: var(--rust); }
.auth-msg--info { background: var(--leaf-pale); color: var(--forest); }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--leaf); font-weight: 700; font-size: 0.85rem; padding: 6px 8px; cursor: pointer; border-radius: 6px; }
.pw-toggle:hover { background: var(--sage-tint); }
.btn-block { width: 100%; justify-content: center; padding: 12px 16px; margin-top: 6px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.auth-note { margin: 18px 0 0; font-size: 0.92rem; text-align: center; }
.auth-foot { text-align: center; font-size: 0.88rem; margin-top: 20px; }
.auth-foot a { color: var(--forest-soft); }

/* ---------- Signed-in user (sidebar) and Team page ---------- */
.side-user { display: grid; gap: 2px; margin-bottom: 10px; }
.side-user strong { color: #fff; font-size: 0.92rem; }
.side-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-links { display: flex; gap: 14px; flex-wrap: wrap; }
.side-links button { background: none; border: 0; padding: 0; color: var(--leaf-light); text-decoration: underline; cursor: pointer; font-size: inherit; }
.preview-banner { background: var(--gold-pale); color: #6e5418; padding: 10px 32px; font-size: 0.88rem; border-bottom: 1px solid var(--line); }
.role-select { padding: 6px 10px; border: 1.5px solid var(--line); border-radius: var(--r); background: #fff; color: var(--forest); font-weight: 600; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; padding: 9px 12px; border: 1.5px solid var(--line); border-radius: var(--r); background: #fff; font-size: 0.85rem; }
.role-help { margin: 0; padding-left: 18px; font-size: 0.9rem; }
.role-help li { margin-bottom: 4px; }
.form-error { background: var(--rust-pale); color: var(--rust); border-radius: var(--r); padding: 9px 12px; font-size: 0.9rem; margin: 0 0 12px; }
