/* ============================================================
   Customer Portal — CSS
   Inspired by LinkedIn's clean, professional aesthetic
   Fonts: Source Sans 3 + Source Serif 4
   ============================================================ */

/* ── Reset & Variables ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand */
  --brand:       #0a66c2;
  --brand-dark:  #004182;
  --brand-light: #e8f1fb;

  /* Neutrals */
  --bg:          #f3f2ef;
  --surface:     #ffffff;
  --border:      #e0ddd8;
  --text-primary:#000000e0;
  --text-secondary:#00000099;
  --text-muted:  #00000060;

  /* Status */
  --green:       #057642;
  --green-bg:    #e8f5ee;
  --red:         #b24020;
  --red-bg:      #fdf0ec;
  --amber:       #b45309;
  --amber-bg:    #fef3c7;
  --blue-bg:     #e8f1fb;
  --purple:      #6d28d9;
  --purple-bg:   #ede9fe;

  /* Layout */
  --topbar-h:    52px;
  --max-w:       1128px;
  --radius:      8px;
  --shadow:      0 0 0 1px var(--border), 0 2px 6px rgba(0,0,0,.06);
  --shadow-md:   0 4px 12px rgba(0,0,0,.12);

  /* Type */
  --font-sans:   'Source Sans 3', system-ui, sans-serif;
  --font-serif:  'Source Serif 4', Georgia, serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Ensures content area fills available space pushing footer down */
body > .topbar + .page-body {
  flex: 1;
}
/* For login page and pages without topbar */
body > .page-body:first-of-type,
body.login-body {
  flex: 1;
}

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

/* ── Top Bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
}
.topbar-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  flex-shrink: 0;
}
.logo-mark {
  width: 32px; height: 32px;
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  display: grid; place-items: center;
  font-weight: 700; font-size: .82rem;
  letter-spacing: .04em;
}
.logo-text {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}


.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 14px;
  border-radius: 4px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: .72rem;
  font-weight: 600;
  transition: color .15s;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--text-primary); text-decoration: none; }
.nav-link.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

/* Avatar */
.topbar-avatar {
  position: relative;
  cursor: pointer;
  margin-left: 8px;
}
.avatar-circle {
  width: 34px; height: 34px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: .9rem;
  transition: opacity .15s;
}
.topbar-avatar:hover .avatar-circle { opacity: .85; }
.avatar-dropdown {
  display: none;
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 200px;
  padding: 12px 0;
  z-index: 200;
}
.topbar-avatar.open .avatar-dropdown { display: block; }
.avatar-name  { font-weight: 700; padding: 4px 16px; font-size: .95rem; }
.avatar-email { color: var(--text-secondary); padding: 0 16px 8px; font-size: .82rem; }
.avatar-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.avatar-dropdown a {
  display: block;
  padding: 8px 16px;
  color: var(--text-primary);
  font-size: .9rem;
}
.avatar-dropdown a:hover { background: var(--bg); text-decoration: none; }

/* ── Page Body ─────────────────────────────────────────────── */
.page-body {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px 16px 60px;
  flex: 1 0 auto;
  width: 100%;
  box-sizing: border-box;
}

main { width: 100%; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 600;
}
.page-sub { color: var(--text-secondary); margin-top: 2px; font-size: .95rem; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1rem; font-weight: 700; }
.link-more { font-size: .85rem; color: var(--brand); }

