:root {
  --ink: #1c2320;
  --paper: #f4f1ea;
  --panel: #ffffff;
  --line: #dcd6c8;
  --brand: #1f6f5c;
  --brand-dark: #165545;
  --muted: #6b6459;
  --warn: #b5541c;
  --danger: #a5261f;
  --ok: #2c7a45;
  --header-bg: #17181a;
  --gold: #b08d3d;
  --gold-light: #d4b56a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--brand-dark); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin: 10px 0 4px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--header-bg); color: #fff;
  border-bottom: 1px solid var(--gold);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; }
.brand-mark { background: #fff; color: var(--header-bg); border: 1px solid var(--gold); border-radius: 6px; padding: 2px 6px; font-size: 13px; }
.nav-links { display: flex; gap: 18px; }
.nav-links a { color: #e7e5df; text-decoration: none; font-size: 14px; }
.nav-links a.router-link-active { font-weight: 700; color: var(--gold-light); text-decoration: underline; text-decoration-color: var(--gold); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { text-align: right; font-size: 12px; line-height: 1.3; }
.user-name { font-weight: 700; }
.user-role { opacity: 0.85; }
.link-btn { background: none; border: none; color: inherit; text-decoration: underline; padding: 0; font-size: 13px; }

.sync-pill { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.15); border: none; color: #fff; padding: 5px 10px; border-radius: 999px; font-size: 12px; }
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #7be0a8; }
.sync-pill.offline .dot { background: #e0a87b; }
.sync-pill.syncing .dot { background: #f5d76e; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.page { max-width: 1080px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }

.data-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.data-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 8px; border-bottom: 1px solid #eee6d6; font-size: 14px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #fbf9f3; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eee6d6; color: var(--ink); text-transform: capitalize; }
.badge-warn { background: var(--warn); color: #fff; }
.badge-ok { background: #dcecdf; color: var(--ok); }
.lost-time-row { opacity: 0.7; font-style: italic; }

.tab-row { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab-btn { background: none; border: none; padding: 8px 16px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--brand); }
.search-row { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; }
.priority-urgent, .priority-high { background: #f6d9cd; color: var(--danger); }
.priority-medium { background: #f5e9c8; color: #7a5a12; }
.priority-low { background: #dcecdf; color: var(--ok); }
.stage-invoiced, .stage-closed, .stage-completed { background: #dcecdf; color: var(--ok); }
.stage-in_progress, .stage-scheduled { background: #f5e9c8; color: #7a5a12; }
.stage-awaiting_analysis, .stage-report_pending_approval { background: #f6d9cd; color: var(--danger); }
.stage-analysis_in_progress { background: #f5e9c8; color: #7a5a12; }
.invstatus-draft { background: #eee6d6; }
.invstatus-pending_approval { background: #f5e9c8; color: #7a5a12; }
.invstatus-approved { background: #d9e6f6; color: #1d4e89; }
.invstatus-sent { background: #dcecdf; color: var(--ok); }
.pay-paid { background: #dcecdf; color: var(--ok); }
.pay-overdue { background: #f6d9cd; color: var(--danger); }
.profit-badge { margin-left: 10px; font-size: 13px; vertical-align: middle; cursor: help; }
.file-picker-btn { display: inline-flex; align-items: center; cursor: pointer; white-space: nowrap; }
.attach-ok { color: var(--ok); font-weight: 700; }

.mana-signature { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--gold); display: flex; justify-content: center; opacity: 0.8; }
.mana-signature img { height: 32px; width: auto; }
.pay-partial, .pay-sent { background: #f5e9c8; color: #7a5a12; }

.primary-btn { background: var(--brand); color: #fff; border: none; padding: 9px 16px; border-radius: 7px; font-weight: 600; font-size: 14px; }
.primary-btn:disabled { opacity: 0.6; }
.secondary-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); padding: 7px 12px; border-radius: 7px; font-size: 13px; }
.chip-btn { background: #eee6d6; border: none; padding: 5px 10px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.chip-btn.active { background: var(--brand); color: #fff; }

.crm-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.crm-column { flex: 0 0 220px; background: #fbf9f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.crm-column h3 { margin-top: 0; }
.crm-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; font-size: 13px; }
.crm-card:hover { background: #fbf9f3; }
.crm-card-title { font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 12px; margin-bottom: 8px; }
.checkbox-grid label { font-weight: 400; color: var(--ink); font-size: 13px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.inline-form input, .inline-form select { flex: 1 1 120px; min-width: 90px; }
.stacked-form { display: flex; flex-direction: column; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20,20,15,0.4); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 20; }
.modal-card { background: var(--panel); border-radius: 10px; padding: 22px; width: 100%; max-width: 560px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.error { color: var(--danger); font-size: 13px; }
.required-field { border-color: var(--danger) !important; }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 360px; }
.demo-row { margin-top: 16px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.action-row { display: flex; gap: 10px; margin-bottom: 10px; }
.grand-total { font-size: 18px; }

.archived-row { opacity: 0.55; }
.archived-banner { background: #f5e9c8; color: #7a5a12; padding: 8px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

.expandable-text {
  display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: bottom;
}
.expandable-text.clickable { cursor: pointer; text-decoration: underline dotted; }
.expandable-text.expanded {
  max-width: none; white-space: pre-wrap; word-break: break-word; display: block;
}

.print-invoice { max-width: 800px; margin: 0 auto; padding: 30px; background: #fff; color: #111; }
.print-header { display: flex; justify-content: space-between; margin-bottom: 20px; font-size: 13px; }
.print-logo { display: block; max-width: 220px; max-height: 70px; margin-bottom: 8px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.calendar-weekday { padding: 6px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fbf9f3; border-bottom: 1px solid var(--line); }
.calendar-cell { min-height: 110px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff; }
.calendar-cell:nth-child(7n) { border-right: none; }
.calendar-dim { background: #fbf9f3; color: var(--muted); }
.calendar-today .calendar-date { background: var(--brand); color: #fff; border-radius: 999px; padding: 0 6px; }
.calendar-date { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.calendar-job { background: var(--paper); border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; cursor: pointer; font-size: 12px; }
.calendar-job:hover { background: #eee6d6; }
.calendar-job-title { font-weight: 600; }
.calendar-job-site { font-size: 11px; }
.calendar-avatars { display: flex; gap: 3px; margin-top: 3px; flex-wrap: wrap; }
.calendar-avatar { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-size: 9px; font-weight: 700; }
.print-addresses { display: flex; justify-content: space-between; margin-bottom: 20px; font-size: 13px; gap: 30px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 16px; }
.print-table th { text-align: left; border-bottom: 2px solid #111; padding: 4px 8px; }
.print-table td { padding: 4px 8px; border-bottom: 1px solid #ddd; }
.print-totals { margin-left: auto; width: 260px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.print-totals .grand-total { border-top: 2px solid #111; padding-top: 6px; margin-top: 4px; font-size: 16px; }
@media print { .no-print { display: none; } }

.attachment-list { list-style: none; padding: 0; margin: 0 0 8px; }
.attachment-list li { padding: 4px 0; }

.conflict-json { background: #f6f3ea; padding: 8px; border-radius: 6px; font-size: 11px; overflow-x: auto; max-height: 160px; }

.welcome-heading { font-size: 32px; margin: 4px 0 18px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.quick-action-btn { display: inline-block; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--gold); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 600; background: var(--panel); transition: background 0.15s ease; }
.quick-action-btn:hover { background: #f7f0dd; }

.recent-jobs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.recent-job-card { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: var(--ink); background: var(--panel); transition: box-shadow 0.15s ease, border-color 0.15s ease; }
.recent-job-card:hover { border-color: var(--gold); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.recent-job-icon { color: var(--brand); margin-bottom: 6px; }
.recent-job-title { font-weight: 700; margin-bottom: 2px; }
.recent-job-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 11px; }

.stat-number { font-size: 30px; font-weight: 700; margin: 4px 0; }
.trend-up { color: var(--ok); font-size: 12px; margin: 0; }
.trend-down { color: var(--danger); font-size: 12px; margin: 0; }
.trend-flat { color: var(--muted); font-size: 12px; margin: 0; }

@media (max-width: 720px) {
  .grid-2, .grid-3, .checkbox-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .nav-links { order: 3; width: 100%; justify-content: space-between; }
}
