:root { color-scheme: light; }
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Calibri, Arial, sans-serif;
  background: #F7F8FA; color: #1a1f2b; font-size: 14px;
}
.app { max-width: 1180px; margin: 0 auto; padding: 18px 20px 60px; }
.topbar {
  background: #031731; border-radius: 10px; padding: 16px 22px;
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px;
  border-bottom: 3px solid #D4AF37;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar img { height: 40px; }
.topbar h1 { color: #fff; font-size: 16px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.topbar p { color: #C8B375; margin: 2px 0 0; font-size: 11.5px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid #E2E5EA; flex-wrap: wrap; }
.tab-btn {
  border: none; background: none; padding: 9px 14px; font-size: 13px; font-weight: 600;
  color: #667085; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: #031731; border-bottom-color: #D4AF37; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi-card { background: #fff; border: 1px solid #E7E9ED; border-radius: 10px; padding: 14px 16px; }
.kpi-card .label { font-size: 11.5px; color: #7A8494; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.kpi-card .value { font-size: 21px; font-weight: 700; color: #031731; margin-top: 4px; }
.kpi-card .sub { font-size: 11.5px; color: #97A0AD; margin-top: 2px; }
.card { background: #fff; border: 1px solid #E7E9ED; border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: 14px; margin: 0 0 12px; color: #031731; }
.card h2 small { font-weight: 400; color: #97A0AD; font-size: 11.5px; margin-left: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
th { text-align: left; color: #7A8494; font-weight: 600; font-size: 11px; text-transform: uppercase;
     letter-spacing: .3px; padding: 7px 8px; border-bottom: 1px solid #E7E9ED; }
td { padding: 7px 8px; border-bottom: 1px solid #F0F1F4; vertical-align: top; }
tr:last-child td { border-bottom: none; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; border: 1px solid #DADFE5; border-radius: 6px; padding: 5px 7px; font-size: 12.5px;
  font-family: inherit; background: #fff; color: #1a1f2b;
}
textarea { resize: vertical; min-height: 32px; }
.btn {
  border: none; border-radius: 6px; padding: 7px 13px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; background: #031731; color: #fff;
}
.btn.secondary { background: #EEF0F3; color: #031731; }
.btn.gold { background: #D4AF37; color: #031731; }
.btn.danger { background: #fdeceb; color: #B3261E; }
.btn:disabled { opacity: .5; cursor: default; }
.row-actions { display: flex; gap: 6px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: capitalize; }
.pill.active, .pill.paid, .pill.resolved { background: #E4F3EA; color: #1E7A45; }
.pill.pending, .pill.draft, .pill.open { background: #FDF3DE; color: #92660D; }
.pill.overdue { background: #FBE7E6; color: #B3261E; }
.pill.sent, .pill.in-progress { background: #E7EEFB; color: #2255A8; }
.empty { color: #97A0AD; font-style: italic; font-size: 12.5px; padding: 10px 0; }
.grid2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.client-select { max-width: 220px; }
.note {
  background: #F7F8FA; border-left: 3px solid #D4AF37; border-radius: 6px; padding: 9px 12px;
  font-size: 12px; color: #4a5261; margin-bottom: 12px;
}
.comms-block { border: 1px solid #E7E9ED; border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.comms-block h3 { margin: 0 0 8px; font-size: 13px; color: #031731; }
.email-result { border: 1px solid #EDEFF2; border-radius: 6px; padding: 8px 10px; margin-top: 6px; background: #FBFBFC; }
.email-result .meta { font-size: 11px; color: #97A0AD; }
.email-result .subj { font-weight: 600; font-size: 12.5px; color: #1a1f2b; }
.small { font-size: 11.5px; color: #7A8494; }
canvas { max-height: 260px; }
.footer-note { text-align: center; color: #A5ADB8; font-size: 11px; margin-top: 22px; }
.role-badge {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08);
  border-radius: 20px; padding: 4px 10px 4px 12px; color: #C8B375; font-size: 11.5px; font-weight: 600;
}
.role-badge a {
  border: none; background: #0C2648; color: #fff; border-radius: 14px; padding: 3px 9px;
  font-size: 10.5px; cursor: pointer; font-weight: 600; text-decoration: none;
}
.doc-overlay {
  position: fixed; inset: 0; background: #6b7280cc; z-index: 900;
  display: none; align-items: flex-start; justify-content: center; overflow: auto; padding: 30px 16px;
}
.doc-overlay.open { display: flex; }
.doc-toolbar {
  max-width: 780px; margin: 0 auto 10px; display: flex; justify-content: space-between; align-items: center;
}
.doc-toolbar .btn { color: #fff; }
.doc-paper {
  background: #fff; max-width: 780px; margin: 0 auto 40px; padding: 40px 46px; border-radius: 6px;
  font-size: 12.5px; line-height: 1.55; color: #1a1f2b;
}
.doc-paper h1 { font-size: 18px; color: #031731; margin: 0 0 4px; }
.doc-paper h2.doc-h { font-size: 13.5px; color: #031731; margin: 22px 0 6px; border-bottom: 1px solid #E2E5EA; padding-bottom: 4px; }
.doc-paper p { margin: 0 0 10px; }
.doc-paper .doc-meta { color: #7A8494; font-size: 11.5px; margin-bottom: 18px; }
.doc-paper table.doc-table { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 12px; }
.doc-paper table.doc-table th { background: #031731; color: #fff; text-align: left; padding: 6px 8px; }
.doc-paper table.doc-table td { padding: 6px 8px; border-bottom: 1px solid #EEE; }
.doc-pagebreak { border-top: 2px dashed #DADFE5; margin: 34px 0; padding-top: 10px; }
.doc-sig-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.doc-sig-table td { border: 1px solid #DADFE5; padding: 10px; width: 50%; font-size: 12px; }
.doc-logo-header { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 3px solid #D4AF37; }
.doc-logo-header img { height: 46px; display: block; }
.doc-logo-header .doc-logo-text strong { color: #031731; font-size: 15px; display: block; }
.doc-logo-header .doc-logo-text span { color: #946200; font-size: 11px; }
@media print {
  body * { visibility: hidden; }
  #docOverlay, #docOverlay * { visibility: visible; }
  #docOverlay { position: absolute; inset: 0; background: #fff; padding: 0; overflow: visible; }
  .no-print { display: none !important; }
  .doc-paper { box-shadow: none; max-width: 100%; }
  .doc-pagebreak { break-before: page; border: none; margin: 0; padding: 0; }
}

/* Login page */
.gate-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate-card { background: #fff; border: 1px solid #E7E9ED; border-radius: 12px; padding: 28px 30px; width: 100%; max-width: 380px; }
.gate-card img { height: 34px; display: block; margin-bottom: 14px; }
.gate-card h2 { font-size: 15px; margin: 0 0 4px; color: #031731; }
.gate-card p.sub { font-size: 12px; color: #7A8494; margin: 0 0 16px; }
.role-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.role-toggle a {
  flex: 1; border: 1px solid #DADFE5; background: #fff; border-radius: 7px; padding: 9px;
  font-size: 12.5px; font-weight: 600; color: #4a5261; cursor: pointer; text-align: center; text-decoration: none; display: block;
}
.role-toggle a.selected { background: #031731; color: #fff; border-color: #031731; }
.gate-card input[type=password] { margin-bottom: 10px; }
.gate-error { color: #B3261E; font-size: 12px; margin-bottom: 10px; }
.gate-hint { font-size: 11.5px; color: #97A0AD; margin-top: 12px; }
.gate-hint a { color: #7A8494; cursor: pointer; text-decoration: underline; }