/* ── Stat Grid ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card--warn { border-left: 3px solid var(--red); }

.stat-icon {
  width: 42px; height: 42px;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.stat-icon--blue   { background: var(--blue-bg);   color: var(--brand); }
.stat-icon--green  { background: var(--green-bg);  color: var(--green); }
.stat-icon--red    { background: var(--red-bg);    color: var(--red); }
.stat-icon--purple { background: var(--purple-bg); color: var(--purple); }

.stat-label { font-size: .78rem; color: var(--text-secondary); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.data-table th {
  background: var(--bg);
  text-align: left;
  padding: 10px 16px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f9f8f6; }
.data-table tfoot td {
  padding: 12px 16px;
  background: var(--bg);
  font-size: .9rem;
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge--lg { padding: 6px 14px; font-size: .85rem; }
.badge--paid    { background: var(--green-bg); color: var(--green); }
.badge--open    { background: var(--blue-bg);  color: var(--brand); }
.badge--overdue { background: var(--red-bg);   color: var(--red); }
.badge--draft   { background: var(--bg);       color: var(--text-secondary); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 20px;
  font-family: var(--font-sans);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, box-shadow .15s;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary {
  background: transparent;
  color: var(--brand);
  border: 1.5px solid var(--brand);
}
.btn-secondary:hover { background: var(--brand-light); text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); text-decoration: none; }
.btn-block { width: 100%; justify-content: center; border-radius: 24px; padding: 12px; font-size: 1rem; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.form-group--sm { flex: 0 0 120px; }
.form-group label { font-size: .82rem; font-weight: 700; color: var(--text-secondary); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: .95rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(10,102,194,.15);
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: .9rem;
  font-weight: 600;
}
.alert-error   { background: var(--red-bg);   color: var(--red);   border-left: 4px solid var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); border-left: 4px solid var(--green); }

/* ── Filter tabs ───────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  text-decoration: none;
  transition: all .15s;
}
.filter-tab:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.filter-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Pagination ────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; justify-content: center; padding: 16px; }
.page-btn {
  min-width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 4px;
  font-size: .85rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  transition: all .15s;
}
.page-btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
}

/* ── Dashboard ─────────────────────────────────────────────── */
.dashboard {}

/* ── Invoices page ─────────────────────────────────────────── */
.back-link { display: inline-block; color: var(--brand); font-size: .88rem; margin-bottom: 4px; }
.invoice-detail-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}
.invoice-meta { padding: 20px; }
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.meta-row:last-child { border-bottom: none; }
.meta-row span:first-child { color: var(--text-secondary); }
.meta-total { font-size: 1.05rem; }
.meta-total strong { font-size: 1.2rem; }

/* ── Profile page ──────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  align-items: start;
}
.profile-sidebar { padding: 28px 20px; text-align: center; }
.profile-avatar {
  width: 72px; height: 72px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 auto 14px;
}
.profile-name    { font-weight: 700; font-size: 1.05rem; }
.profile-company { color: var(--text-secondary); font-size: .88rem; margin-top: 2px; }
.profile-meta    { margin-top: 16px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.profile-meta-item {
  display: flex; align-items: center; gap: 8px;
  font-size: .85rem; color: var(--text-secondary);
}
.profile-since { margin-top: 16px; font-size: .78rem; color: var(--text-muted); }

.profile-details { padding: 0; }
.profile-form  { padding: 20px; }
.detail-section { padding: 20px; border-bottom: 1px solid var(--border); }
.detail-section:last-child { border-bottom: none; }
.detail-section h3 { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-item--full { grid-column: 1/-1; }
.detail-item label { font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.detail-item span  { font-size: .95rem; }

/* ── Login page ────────────────────────────────────────────── */
body.login-body { background: var(--surface); }
.login-split {
  display: flex;
  min-height: 100vh;
}

