:root {
  color-scheme: dark;
  --bg: #0C192B;
  --fg: #E6EDF7;
  --muted: #94A3B8;
  --accent: #7DD3FC;
  --error: #fca5a5;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

main {
  max-width: 28rem;
  margin: 4rem auto;
  padding: 0 1.5rem;
}

h1 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
  letter-spacing: 0.01em;
}

h2 {
  margin: 0.25rem 0 1.5rem 0;
  font-size: 1.25rem;
  font-weight: 500;
}

p { margin: 0.5rem 0; }

.muted { color: var(--muted); }
.error { color: var(--error); }

form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

label {
  font-size: 0.875rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  border: 0;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

button.ghost:hover {
  color: var(--fg);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

#message:empty { display: none; }

button.oauth {
  margin-top: 1rem;
  width: 100%;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(148, 163, 184, 0.25);
}

.jobs {
  margin: 1.5rem 0;
}

.jobs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0 0.75rem 0;
}

.jobs-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.new-job-form {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.new-job-form label {
  margin-top: 0.25rem;
}

.new-job-form .form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.hidden {
  display: none;
}

.job {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.job:last-child {
  margin-bottom: 0;
}

.job-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.job p {
  margin: 0.25rem 0;
}

.job-meta {
  font-size: 0.875rem;
}

.status-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.status-scheduled {
  background: rgba(125, 211, 252, 0.15);
  color: var(--accent);
}

.status-in_progress {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

.status-done {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

.empty {
  font-style: italic;
}

.job {
  cursor: pointer;
  transition: border-color 120ms ease;
}

.job:hover,
.job:focus-visible {
  border-color: rgba(125, 211, 252, 0.5);
  outline: none;
}

.job-detail {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 1rem;
}

.job-detail #back-to-list {
  align-self: flex-start;
  padding-left: 0;
}

.job-detail-row {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding-bottom: 0.5rem;
}

.job-detail-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.job-detail-label {
  flex: 0 0 6rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.status-actions button {
  align-self: flex-start;
}

.status-actions p {
  margin: 0;
  font-size: 0.875rem;
}

.admin-section {
  margin: 1.5rem 0;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1.5rem;
}

.invite-form {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.invite-form label {
  margin-top: 0.25rem;
}

.invite-form select {
  width: 100%;
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.invite-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.invite-form .form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.inv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  font-size: 0.875rem;
}

.inv-row:last-child {
  border-bottom: 0;
}

.users-section {
  margin-top: 1rem;
}

.users-section h4 {
  margin: 0 0 0.25rem 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  font-size: 0.875rem;
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-shrink: 0;
}

.user-row select {
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.user-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.assign-select {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.assign-select:focus {
  outline: none;
  border-color: var(--accent);
}

.assign-btns {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.375rem;
}

.notes-section {
  margin-top: 1.5rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1rem;
}

.notes-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.notes-head h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.note-item {
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding: 0.5rem 0;
  font-size: 0.9375rem;
}

.note-item:last-child {
  border-bottom: 0;
}

.note-item p {
  margin: 0;
}

.note-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.25rem !important;
}

.add-note-form {
  margin-top: 0.75rem;
  gap: 0.5rem;
}

.add-note-form textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.9375rem;
  resize: vertical;
  min-height: 4.5rem;
}

.add-note-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.photos-section {
  margin-top: 1.5rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1rem;
}

.photos-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.photos-head h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.photo-thumb {
  width: 5rem;
  height: 5rem;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  cursor: pointer;
}

.upload-photo-label {
  display: inline-block;
  cursor: pointer;
}

.upload-photo-btn {
  cursor: pointer;
}

.schedule-day {
  margin: 1rem 0 0.375rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.schedule-day:first-child {
  margin-top: 0;
}

.schedule-empty {
  font-style: italic;
}

.field-app {
  font-size: 18px;
}

.field-app button {
  min-height: 48px;
  padding: 0.875rem 1.25rem;
}

.field-app .ghost {
  min-height: unset;
  padding: 0.375rem 0.75rem;
}

.conflict-warning {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  color: #fbbf24;
}

.conflict-warning p {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}

.estimates-section {
  margin-top: 1.5rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1rem;
}

.estimates-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.estimates-head h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.estimate-item {
  padding: 0.625rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.estimate-item:last-child {
  border-bottom: 0;
}

.estimate-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.status-draft {
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
}

.status-sent {
  background: rgba(125, 211, 252, 0.15);
  color: var(--accent);
}

.status-accepted {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

.status-declined {
  background: rgba(252, 165, 165, 0.15);
  color: var(--error);
}

.line-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  margin-bottom: 0.25rem;
}

.line-items-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 0.25rem 0.375rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.line-items-table td {
  padding: 0.3125rem 0.375rem;
  vertical-align: top;
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 4rem 5rem auto;
  gap: 0.375rem;
  align-items: center;
  margin-bottom: 0.375rem;
}

.line-item-row input {
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
}

.line-item-total {
  text-align: right;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0.375rem 0;
  color: var(--fg);
}

.estimate-status-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.375rem;
}

.new-estimate-form {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 1rem;
  margin-top: 0.75rem;
  gap: 0.5rem;
}

.new-estimate-form label {
  margin-top: 0.25rem;
}

.new-estimate-form textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.9375rem;
  resize: vertical;
  min-height: 3rem;
}

.new-estimate-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.new-estimate-form .form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

/* ── Invoices ─────────────────────────────────────────────────────── */

.invoice-section {
  margin-top: 1.5rem;
}

.invoice-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.invoice-section-head h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
}

.invoice-item {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.625rem;
}

.invoice-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.invoice-convert-row {
  margin-top: 0.375rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.invoice-status-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.375rem;
}

.payment-form {
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  margin-top: 0.625rem;
  padding-top: 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.payment-form label {
  font-size: 0.8125rem;
  color: var(--muted);
}

.payment-form input {
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
  border-radius: 4px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font: inherit;
}

.payment-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.payment-form .form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.25rem;
}

/* ── Portal (portal.sparkshark.com) ───────────────────────────────────── */

.portal-shell {
  max-width: 36rem;
  margin: 3rem auto;
  padding: 0 1.25rem;
}

.portal-resource {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 10px;
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.portal-header {
  margin-bottom: 0.25rem;
}

.portal-brand {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
}

.portal-brand-sub {
  font-size: 0.8125rem;
  margin: 0.125rem 0 0;
}

.portal-line-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.portal-line-items th,
.portal-line-items td {
  padding: 0.5rem 0.625rem;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.portal-line-items th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.portal-line-items td:nth-child(2),
.portal-line-items td:nth-child(3),
.portal-line-items td:nth-child(4),
.portal-line-items th:nth-child(2),
.portal-line-items th:nth-child(3),
.portal-line-items th:nth-child(4) {
  text-align: right;
}

.portal-line-items tfoot td {
  border-bottom: none;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 0.625rem;
}

.portal-line-items .total-label {
  color: var(--muted);
  font-size: 0.875rem;
}

.portal-line-items .total-amount {
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent);
}

.portal-notes {
  font-size: 0.875rem;
  color: var(--muted);
  white-space: pre-wrap;
  margin: 0;
}

.portal-cta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.portal-cta button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 7px;
  border: none;
  background: var(--accent);
  color: #0C192B;
  cursor: pointer;
  transition: opacity 0.15s;
}

.portal-cta button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.portal-status-accepted {
  background: rgba(125, 211, 252, 0.08);
  border: 1px solid rgba(125, 211, 252, 0.25);
  border-radius: 7px;
  padding: 1rem 1.25rem;
  color: var(--accent);
  font-size: 0.9375rem;
}

.portal-status-accepted p {
  margin: 0;
}

.portal-error {
  background: rgba(252, 165, 165, 0.06);
  border: 1px solid rgba(252, 165, 165, 0.2);
  border-radius: 7px;
  padding: 1.25rem;
  color: var(--error);
}

.portal-error p {
  margin: 0;
}

/* ── Ops: send-portal-link block (estimates list) ─────────────────────── */

.send-portal-link {
  margin-top: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: rgba(125, 211, 252, 0.05);
  border: 1px solid rgba(125, 211, 252, 0.15);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.portal-url-row {
  display: flex;
  gap: 0.375rem;
  align-items: center;
}

.portal-url-input {
  flex: 1;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-family: inherit;
  cursor: text;
}

.portal-copy-btn {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.portal-copy-btn:hover {
  background: rgba(125, 211, 252, 0.08);
}

.portal-stats {
  font-size: 0.75rem;
  color: var(--muted);
}
