﻿/* ToolsPlan — Core Design System */
/* All component styles reference these variables. Never hardcode hex values. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Custom Properties ──────────────────────────────────────────────── */
:root {
  /* Brand */
  --color-brand:        #1B4FD8;
  --color-brand-light:  #DBEAFE;
  --color-brand-dark:   #1E3A8A;
  --color-brand-50:     #EFF6FF;
  --color-brand-200:    #BFDBFE;

  /* Semantic */
  --color-success:       #16A34A;
  --color-success-light: #DCFCE7;
  --color-warning:       #F59E0B;
  --color-warning-light: #FEF3C7;
  --color-danger:        #DC2626;
  --color-danger-light:  #FEE2E2;

  /* Neutrals */
  --color-slate:        #1A2332;
  --color-text:         #0F172A;
  --color-text-muted:   #64748B;
  --color-text-hint:    #94A3B8;
  --color-bg:           #F8FAFC;
  --color-surface:      #FFFFFF;
  --color-border:       #E2E8F0;
  --color-border-strong:#94A3B8;

  /* Pipeline stages */
  --stage-enquiry-bg:    #DBEAFE;
  --stage-enquiry-text:  #1E40AF;
  --stage-visit-bg:      #FEF3C7;
  --stage-visit-text:    #B45309;
  --stage-quote-bg:      #F3E8FF;
  --stage-quote-text:    #6B21A8;
  --stage-quoted-bg:     #CCFBF1;
  --stage-quoted-text:   #0F766E;
  --stage-progress-bg:   #DCFCE7;
  --stage-progress-text: #15803D;
  --stage-done-bg:       #F1F5F9;
  --stage-done-text:     #475569;
  --stage-lost-bg:       #FEE2E2;
  --stage-lost-text:     #991B1B;

  /* Typography */
  --font-sans:   'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   'JetBrains Mono', 'Courier New', Courier, monospace;
  --font-serif:  Georgia, 'Times New Roman', serif;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-6:  24px;
  --space-8:  32px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-card:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-focus: 0 0 0 3px rgba(27,79,216,0.12);

  /* Transitions */
  --transition: 150ms ease;

  /* Layout */
  --nav-width:      240px;
  --nav-width-icon: 56px;
  --content-max:    1200px;

  /* Extra spacing */
  --space-5:  20px;
  --space-10: 40px;
}

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

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

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

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

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

img, svg { display: block; max-width: 100%; }

button { cursor: pointer; font-family: var(--font-sans); }

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar Navigation ──────────────────────────────────────────────────── */
.app-nav {
  width: var(--nav-width);
  min-height: 100vh;
  background: var(--color-slate);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.app-nav__logo {
  height: 80px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  text-decoration: none;
}
.app-nav__logo img {
  height: 64px;
  width: auto;
}

.app-nav__logomark {
  width: 32px;
  height: 32px;
  background: var(--color-brand);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 14px;
}

.app-nav__name {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.app-nav__tagline {
  display: none;
}

.app-nav__links {
  flex: 1;
  padding: var(--space-3) 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-4);
  margin: 1px var(--space-2);
  border-radius: var(--radius-md);
  color: #9CA3AF;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #F9FAFB;
  text-decoration: none;
}

.nav-item.active {
  background: #111827;
  color: #F9FAFB;
  border-left: 3px solid var(--color-brand);
  padding-left: calc(var(--space-4) - 3px);
}

.nav-item .ti {
  font-size: 18px;
  color: #6B7280;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.nav-item.active .ti,
.nav-item:hover .ti {
  color: #60A5FA;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4B5563;
  padding: var(--space-3) var(--space-4) var(--space-1);
  margin-top: var(--space-2);
}

.app-nav__bottom {
  padding: var(--space-3);
  border-top: 1px solid rgba(255,255,255,0.06);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.nav-user__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.nav-user__info { min-width: 0; }

.nav-user__name {
  font-size: 13px;
  font-weight: 500;
  color: #F9FAFB;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-user__role {
  font-size: 11px;
  color: #6B7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.app-content {
  margin-left: var(--nav-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-8);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.page-header__mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 22px;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.02em;
  flex: 1;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.page-body {
  padding: var(--space-6) var(--space-8);
  flex: 1;
}

/* ── Two-column detail page layouts ─────────────────────────────────────── */
.job-detail-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--space-6);
  align-items: start;
}

.customer-detail-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--space-6);
  align-items: start;
}