.login-hero {
  flex: 1;
  background: linear-gradient(135deg, #004182 0%, #0a66c2 60%, #0d8ecf 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.login-hero-inner {
  position: relative;
  z-index: 1;
  padding: 60px 56px;
  max-width: 480px;
}
.hero-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 48px;
}
.hero-logo .logo-mark {
  background: rgba(255,255,255,.2);
  width: 40px; height: 40px; font-size: 1rem;
}
.hero-logo .logo-text { font-size: 1.1rem; color: #fff; font-weight: 700; }
.hero-headline {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  line-height: 1.2;
  margin-bottom: 36px;
  font-weight: 600;
}
.hero-headline em { font-style: italic; font-weight: 400; }
.hero-features { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.hero-features li { display: flex; align-items: center; gap: 12px; font-size: 1rem; opacity: .9; }
.hero-bg-shape {
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  bottom: -140px; right: -100px;
}

.login-form-panel {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
}
.login-card { width: 100%; }
.login-card h2 { font-size: 1.5rem; font-weight: 700; font-family: var(--font-serif); margin-bottom: 6px; }
.login-sub  { color: var(--text-secondary); font-size: .9rem; margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-help { text-align: center; margin-top: 20px; font-size: .85rem; color: var(--text-secondary); }

/* ── Footer ────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .78rem;
  background: var(--surface);
  flex-shrink: 0;
  margin-top: auto;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 860px) {
  .login-hero { display: none; }
  .login-form-panel { width: 100%; }
  .invoice-detail-grid { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .nav-link span { display: none; }
}

/* ── Additional elements ─────────────────────────────────────────────────── */

/* Type pill (Invoice vs Estimate tag in dashboard) */
.type-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.type-pill--invoice  { background: var(--blue-bg);   color: var(--brand); }
.type-pill--estimate { background: var(--purple-bg); color: var(--purple); }

/* Balance due highlight in invoice meta */
.meta-balance-due { color: var(--red); }
.meta-balance-due strong { color: var(--red); }

/* Invoice notes section */
.invoice-notes {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.notes-block strong { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); display: block; margin-bottom: 4px; }
.notes-block p { font-size: .9rem; color: var(--text-secondary); }

/* Meta address block */
.meta-address {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  line-height: 1.6;
  color: var(--text-secondary);
}
.meta-address-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Probability badge (estimates) */
.probability-badge {
  background: var(--purple-bg);
  color: var(--purple);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 700;
}

/* Profile additions */
.profile-title  { color: var(--text-secondary); font-size: .88rem; margin-top: 2px; }
.profile-ids    { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; font-size: .78rem; color: var(--text-muted); }
.avatar-company { color: var(--text-muted); padding: 0 16px 4px; font-size: .78rem; }

/* Text helpers */
.text-muted { color: var(--text-muted); }

/* Badge status additions */
.badge--new      { background: var(--bg);        color: var(--text-secondary); }
.badge--open     { background: var(--blue-bg);   color: var(--brand); }
.badge--paid     { background: var(--green-bg);  color: var(--green); }
.badge--overdue  { background: var(--red-bg);    color: var(--red); }
.badge--sent     { background: var(--amber-bg);  color: var(--amber); }
.badge--approved { background: var(--green-bg);  color: var(--green); }
.badge--declined { background: var(--red-bg);    color: var(--red); }
.badge--draft    { background: var(--bg);        color: var(--text-muted); }

/* ── New feature styles ──────────────────────────────────────────────────── */

/* Date filter on dashboard */
.date-filter {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Estimate accept/decline actions */
.estimate-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Ticket styles */
.ticket-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.ticket-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.ticket-item:last-child { border-bottom: none; }
.ticket-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.ticket-subject { font-weight: 700; font-size: .95rem; margin-bottom: 3px; }
.ticket-meta    { font-size: .78rem; color: var(--text-muted); }
.ticket-reply {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--blue-bg);
  border-left: 3px solid var(--brand);
  border-radius: 0 4px 4px 0;
  font-size: .88rem;
  color: var(--text-secondary);
}
.ticket-reply-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--brand);
  margin-bottom: 4px;
}

/* Priority badges */
.badge--priority-low    { background: var(--bg);       color: var(--text-muted); }
.badge--priority-normal { background: var(--blue-bg);  color: var(--brand); }
.badge--priority-high   { background: var(--red-bg);   color: var(--red); }

@media (max-width: 768px) {
  .ticket-grid { grid-template-columns: 1fr; }
  .date-filter { display: none; }
}

/* ── Invoice / Estimate detail layout ───────────────────────────────────── */
.invoice-layout { display: flex; flex-direction: column; gap: 16px; }
.invoice-header-grid { display: grid; gap: 16px; }

/* Totals section — sits BELOW table-wrap, inside same card */
.invoice-totals {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 20px;
  border-top: 2px solid var(--border);
  flex-wrap: wrap;
}
.totals-left  { flex: 1; min-width: 180px; }
.totals-right { min-width: 260px; width: 260px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.totals-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.total-row:last-child { border-bottom: none; }
.total-row span:first-child { color: var(--text-secondary); }
.total-row span:last-child  { font-weight: 600; text-align: right; }
.total-row--grand {
  background: var(--bg);
  font-weight: 700;
  font-size: 1rem;
}
.total-row--grand span { font-weight: 700; color: var(--text-primary) !important; }
.total-row--balance {
  background: var(--red-bg);
}
.total-row--balance span { color: var(--red) !important; font-weight: 700; }

@media (max-width: 640px) {
  .invoice-totals { flex-direction: column; }
  .totals-right { width: 100%; min-width: unset; }
}

/* ── Login page additions ────────────────────────────────────────────────── */
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: .85rem;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-links {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  font-size: .85rem;
}
.login-links a { color: var(--text-secondary); }
.login-links a:hover { color: var(--brand); }

/* ── Signature pad ────────────────────────────────────────────────────────── */
.signature-section {
  padding: 20px;
  border-top: 2px solid var(--border);
}
.signature-section h3 {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.signature-pad-wrap {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  cursor: crosshair;
  touch-action: none;
  transition: border-color .15s;
}
.signature-pad-wrap:hover,
.signature-pad-wrap.active { border-color: var(--brand); }
.signature-pad-wrap canvas  { display: block; width: 100%; height: 200px; }
.signature-pad-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: .9rem;
  pointer-events: none;
  transition: opacity .2s;
}
.signature-pad-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.signature-pad-actions small { color: var(--text-muted); font-size: .78rem; }
.signature-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #fafafa;
  text-align: center;
}
.signature-preview img { max-height: 80px; }
.signature-meta {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--text-muted);
}
.signature-meta span strong { color: var(--text-primary); }

