/* BlackCrest Invoicing
   Dark charcoal app shell in the site's own gold/serif brand; the invoice
   itself flips to a clean paper sheet since financial documents need to
   print well and read as professional correspondence. */

:root {
  --ink: #14120f;
  --panel: #1e1b17;
  --panel-2: #262019;
  --line: #35302a;
  --gold: #c9a961;
  --gold-dim: #8a7645;
  --text: #ece6d9;
  --text-soft: #b3aa98;
  --paper: #faf7f1;
  --paper-line: #e4dccb;
  --ink-on-paper: #241f18;
  --green: #74936a;
  --rust: #b3573f;
  --blue-grey: #7c93a6;
  --grey: #7a7264;
  --radius: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: 'Montserrat', -apple-system, Segoe UI, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.6em;
  letter-spacing: 0.01em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; font-family: 'Montserrat', sans-serif; font-weight: 600; font-size: 0.78rem; }

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-soft); }
.error { color: #e0897a; background: rgba(179, 87, 63, 0.12); border: 1px solid rgba(179, 87, 63, 0.4); padding: 0.6em 0.9em; border-radius: var(--radius); }
.success { color: #9bc28f; background: rgba(116, 147, 106, 0.12); border: 1px solid rgba(116, 147, 106, 0.4); padding: 0.6em 0.9em; border-radius: var(--radius); }

/* ---------- Header / nav ---------- */

.app-header { background: var(--panel); border-bottom: 1px solid var(--line); }
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 0.4rem; }
.brand-word { font-family: 'Cormorant Garamond', serif; font-weight: 700; font-size: 1.5rem; color: var(--text); }
.brand-sub { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }

.main-nav { display: flex; gap: 1.35rem; flex-wrap: wrap; }
.main-nav a { color: var(--text-soft); font-size: 0.85rem; font-weight: 500; letter-spacing: 0.02em; }
.main-nav a:hover { color: var(--gold); text-decoration: none; }
.main-nav a.active { color: var(--gold); }

.roofline { position: relative; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-dim) 15%, var(--gold) 50%, var(--gold-dim) 85%, transparent); }
.roofline::after {
  content: "";
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 7px solid var(--gold);
}