.invoice-detail-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-6);
  align-items: start;
}

/* ── Trial Banner ────────────────────────────────────────────────────────── */
.trial-banner {
  background: var(--color-brand);
  color: #fff;
  text-align: center;
  padding: 8px var(--space-6);
  font-size: 13px;
  font-weight: 500;
}

.trial-banner a {
  color: #fff;
  font-weight: 600;
  text-decoration: underline;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity var(--transition), transform var(--transition), background var(--transition), box-shadow var(--transition);
  outline: none;
}

.btn:focus-visible { box-shadow: var(--shadow-focus); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--color-brand);
  color: #FFFFFF;
}
.btn-primary:hover { opacity: 0.88; text-decoration: none; color: #fff; }

.btn-secondary {
  background: transparent;
  color: var(--color-brand);
  border: 1.5px solid var(--color-brand);
}
.btn-secondary:hover { background: var(--color-brand-50); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 0.5px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-bg); text-decoration: none; color: var(--color-text); }

.btn-danger {
  background: var(--color-danger);
  color: #FFFFFF;
}
.btn-danger:hover { opacity: 0.88; text-decoration: none; color: #fff; }

.btn-success {
  background: var(--color-success);
  color: #FFFFFF;
}
.btn-success:hover { opacity: 0.88; text-decoration: none; color: #fff; }

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  min-height: 32px;
}

.btn-icon {
  padding: 8px;
  min-height: 36px;
  width: 36px;
  justify-content: center;
}

/* ── Form Components ─────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.form-control {
  background: var(--color-bg);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  height: 40px;
  font-size: 14px;
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-control::placeholder { color: var(--color-text-hint); }

.form-control:focus {
  outline: none;
  border: 1.5px solid var(--color-brand);
  box-shadow: var(--shadow-focus);
}

.form-control.error { border: 1.5px solid var(--color-danger); }

.form-error {
  font-size: 11px;
  color: var(--color-danger);
  margin-top: 2px;
}

textarea.form-control {
  height: auto;
  min-height: 80px;
  resize: vertical;
}

select.form-control { cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
}

.card-raised {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  box-shadow: var(--shadow-card);
}

.card-surface {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

/* ── Stat Cards ──────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.15;
  font-family: var(--font-mono);
}

.stat-value.money::before { content: '£'; font-size: 16px; font-weight: 500; vertical-align: top; margin-top: 4px; display: inline-block; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--color-border);
  background: var(--color-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--color-bg);
}

th {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 16px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 12px 16px;
  font-size: 13.5px;
  color: var(--color-text);
  border-bottom: 0.5px solid var(--color-border);
}

tr:last-child td { border-bottom: none; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--color-bg); }

.td-mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ── Badges / Status Pills ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  line-height: 1.4;
  white-space: nowrap;
}

/* Pipeline stages */
.stage-enquiry   { background: var(--stage-enquiry-bg);   color: var(--stage-enquiry-text); }
.stage-site-visit{ background: var(--stage-visit-bg);     color: var(--stage-visit-text); }
.stage-to-quote  { background: var(--stage-quote-bg);     color: var(--stage-quote-text); }
.stage-quoted    { background: var(--stage-quoted-bg);    color: var(--stage-quoted-text); }
.stage-in-progress { background: var(--stage-progress-bg); color: var(--stage-progress-text); }
.stage-done      { background: var(--stage-done-bg);      color: var(--stage-done-text); }
.stage-lost      { background: var(--stage-lost-bg);      color: var(--stage-lost-text); }

/* Invoice / quote statuses */
.badge-unpaid   { background: #FEE2E2; color: #B91C1C; }
.badge-partial  { background: #FEF3C7; color: #B45309; }
.badge-paid     { background: #DCFCE7; color: #15803D; }
.badge-overdue  { background: var(--color-danger); color: #FFFFFF; }
.badge-draft    { background: #F1F5F9; color: #475569; }
.badge-sent     { background: #DBEAFE; color: #1E40AF; }
.badge-accepted { background: #DCFCE7; color: #15803D; }
.badge-declined { background: #FEE2E2; color: #B91C1C; }

/* ── Search Bar ──────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-wrap .ti-search {
  position: absolute;
  left: 10px;
  color: var(--color-text-hint);
  font-size: 16px;
  pointer-events: none;
}

.search-input {
  padding-left: 34px;
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  height: 38px;
  width: 280px;
  font-size: 13.5px;
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder { color: var(--color-text-hint); }
.search-input:focus {
  outline: none;
  border: 1.5px solid var(--color-brand);
  box-shadow: var(--shadow-focus);
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  gap: var(--space-4);
}

.empty-state .ti {
  font-size: 40px;
  color: var(--color-text-hint);
}

.empty-state__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.empty-state__body {
  font-size: 13.5px;
  color: var(--color-text-hint);
  max-width: 320px;
}

/* ── Slide-Out Panel ─────────────────────────────────────────────────────── */
.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.35);
  z-index: 200;
  backdrop-filter: blur(2px);
}

.panel-overlay.open { display: block; }

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 100%;
  background: var(--color-surface);
  border-left: 0.5px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 201;
  transform: translateX(100%);
  transition: transform 200ms ease;
  box-shadow: -8px 0 32px rgba(0,0,0,0.08);
}

.panel.open { transform: translateX(0); }

.panel__header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 0.5px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.panel__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.panel__close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 20px;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.panel__close:hover { color: var(--color-text); background: var(--color-bg); }

.panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.panel__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 0.5px solid var(--color-border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 0.5px solid var(--color-border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal__header {
  padding: var(--space-6);
  border-bottom: 0.5px solid var(--color-border);
}

.modal__title {
  font-size: 17px;
  font-weight: 600;
  color: var(--color-text);
}

.modal__body { padding: var(--space-6); }

.modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 0.5px solid var(--color-border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* ── Toast Notifications ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--color-slate);
  color: #F9FAFB;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  transform: translateX(120%);
  opacity: 0;
  transition: transform 200ms ease, opacity 200ms ease;
  max-width: 320px;
}

.toast.show { transform: translateX(0); opacity: 1; }

.toast.toast-success { border-left: 3px solid var(--color-success); }
.toast.toast-error   { border-left: 3px solid var(--color-danger); }
.toast.toast-info    { border-left: 3px solid var(--color-brand); }

/* ── Dashboard Grid ──────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

/* ── Kanban Board ────────────────────────────────────────────────────────── */
.pipeline-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(190px, 1fr));
  gap: var(--space-4);
  align-items: start;
  overflow-x: auto;
  padding-bottom: var(--space-4);
}

.kanban-col {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--color-border);
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.kanban-col.drag-over {
  border-color: var(--color-brand);
  background: var(--color-brand-50);
}

.kanban-col__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 0.5px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.kanban-col__title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 1;
}

.kanban-col__count {
  font-size: 11px;
  font-weight: 600;
  background: var(--color-border);
  color: var(--color-text-muted);
  padding: 1px 7px;
  border-radius: 10px;
}

.kanban-col__cards {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
  min-height: 100px;
}

.kanban-col__total {
  padding: var(--space-2) var(--space-4);
  border-top: 0.5px solid var(--color-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  text-align: right;
}

.job-card {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-3) + 3px);
  cursor: grab;
  text-decoration: none;
  display: block;
  transition: border-color var(--transition);
  border-left: 3px solid transparent;
}

.job-card:hover { border-color: var(--color-border-strong); text-decoration: none; }
.job-card:active { cursor: grabbing; }
.job-card { position: relative; }
.job-card__delete {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  color: var(--color-text-hint); border-radius: 4px; line-height: 1;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.job-card:hover .job-card__delete { opacity: 1; }
.job-card__delete:hover { color: var(--color-danger); background: #fef2f2; }

.job-card.stage-enquiry    { border-left-color: var(--stage-enquiry-text); }
.job-card.stage-site-visit { border-left-color: var(--stage-visit-text); }
.job-card.stage-to-quote   { border-left-color: var(--stage-quote-text); }
.job-card.stage-quoted     { border-left-color: var(--stage-quoted-text); }
.job-card.stage-in-progress{ border-left-color: var(--stage-progress-text); }
.job-card.stage-done       { border-left-color: var(--stage-done-text); }
.job-card.stage-lost       { border-left-color: var(--stage-lost-text); }

.job-card__customer {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.job-card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
  line-height: 1.3;
}

.job-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.job-card__date {
  font-size: 11px;
  color: var(--color-text-hint);
}

.job-card__price {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
}

/* ── Calendar ────────────────────────────────────────────────────────────── */
.calendar-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.calendar-grid {
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
}

.calendar-day-headers {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--color-bg);
  border-bottom: 0.5px solid var(--color-border);
}

.calendar-day-header {
  padding: var(--space-2) var(--space-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  text-align: center;
  min-width: 0;
  overflow: hidden;
}

/* ── Cal view toggle buttons ─────────────────────────────────────────────── */
.cal-view-btns {
  display: flex;
  background: var(--color-bg);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.cal-view-btn {
  padding: 5px 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.cal-view-btn:hover { background: var(--color-surface); color: var(--color-text); }
.cal-view-btn.active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 0 0 0.5px var(--color-border);
}

/* Calendar: no outer border in week/day mode */
.cal-week-wrap { border: none !important; background: none !important; border-radius: 0 !important; }

.calendar-weeks {
  display: flex;
  flex-direction: column;
}

.calendar-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 0.5px solid var(--color-border);
}

.calendar-week:last-child { border-bottom: none; }

.calendar-day {
  min-height: 100px;
  min-width: 0;
  overflow: hidden;
  padding: var(--space-2) var(--space-3);
  border-right: 0.5px solid var(--color-border);
  cursor: pointer;
  transition: background var(--transition);
}

.calendar-day:last-child { border-right: none; }
.calendar-day:hover { background: var(--color-bg); }
.calendar-day.today { background: var(--color-brand-50); }
.calendar-day.other-month .day-num { color: var(--color-text-hint); }

.day-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.calendar-day.today .day-num {
  background: var(--color-brand);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.cal-job-pill {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  display: block;
}

/* ── Week View (vertical list) ───────────────────────────────────────────── */
.week-view {
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
}

.week-day-row {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 0.5px solid var(--color-border);
  min-height: 64px;
  cursor: pointer;
  transition: background var(--transition);
}
.week-day-row:last-child { border-bottom: none; }
.week-day-row:hover { background: var(--color-bg); }
.week-day-row.today { background: var(--color-brand-50); }

.week-day-label {
  width: 52px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2px;
}
.week-day-name {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
.week-day-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}
.week-day-row.today .week-day-num {
  background: var(--color-brand);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.week-day-jobs {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  justify-content: center;
}
.week-no-jobs { font-size: 12px; color: var(--color-text-hint); }

/* ── Day View ────────────────────────────────────────────────────────────── */
.day-view {
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
}
.day-view-body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 200px;
}
.day-job-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--color-border);
  text-decoration: none;
  background: var(--color-bg);
  transition: border-color var(--transition);
}
.day-job-item:hover { border-color: var(--color-border-strong); text-decoration: none; }
.day-job-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.day-job-info { flex: 1; min-width: 0; }
.day-job-customer { font-size: 11px; color: var(--color-text-muted); }
.day-job-title { font-size: 13.5px; font-weight: 600; color: var(--color-text); }

/* ── Pipeline scroll indicator ───────────────────────────────────────────── */
.pipeline-stage-nav-wrap { position: relative; }
.pipeline-stage-nav-fade { display: none; }

/* ── Job detail: mobile Actions block hidden on desktop ──────────────────── */
.job-actions-mobile { display: none; }

/* ── Materials Table (job detail) ────────────────────────────────────────── */
.materials-table td:nth-child(2),
.materials-table td:nth-child(3),
.materials-table td:nth-child(4) {
  font-family: var(--font-mono);
  font-size: 13px;
}

.materials-table .editable {
  border: none;
  background: transparent;
  font: inherit;
  width: 100%;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
}

.materials-table .editable:focus {
  outline: 1.5px solid var(--color-brand);
  background: var(--color-surface);
}

/* ── Photos Grid ─────────────────────────────────────────────────────────── */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
}

.photo-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 0.5px solid var(--color-border);
  position: relative;
  background: var(--color-bg);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Notes Timeline ──────────────────────────────────────────────────────── */
.notes-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.note-item {
  display: flex;
  gap: var(--space-3);
}

.note-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-brand);
  margin-top: 5px;
  flex-shrink: 0;
}

.note-content { flex: 1; }
.note-text { font-size: 13.5px; line-height: 1.6; color: var(--color-text); }
.note-meta { font-size: 11px; color: var(--color-text-hint); margin-top: 2px; }

/* ── Quote Builder ───────────────────────────────────────────────────────── */
.quote-line-items {
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.quote-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) 0;
}