/* ── Documents page ───────────────────────────────────────────────────────── */
.doc-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
  background: var(--bg);
}
.doc-upload-zone:hover,
.doc-upload-zone.dragover {
  border-color: var(--brand);
  background: #eff6ff;
}
.doc-upload-zone input[type=file] { display: none; }
.doc-upload-icon {
  width: 48px; height: 48px;
  background: var(--brand-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s;
}
.doc-item:hover { border-color: var(--brand); }
.doc-icon {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: #fff;
}
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.doc-actions { display: flex; gap: 6px; align-items: center; }
.upload-progress {
  height: 4px; background: var(--border); border-radius: 2px; margin-top: 12px; overflow: hidden; display: none;
}
.upload-progress-bar { height: 100%; background: var(--brand); border-radius: 2px; width: 0; transition: width .3s; }

/* ── Dark Mode ────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:              #0f1117;
  --bg-card:         #1a1d27;
  --bg-hover:        #22263a;
  --surface:         #1a1d27;
  --text-primary:    #f0f2f8;
  --text-secondary:  #a0a8c0;
  --text-muted:      #606880;
  --border:          #2a2f45;
  --brand:           #3b82f6;
  --brand-light:     #1e3a5f;
  --red:             #f87171;
  --red-bg:          #2d0a0a;
  --green:           #4ade80;
  --green-bg:        #052e16;
  --amber:           #fbbf24;
  --amber-bg:        #1c1400;
}
[data-theme="dark"] body                { background: var(--bg); color: var(--text-primary); }
[data-theme="dark"] .topbar            { background: #13162080; border-bottom-color: var(--border); }
[data-theme="dark"] .card              { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .card-header       { border-bottom-color: var(--border); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea           { background: var(--bg-card); border-color: var(--border); color: var(--text-primary); }
[data-theme="dark"] .btn-ghost         { border-color: var(--border); color: var(--text-secondary); }
[data-theme="dark"] .btn-ghost:hover   { background: var(--bg-hover); }
[data-theme="dark"] table              { color: var(--text-primary); }
[data-theme="dark"] th                 { background: var(--bg-hover); color: var(--text-secondary); }
[data-theme="dark"] tr:hover td        { background: var(--bg-hover); }
[data-theme="dark"] .stat-card         { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .doc-item,
[data-theme="dark"] .invoice-layout    { background: var(--bg-card); }
[data-theme="dark"] .invoice-meta      { background: var(--bg-card); }
[data-theme="dark"] .meta-row          { border-bottom-color: var(--border); }
[data-theme="dark"] .meta-row:nth-child(even) { background: var(--bg-hover); }
[data-theme="dark"] .site-footer       { border-top-color: var(--border); color: var(--text-muted); }
[data-theme="dark"] mark               { background: #854d0e; color: #fef9c3; }
[data-theme="dark"] #chat-window       { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .chat-msg--ai      { background: var(--bg-hover); border-color: var(--border); color: var(--text-primary); }
[data-theme="dark"] #search-dropdown   { background: var(--bg-card); border-color: var(--border); }

/* Dark mode toggle button */
.dark-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: .78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .15s;
}
.dark-toggle:hover { border-color: var(--brand); color: var(--brand); }