.app-main { max-width: 1080px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

/* ---------- Buttons / forms ---------- */

.btn {
  display: inline-block;
  padding: 0.55em 1.1em;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
.btn:hover { border-color: var(--gold-dim); text-decoration: none; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #1a1710; }
.btn-primary:hover { background: #d8b876; }
.btn-danger { background: transparent; border-color: var(--rust); color: #e0897a; }
.btn-danger:hover { background: rgba(179, 87, 63, 0.15); }
.btn-ghost { background: transparent; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 0.3em 0.7em; font-size: 0.78rem; }

label { display: block; font-size: 0.78rem; color: var(--text-soft); margin-bottom: 0.9rem; font-weight: 500; }
label.checkbox-line { display: flex; align-items: center; gap: 0.5em; font-size: 0.85rem; }
label.checkbox-line input { margin: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.35em;
  padding: 0.55em 0.7em;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus, button:focus, a:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}
input[readonly] { color: var(--text-soft); background: var(--panel-2); }
textarea { resize: vertical; }
input[type="color"] { padding: 0.2em; height: 2.4em; }
input[type="checkbox"] { width: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.5rem;
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head-tight { margin-bottom: 1rem; }
.section-heading { margin-top: 2rem; }

.form-actions { display: flex; gap: 0.75rem; }
.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; margin: 0 0.5rem 0.75rem 0; }
.add-item-form { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.75rem; }
.add-item-form input { width: auto; flex: 1 1 140px; margin-top: 0; }

/* ---------- Stat cards ---------- */

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 720px) { .stat-row { grid-template-columns: 1fr; } }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.3rem; display: flex; flex-direction: column; gap: 0.3rem; }
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-soft); }
.stat-value { font-family: 'Cormorant Garamond', serif; font-size: 1.8rem; font-weight: 600; color: var(--gold); }

.filter-row { display: flex; gap: 0.6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.filter-row input, .filter-row select { width: auto; margin-top: 0; }
.filter-row input[type="text"] { flex: 1 1 220px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.data-table, .items-table, .invoice-items-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.data-table th, .items-table th, .invoice-items-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  border-bottom: 1px solid var(--line);
  padding: 0.5em 0.6em;
}
.data-table td, .items-table td, .invoice-items-table td {
  padding: 0.4em 0.6em;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.data-table input, .items-table input { margin-top: 0; }
.num { text-align: right; }
.center { text-align: center; }
.row-actions a { margin-right: 0.8em; font-size: 0.82rem; }

.badge { display: inline-block; padding: 0.2em 0.7em; border-radius: 999px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }
.status-draft { background: rgba(122, 114, 100, 0.2); color: var(--grey); }
.status-sent { background: rgba(124, 147, 166, 0.18); color: var(--blue-grey); }
.status-paid { background: rgba(116, 147, 106, 0.2); color: var(--green); }
.status-overdue { background: rgba(179, 87, 63, 0.2); color: #e0897a; }

/* ---------- Invoice line-item editor ---------- */

.quick-add-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.quick-add-row select { width: auto; margin-top: 0; min-width: 160px; }
.items-table .item-desc { min-width: 180px; }
.items-table td { padding: 0.3em 0.4em; }
.btn-remove-row { background: transparent; border: none; color: var(--text-soft); font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0.2em 0.5em; }
.btn-remove-row:hover { color: #e0897a; }

.totals-box { max-width: 360px; margin-left: auto; margin-top: 1rem; }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.4em 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.totals-row.total-row { border-bottom: none; border-top: 1px solid var(--gold-dim); margin-top: 0.3em; padding-top: 0.6em; font-size: 1.1rem; color: var(--gold); font-weight: 600; }
.tax-inputs { display: flex; align-items: center; gap: 0.4em; }
.tax-label-input { width: 90px; margin-top: 0; display: inline-block; }
.tax-rate-input { width: 60px; margin-top: 0; display: inline-block; }

/* ---------- Tabs (price lists) ---------- */

.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tab { padding: 0.6em 1em; color: var(--text-soft); font-size: 0.85rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--gold); text-decoration: none; }
.tab-active { color: var(--gold); border-bottom-color: var(--gold); }
.list-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---------- Auth pages ---------- */

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 2.2rem; max-width: 380px; width: 100%; box-shadow: var(--shadow); }
.auth-brand { justify-content: center; margin-bottom: 0.9rem; }
.auth-card .roofline { margin-bottom: 1.4rem; }
.auth-card p.muted { font-size: 0.85rem; margin-bottom: 1.2rem; }
.auth-card form button { margin-top: 0.4rem; }

/* ---------- Invoice sheet (screen) ---------- */

.view-toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

.invoice-sheet {
  background: var(--paper);
  color: var(--ink-on-paper);
  border-radius: var(--radius);
  padding: 2.5rem;
  max-width: 800px;
  margin: 0 auto;
  box-shadow: var(--shadow);
}
.invoice-letterhead { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; }
.invoice-biz .biz-name { font-size: 1.6rem; margin-bottom: 0.3rem; color: var(--ink-on-paper); }
.invoice-biz div { font-size: 0.85rem; color: #57503f; }
.invoice-meta { text-align: right; font-size: 0.85rem; color: #57503f; }
.invoice-meta h2 { color: var(--gold-dim); font-size: 1.7rem; margin-bottom: 0.3rem; }
.invoice-meta div { margin-bottom: 0.1rem; }

.invoice-roofline { position: relative; height: 1px; background: linear-gradient(90deg, transparent, var(--gold) 15%, var(--gold) 85%, transparent); margin: 1.3rem 0 1.5rem; }
.invoice-roofline::after {
  content: "";
  position: absolute;
  top: -5px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--gold);
}

.invoice-parties { display: flex; gap: 3rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.invoice-parties h3 { color: var(--gold-dim); margin-bottom: 0.4rem; }
.invoice-parties div { font-size: 0.9rem; }

.invoice-items-table th { color: #8a806a; border-bottom: 1px solid var(--paper-line); }
.invoice-items-table td { border-bottom: 1px solid var(--paper-line); font-size: 0.9rem; }

.invoice-totals { max-width: 320px; margin-left: auto; margin-top: 0.5rem; }
.invoice-totals .totals-row { border-bottom: 1px solid var(--paper-line); font-size: 0.9rem; }
.invoice-totals .total-row { border-top: 1px solid var(--gold); border-bottom: none; color: var(--gold-dim); font-weight: 700; font-size: 1.15rem; }

.invoice-notes { margin-top: 1.8rem; font-size: 0.85rem; color: #57503f; }
.invoice-notes h3 { color: var(--gold-dim); }
.invoice-footer { margin-top: 2.2rem; text-align: center; font-family: 'Cormorant Garamond', serif; font-style: italic; color: #8a806a; font-size: 1rem; }

/* ---------- Print ---------- */

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .app-main { padding: 0; max-width: none; }
  .invoice-sheet { box-shadow: none; padding: 0; max-width: none; }
}