.quote-total-row {
  display: flex;
  gap: var(--space-6);
  align-items: center;
  font-size: 13.5px;
}

.quote-total-row span:first-child { color: var(--color-text-muted); width: 120px; text-align: right; }
.quote-total-row span:last-child  { font-family: var(--font-mono); width: 100px; text-align: right; }

.quote-total-row.grand-total {
  font-size: 16px;
  font-weight: 700;
  padding-top: var(--space-3);
  border-top: 1.5px solid var(--color-text);
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6);
}

.tab {
  padding: 10px var(--space-4);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  margin-bottom: -1px;
}

.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-brand); border-bottom-color: var(--color-brand); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Filter Bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
}
.filter-bar__group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.filter-bar__label {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.filter-bar__input {
  width: 136px !important;
  font-size: 13px !important;
  padding: 5px 8px !important;
  height: auto !important;
}

/* ── Misc Utilities ──────────────────────────────────────────────────────── */
.text-muted   { color: var(--color-text-muted); }
.text-hint    { color: var(--color-text-hint); }
.text-danger  { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-brand   { color: var(--color-brand); }

.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 600; }

.text-right  { text-align: right; }
.text-center { text-align: center; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.divider {
  height: 0;
  border: none;
  border-top: 0.5px solid var(--color-border);
  margin: var(--space-4) 0;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

/* ── Hamburger / Mobile nav ──────────────────────────────────────────────── */
@media (max-width: 1023px) {
  /* Use opacity/visibility instead of transform.
     transform:translateX(-100%) on a position:fixed element creates a compositor
     layer that Chrome Android registers as off-screen overflow, which can shift
     the initial scroll position and make page content appear cut off. */
  .app-nav {
    transform: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 200ms ease, visibility 0ms linear 200ms;
  }
  .app-nav.mobile-open {
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 200ms ease, visibility 0ms;
    box-shadow: 4px 0 32px rgba(0,0,0,0.2);
  }
  .app-content { margin-left: 0; }
  .page-header__mobile-toggle { display: flex; }
  .page-body { padding: var(--space-4) var(--space-4); }
  .page-header { padding: var(--space-3) var(--space-4); }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .stats-grid { grid-template-columns: 1fr; }

  /* Pipeline: single-column stage view with tab nav */
  .pipeline-board {
    grid-template-columns: 1fr !important;
    overflow: hidden !important;
    scroll-snap-type: none !important;
    width: 100%;
  }
  .kanban-col {
    display: none;
    scroll-snap-align: none;
  }
  .kanban-col.mobile-active { display: flex; }

  /* Panel: fade in/out instead of slide from right.
     transform:translateX(100%) pushes the panel off the right edge of the viewport,
     which can cause Chrome on Android to register phantom horizontal overflow.
     Using opacity+visibility keeps the panel within the viewport boundary at all times. */
  .panel {
    width: 100%;
    transform: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 180ms ease, visibility 0ms linear 180ms;
  }
  .panel.open {
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 180ms ease, visibility 0ms;
  }
  .search-input { width: 100%; }

  /* Tables to card-list on mobile */
  .table-responsive thead { display: none; }
  .table-responsive tr {
    display: block;
    padding: var(--space-3) var(--space-4);
    border-bottom: 0.5px solid var(--color-border);
  }
  .table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border: none;
    font-size: 13px;
  }
  .table-responsive td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    margin-right: var(--space-3);
  }
  .table-responsive td:last-child::before { content: none; }
}

/* ── Nav mobile overlay ──────────────────────────────────────────────────── */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 99;
}
.nav-overlay.open { display: block; }

