:root {
  /* Brand — Bwalo Books. Terracotta is the one accent color: buttons, links, active
     states, logo. Status colors (info/amber/green/red) are kept separate from the
     brand color on purpose, so "this is clickable" and "this is a status" never look
     the same. */
  --blue: #3e5c8a;       /* status only: "sent" / "awaiting payment" pill */
  --blue-dark: #2f4a70;
  --brand: #d9601f;      /* terracotta — primary accent, overridden per-org via JS to the org's own brand color */
  --brand-dark: #b34e18;
  --bwalo-accent: #d9601f; /* fixed — always terracotta, never overridden. Reserved for bwalo's own "Powered by" credit. */
  --gold: #e8a33d;       /* secondary accent — highlights, progress bars */
  --green: #17825a;
  --red: #c4362d;
  --amber: #b8790a;
  --bg: #f7f3ec;
  --panel: #ffffff;
  --border: #e7e0d3;
  --text: #221f1c;
  --muted: #7a7266;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #f1ece1; color: var(--text); }
.btn-secondary:hover { background: #e7e0d1; }
.btn-danger { background: #fdecea; color: var(--red); }
.btn-danger:hover { background: #fbdedb; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #f3d9c4; border-color: var(--brand); }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; }

/* ---- auth screens ---- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #201d1a, #46301f 55%, #d9601f);
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 34px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(20,15,10,.35);
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.auth-card button[type=submit] { width: 100%; padding: 10px; margin-top: 6px; }
.auth-switch { margin-top: 16px; font-size: 13px; text-align: center; color: var(--muted); }
.auth-error { background: #fdecea; color: var(--red); padding: 8px 10px; border-radius: 7px; font-size: 13px; margin-bottom: 12px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 18px; }
.brand .wordmark { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--text); }
.brand .wordmark .accent { color: var(--brand); }
.brand .wordmark-bar { width: 26px; height: 4px; border-radius: 2px; background: var(--brand); }

/* ---- app shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #201d1a;
  color: #d8d1c4;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
}
.sidebar .brand { padding: 0 8px; margin-bottom: 22px; }
.sidebar .brand .wordmark { color: #fdfaf5; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #b8b0a0;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sidebar nav a:hover { background: #2c2723; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar .org { font-size: 12px; color: #948c7c; padding: 8px; border-top: 1px solid #332e28; margin-top: 8px; }
.sidebar .org b { color: #efe9dd; display: block; }
.sidebar .logout { margin-top: 8px; background: transparent; color: #b8b0a0; text-align: left; font-weight: 600; }
.sidebar .logout:hover { color: #fff; }

/* ---- per-org branding in the sidebar (own logo/name, colored by --brand which JS sets per org) ---- */
.sidebar-brand { display: flex; align-items: center; gap: 9px; padding: 0 8px; margin-bottom: 22px; min-width: 0; }
.org-mark-img { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; flex-shrink: 0; background: #fff; }
.org-mark-fallback {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.org-mark-name {
  color: #fdfaf5; font-weight: 700; font-size: 14.5px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- fixed "Powered by bwalo" credit — always terracotta, never the org's own brand color ---- */
.powered-by {
  font-size: 11px; color: #7d766a; padding: 10px 8px 2px; margin-top: auto;
  display: flex; align-items: center; gap: 5px;
}
.powered-by .wordmark-sm { font-weight: 800; letter-spacing: -0.01em; color: #b8b0a0; }
.powered-by .wordmark-sm .accent { color: var(--bwalo-accent); }
.powered-by-print {
  margin-top: 24px; padding-top: 10px; border-top: 1px solid #e7e0d3;
  font-size: 10.5px; color: #a39c8e; text-align: center;
}
.powered-by-print .accent { color: #d9601f; font-weight: 800; }

.main { flex: 1; min-width: 0; }
.topbar {
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { margin: 0; font-size: 19px; }
.content { padding: 24px 28px; max-width: 1180px; }

/* ---- cards / grid ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card .value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.card .value.pos { color: var(--green); }
.card .value.neg { color: var(--red); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-header h3 { margin: 0; font-size: 15px; }

.org-header-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; margin-bottom: 18px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.org-header-banner img { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; }
.org-header-name { font-size: 16px; font-weight: 700; }
.org-header-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px 10px; border-bottom: 1px solid #f0ebe0; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
table.compact td, table.compact th { padding: 6px 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row td { text-align: center; color: var(--muted); padding: 26px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; }
.pill-draft { background: #f1ece1; color: #6b6255; }
.pill-sent, .pill-awaiting_payment { background: #e8ecf3; color: var(--blue); }
.pill-partial { background: #fff4e0; color: var(--amber); }
.pill-paid { background: #e6f6ee; color: var(--green); }
.pill-void { background: #fdecea; color: var(--red); }
.pill-overdue { background: #fdecea; color: var(--red); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; }
.spacer { flex: 1; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(30,22,15,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; padding: 26px 26px 22px;
  width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(25,18,10,.3);
}
.modal.wide { max-width: 760px; }
.modal h3 { margin: 0 0 18px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.line-items-table input, .line-items-table select { padding: 6px 8px; font-size: 12.5px; }
.line-items-table td { padding: 6px 4px; }
.totals-box { margin-left: auto; width: 240px; margin-top: 10px; }
.totals-box div { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.totals-box .grand { font-weight: 800; font-size: 15px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border-radius: 0; padding: 9px 4px; margin-right: 18px; color: var(--muted); font-weight: 700; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.muted { color: var(--muted); }
.section-title { font-weight: 700; font-size: 13.5px; margin: 18px 0 8px; }
.help-text { font-size: 12px; color: var(--muted); margin-top: 6px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff;
  padding: 11px 18px; border-radius: 8px; font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.error { background: var(--red); }
.icon-btn { background: transparent; padding: 4px 8px; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---- public marketing home page ---- */
.home { max-width: 1080px; margin: 0 auto; padding: 0 24px 60px; }
.home-nav { display: flex; align-items: center; justify-content: space-between; padding: 22px 0; }
.home-nav .brand { margin-bottom: 0; }
.home-nav-actions { display: flex; gap: 10px; align-items: center; }
.home-nav-actions .btn-primary, .home-nav-actions .btn-secondary { text-decoration: none; display: inline-flex; align-items: center; }

.home-hero { text-align: center; padding: 48px 0 40px; }
.home-hero h1 { font-size: 36px; line-height: 1.2; margin: 0 0 16px; letter-spacing: -0.01em; max-width: 760px; margin-left: auto; margin-right: auto; }
.home-hero-sub { font-size: 16px; color: var(--muted); max-width: 620px; margin: 0 auto 26px; line-height: 1.6; }
.home-hero-actions { display: flex; gap: 12px; justify-content: center; }
.home-hero-actions a { text-decoration: none; padding: 11px 22px; font-size: 14.5px; border-radius: var(--radius); font-weight: 700; }

.home-section { padding: 40px 0; }
.home-section h2 { font-size: 24px; text-align: center; margin: 0 0 8px; }
.home-section-sub { text-align: center; color: var(--muted); margin: 0 0 28px; font-size: 14px; }
.home-section-alt { background: var(--panel); border-radius: 16px; border: 1px solid var(--border); }

.legal-body h2 { font-size: 16.5px; text-align: left; margin: 26px 0 8px; }
.legal-body h2:first-child { margin-top: 0; }
.legal-body p { margin: 0 0 12px; line-height: 1.65; font-size: 14px; color: var(--text); }
.legal-body p.help-text { font-size: 12.5px; }

.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 26px; }
.feature-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.feature-card h3 { margin: 0 0 8px; font-size: 16px; }
.feature-card p { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.feature-card ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text); line-height: 1.8; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; padding: 30px; }
.step { text-align: center; }
.step-num {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; margin: 0 auto 12px;
}
.step h3 { margin: 0 0 6px; font-size: 15px; }
.step p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.pricing-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: stretch; }
.pricing-card {
  position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 26px 22px; display: flex; flex-direction: column;
}
.pricing-card.highlighted { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.pricing-badge {
  position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
  background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.4px; padding: 3px 10px; border-radius: 999px;
}
.pricing-card h3 { margin: 4px 0 4px; font-size: 18px; }
.pricing-tagline { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; min-height: 32px; }
.pricing-price { margin-bottom: 18px; }
.pricing-price .amount { font-size: 30px; font-weight: 800; }
.pricing-price .period { color: var(--muted); font-size: 13px; margin-left: 2px; }
.pricing-features { list-style: none; margin: 0 0 22px; padding: 0; flex: 1; }
.pricing-features li { font-size: 13px; padding: 6px 0; border-top: 1px solid var(--border); }
.pricing-features li:first-child { border-top: none; }
.pricing-cta { text-align: center; text-decoration: none; padding: 10px; border-radius: var(--radius); font-weight: 700; font-size: 13.5px; }

.home-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 30px; margin-top: 20px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12.5px; flex-wrap: wrap;
}
.home-footer .powered-by { padding: 0; color: var(--muted); }
.home-footer .powered-by .wordmark-sm { color: var(--text); }
.faq-list { max-width: 720px; margin: 24px auto 0; display: flex; flex-direction: column; gap: 10px; }
.faq-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px;
}
.faq-item summary {
  cursor: pointer; font-weight: 700; font-size: 14px; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; font-size: 18px; font-weight: 400; color: var(--muted); margin-left: 12px; }
.faq-item[open] summary::after { content: '−'; }
.faq-item p { margin: 10px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.faq-item p a { color: var(--brand); font-weight: 600; }
.home-footer-cols { display: flex; flex-direction: column; gap: 6px; }
.home-footer-contact { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.home-footer-contact a { color: var(--muted); text-decoration: none; }
.home-footer-contact a:hover { color: var(--brand); text-decoration: underline; }
.home-footer-contact span { color: var(--border); }

@media (max-width: 860px) {
  .feature-grid, .steps, .pricing-grid { grid-template-columns: 1fr; }
  .home-hero h1 { font-size: 28px; }
}

/* ---- Settings > Billing tab ---- */
.current-plan-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.current-plan-name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.current-plan-price { font-size: 14px; color: var(--muted); margin-top: 4px; }
.usage-row { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.usage-row:last-child { border-bottom: none; }
.billing-plan-list { display: flex; flex-direction: column; gap: 10px; }
.billing-plan-row { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; gap: 10px; }
.billing-plan-row.current { border-color: var(--brand); background: #fdf7f2; }
.billing-plan-row-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.billing-plan-row-right { display: flex; align-items: center; gap: 10px; }
.billing-plan-row-price { font-weight: 700; font-size: 13.5px; color: var(--muted); }

.trial-banner {
  background: #fdf7f2; border: 1px solid var(--gold); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 18px; font-size: 13.5px; line-height: 1.5;
}
.trial-banner a { color: var(--brand); font-weight: 700; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