/* ── Dark Mode — Additional coverage ─────────────────────────────────────── */
[data-theme="dark"] .site-footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}
[data-theme="dark"] .page-body {
  background: var(--bg);
}
/* Invoice/Estimate totals & subtotal section */
[data-theme="dark"] .invoice-totals,
[data-theme="dark"] .total-row,
[data-theme="dark"] .total-row--grand,
[data-theme="dark"] .total-row--balance { 
  border-color: var(--border);
  color: var(--text-primary);
}
[data-theme="dark"] .total-row { border-bottom-color: var(--border); }
[data-theme="dark"] .totals-right { border-color: var(--border) !important; background: var(--bg-card); }
[data-theme="dark"] .totals-label { color: var(--text-muted); background: var(--bg-hover); }
[data-theme="dark"] .totals-left  { color: var(--text-primary); }
[data-theme="dark"] .total-row--grand { background: var(--bg-hover) !important; }
[data-theme="dark"] .total-row--balance { background: var(--red-bg) !important; }
[data-theme="dark"] .invoice-notes { background: var(--bg-hover); }
[data-theme="dark"] .line-items-table th { background: var(--bg-hover); color: var(--text-secondary); }
[data-theme="dark"] .line-items-table td { border-bottom-color: var(--border); }
[data-theme="dark"] .line-items-table tr:nth-child(even) td { background: var(--bg-hover); }
/* Search dropdown */
[data-theme="dark"] #search-dropdown {
  background: var(--bg-card) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] #search-dropdown input {
  background: transparent;
  color: var(--text-primary);
}
[data-theme="dark"] #search-results-preview a:hover { background: var(--bg-hover) !important; }
/* AI chat window */
[data-theme="dark"] #chat-window {
  background: var(--bg-card) !important;
  border: 1px solid var(--border);
}
[data-theme="dark"] #chat-messages { background: var(--bg-card); }
[data-theme="dark"] #chat-window > div:last-child {
  background: var(--bg-card);
  border-top-color: var(--border);
}
[data-theme="dark"] #chat-input {
  background: var(--bg) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}
[data-theme="dark"] .chat-msg--ai {
  background: var(--bg-hover) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}
/* Filter tabs */
[data-theme="dark"] .filter-tab { 
  color: var(--text-secondary);
  border-color: var(--border);
}
[data-theme="dark"] .filter-tab.active { 
  background: var(--brand); 
  color: #fff; 
  border-color: var(--brand);
}
/* Page header */
[data-theme="dark"] .page-header { border-bottom-color: var(--border); }
/* Alerts */
[data-theme="dark"] .alert-success { background: #052e16; border-left-color: var(--green); color: var(--green); }
[data-theme="dark"] .alert-error   { background: #450a0a; border-left-color: var(--red);   color: var(--red); }
/* Badges */
[data-theme="dark"] .badge--paid    { background: #052e16; color: #4ade80; }
[data-theme="dark"] .badge--new,
[data-theme="dark"] .badge--open    { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge--overdue { background: #450a0a; color: #fca5a5; }
/* Stat cards */
[data-theme="dark"] .stat-card { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .stat-value { color: var(--text-primary); }
[data-theme="dark"] .stat-label { color: var(--text-muted); }
/* Doc items */
[data-theme="dark"] .doc-item { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .doc-upload-zone { background: var(--bg-hover); border-color: var(--border); }
/* Upload modal */
[data-theme="dark"] #upload-modal > div > div { background: var(--bg-card); }
/* Topbar */
[data-theme="dark"] .topbar { background: var(--bg-card); border-bottom-color: var(--border); }
[data-theme="dark"] .logo-text { color: var(--text-primary); }
[data-theme="dark"] .nav-link  { color: var(--text-secondary); }
[data-theme="dark"] .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); }
[data-theme="dark"] .nav-link:hover  { color: var(--brand); }
[data-theme="dark"] .avatar-circle   { background: var(--brand); }
[data-theme="dark"] .avatar-dropdown { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .avatar-dropdown a { color: var(--text-secondary); }
[data-theme="dark"] .avatar-dropdown hr { border-color: var(--border); }