/* ── Pipeline mobile CTA (hidden — page header actions handle this) ──────── */
.pipeline-mobile-cta { display: none; }

/* ── Pipeline stage nav tabs (mobile only) ───────────────────────────────── */
.pipeline-stage-nav { display: none; }

@media (max-width: 767px) {
  /* Page header: title on row 1, actions wrap to row 2 */
  .page-header {
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-3);
  }
  .page-title { flex: 1; min-width: 0; }
  .page-actions {
    width: 100%;
    gap: var(--space-2);
  }
  .page-actions .search-wrap { flex: 1; min-width: 0; }
  .page-actions .search-input { width: 100%; }

  /* Stage tab strip */
  .pipeline-stage-nav {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding: 0 0 var(--space-3);
    margin-bottom: var(--space-4);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .pipeline-stage-nav::-webkit-scrollbar { display: none; }

  .stage-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--color-border);
    background: var(--color-surface);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .stage-tab.active {
    background: var(--tab-color, var(--color-brand));
    border-color: var(--tab-color, var(--color-brand));
    color: #fff;
  }
  .stage-tab__count {
    background: rgba(0,0,0,0.15);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
  }

  /* Two-column detail layouts collapse to one column on mobile.
     minmax(0,1fr) instead of bare 1fr: the 0 floor stops the track expanding
     to the content's min-content size (e.g. an unsized text input in the
     materials table that pushes the card wider than the viewport).
     overflow-x:hidden clips any residual overflow. */
  .job-detail-layout,
  .customer-detail-layout,
  .invoice-detail-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Direct grid children: allow shrinking below their min-content width.
     Without this a flex-column wrapper around the cards inherits auto
     min-width and forces the grid track wider than the available space. */
  .job-detail-layout > *,
  .customer-detail-layout > *,
  .invoice-detail-layout > * {
    min-width: 0;
  }

  /* Individual cards: same fix at the flex-item level so space-between
     inside .card-header uses the correct (constrained) card width. */
  .job-detail-layout .card,
  .job-detail-layout .card-surface,
  .customer-detail-layout .card,
  .customer-detail-layout .card-surface,
  .invoice-detail-layout .card,
  .invoice-detail-layout .card-surface {
    min-width: 0;
  }

  /* Job detail: constrain header row items so nothing bleeds past viewport */
  .job-meta-row { gap: var(--space-2) !important; row-gap: var(--space-2) !important; }
  .job-meta-row #stageSelector { max-width: 150px; }
  .job-meta-row span[style*="font-mono"] { white-space: nowrap; }
  .job-meta-row a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

  /* Materials table: scrollable on mobile, limit input widths so table fits better */
  .materials-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .materials-table .editable[type="number"] { width: 56px !important; }
  .materials-table th, .materials-table td { white-space: nowrap; }

  /* Notes add-note button: full width on mobile for easier tapping */
  .note-add-row { display: flex !important; justify-content: stretch !important; }
  .note-add-row .btn { width: 100%; justify-content: center; }

  /* Job actions: show mobile version after Notes, hide sidebar version */
  .job-actions-mobile { display: block; }
  .job-actions-sidebar { display: none !important; }

  /* Quote builder header grid */
  .card [style*="grid-template-columns:1fr auto"] {
    grid-template-columns: 1fr !important;
  }
  .card [style*="grid-template-columns:1fr auto"] > div:last-child {
    text-align: left !important;
  }

  /* Notes/terms grid in quote builder */
  .card [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Page header actions — wrap on small screens */
  .page-actions { flex-wrap: wrap; gap: var(--space-2); }

  /* Toast full width on mobile */
  .toast-container { left: var(--space-4); right: var(--space-4); }
  .toast { max-width: 100%; }

  /* Modal full width on mobile */
  .modal { max-width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-overlay.open { align-items: flex-end; padding: 0; }

  /* Tables - make them scrollable rather than collapsing */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Calendar mobile: smaller day cells */
  .calendar-day { min-height: 60px; padding: 4px; }
  .cal-job-pill { font-size: 9px; padding: 1px 4px; }

  /* Stat cards 2 per row on small mobile */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .stat-value { font-size: 20px; }

  /* Form rows stay single column */
  .form-row { grid-template-columns: 1fr; }

  /* Dashboard grid single column */
  .dashboard-grid { grid-template-columns: 1fr; }

  /* Buttons - full width when stacked */
  .btn-stack-mobile { width: 100%; justify-content: center; }

  /* History filters: search takes full row, date pickers below */
  .history-search { max-width: 100% !important; width: 100%; }
  .history-filters > div { width: 100%; }
  .history-filters [id="historyCount"] { margin-left: 0 !important; }

  /* Prevent horizontal overflow on mobile. */
  html, body { overflow-x: hidden; }
  .app-content { overflow-x: hidden; }

  /* Calendar: fit within viewport using abbreviated day names */
  .calendar-scroll-wrap { overflow-x: hidden; }
  .calendar-grid { min-width: unset; }
  .calendar-day { padding: 3px 3px; min-height: 64px; }
  .calendar-day-header { padding: 4px 2px; font-size: 0; } /* hide text */
  .calendar-day-header::after {
    content: attr(data-short);
    font-size: 10px;
    font-weight: 600;
    display: block;
    text-align: center;
  }
  .day-num { font-size: 11px; }
  .cal-job-pill { font-size: 9px; padding: 1px 3px; }
  .calendar-day.today .day-num { width: 18px; height: 18px; font-size: 9px; }

  /* Pipeline scroll fade indicator */
  .pipeline-stage-nav-fade {
    display: flex;
    position: absolute;
    right: 0;
    top: 0;
    bottom: var(--space-3);
    width: 48px;
    align-items: center;
    justify-content: flex-end;
    padding-right: 4px;
    background: linear-gradient(to right, transparent, var(--color-bg) 60%);
    pointer-events: none;
    font-size: 16px;
    color: var(--color-text-muted);
    transition: opacity 0.2s;
  }
  .pipeline-stage-nav-wrap.tabs-end .pipeline-stage-nav-fade { opacity: 0; }

  /* Cal view buttons smaller on mobile */
  .cal-view-btn { padding: 5px 9px; font-size: 12px; }

  /* Filter bar: stack vertically on mobile */
  .filter-bar { gap: var(--space-2); }
  .filter-bar__input { width: 120px !important; }
}

/* Second safety net: coarse-pointer (touch) devices up to 1024px wide.
   Catches phones in landscape and any viewport the 767px query misses. */
@media (max-width: 1024px) and (pointer: coarse) {
  .job-detail-layout,
  .customer-detail-layout,
  .invoice-detail-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .job-detail-layout > *,
  .customer-detail-layout > *,
  .invoice-detail-layout > *,
  .job-detail-layout .card,
  .job-detail-layout .card-surface,
  .customer-detail-layout .card,
  .customer-detail-layout .card-surface,
  .invoice-detail-layout .card,
  .invoice-detail-layout .card-surface { min-width: 0; }
  html, body { overflow-x: hidden; }
  .panel { transform: none; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 180ms ease, visibility 0ms linear 180ms; }
  .panel.open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 180ms ease, visibility 0ms; }
}
