/* ─── Vision Fences CRM — Stylesheet ─────────────────────────────────────── */
:root {
  --primary:    #1a5276;
  --primary-d:  #154360;
  --accent:     #27ae60;
  --accent-d:   #1e8449;
  --danger:     #e74c3c;
  --warning:    #f39c12;
  --info:       #2980b9;
  --bg:         #f0f2f5;
  --card:       #ffffff;
  --border:     #dde1e7;
  --text:       #2c3e50;
  --text-light: #7f8c8d;
  --sidebar-w:  240px;
  --topbar-h:   56px;
  --radius:     8px;
  --shadow:     0 2px 8px rgba(0,0,0,.09);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100vw; overflow-x: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }

/* ─── Login ──────────────────────────────────────────────────────────────── */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1a5276 0%, #154360 100%); }
.login-card { background: #fff; border-radius: 12px; padding: 40px; width: 360px; box-shadow: 0 8px 32px rgba(0,0,0,.2); text-align: center; }
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-card h1 { font-size: 22px; color: var(--primary); margin-bottom: 4px; }
.login-sub { color: var(--text-light); margin-bottom: 28px; }
.login-card .form-group { text-align: left; margin-bottom: 16px; }
.btn-full { width: 100%; margin-top: 8px; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--primary); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; transition: transform .25s; }
.sidebar-header { display: flex; align-items: center; padding: 16px; border-bottom: 1px solid rgba(255,255,255,.1); gap: 10px; }
.sidebar-logo { font-size: 24px; }
.sidebar-title { font-weight: 700; font-size: 15px; flex: 1; }
.sidebar-close { display: none; background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; padding: 10px 20px; color: rgba(255,255,255,.8); gap: 10px; cursor: pointer; transition: background .15s; font-size: 14px; position: relative; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-item.active { border-left: 3px solid #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: auto; }
.badge-red { background: var(--danger); }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.btn-link { background: none; border: none; color: rgba(255,255,255,.7); cursor: pointer; font-size: 12px; }
.btn-link:hover { color: #fff; }

.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.page-title { font-size: 18px; font-weight: 600; flex: 1; }
.content { padding: 24px; flex: 1; }

/* ─── Cards & Stats ───────────────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.stat-label { font-size: 12px; color: var(--text-light); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.stat-card.green  { border-left-color: var(--accent); }
.stat-card.green .stat-value { color: var(--accent); }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.red .stat-value { color: var(--danger); }
.stat-card.orange { border-left-color: var(--warning); }
.stat-card.orange .stat-value { color: var(--warning); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: #f8f9fa; font-size: 12px; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
.table-actions { display: flex; gap: 6px; }

/* ─── Badges / Status ─────────────────────────────────────────────────────── */
.status { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.status-New       { background: #e8f5e9; color: #2e7d32; }
.status-Contacted { background: #e3f2fd; color: #1565c0; }
.status-Quoted    { background: #fff8e1; color: #e65100; }
.status-Won       { background: #e8f5e9; color: #2e7d32; }
.status-Lost      { background: #fce4ec; color: #c62828; }
.status-Sent      { background: #e3f2fd; color: #1565c0; }
.status-Accepted  { background: #e8f5e9; color: #2e7d32; }
.status-Paid      { background: #e8f5e9; color: #2e7d32; }
.status-Overdue   { background: #fce4ec; color: #c62828; }
.status-Scheduled { background: #e3f2fd; color: #1565c0; }
.status-Complete  { background: #e8f5e9; color: #2e7d32; }
.status-Draft     { background: #f5f5f5; color: #666; }
.status-Pending   { background: #fff8e1; color: #e65100; }
.status-Skipped   { background: #f5f5f5; color: #999; }
.status-Failed    { background: #fce4ec; color: #c62828; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: background .15s; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success   { background: var(--accent); color: #fff; }
.btn-success:hover { background: var(--accent-d); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f5f5f5; }
.btn-sm        { padding: 5px 12px; font-size: 13px; }
.btn-xs        { padding: 3px 8px; font-size: 12px; }
.btn-icon      { padding: 6px 8px; }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group   { margin-bottom: 16px; }
.form-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
label         { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--text); }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; color: var(--text); background: #fff; outline: none; transition: border .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,82,118,.1); }
textarea      { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 8px; }

/* ─── Alerts ──────────────────────────────────────────────────────────────── */
.alert         { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert-error   { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert-info    { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal         { background: #fff; border-radius: 10px; width: 100%; max-width: 600px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-header  { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-header button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-light); }
.modal-body    { padding: 24px; overflow-y: auto; flex: 1; }
.modal-lg      { max-width: 800px; }

/* ─── Toast ───────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #333; color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.2); animation: slideIn .2s ease; }
.toast-success { background: var(--accent); }
.toast-error   { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Quote builder ───────────────────────────────────────────────────────── */
.quote-items   { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 16px; }
.quote-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 80px 36px; gap: 8px; padding: 10px 12px; align-items: center; border-bottom: 1px solid var(--border); }
.quote-item-row:last-child { border-bottom: none; }
.quote-item-header { background: #f8f9fa; font-size: 12px; font-weight: 600; color: var(--text-light); }
.quote-totals  { text-align: right; padding: 12px; background: #f8f9fa; border-top: 1px solid var(--border); }
.quote-totals div { margin-bottom: 4px; }
.quote-totals .grand-total { font-size: 16px; font-weight: 700; color: var(--primary); }

/* ─── Job tiles (Jobs page upcoming-jobs grid) ────────────────────────────── */
.job-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.job-tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.job-tile-head  { display: flex; justify-content: space-between; align-items: center; }
.job-tile-name  { font-size: 16px; font-weight: 700; color: var(--text); }
.job-tile-addr  { font-size: 13px; color: var(--text-light); }
.job-tile-spec  { font-size: 13px; color: var(--text); }
.job-tile-spec strong { color: var(--text); }
.job-tile-price { font-size: 18px; font-weight: 700; color: var(--primary); margin-top: 4px; }
.job-tile-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.job-tile-actions .btn { flex: 1; min-width: 110px; }

/* ─── Calendar ────────────────────────────────────────────────────────────── */
.cal-header    { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cal-grid      { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day-label { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-light); padding: 6px 0; text-transform: uppercase; }
.cal-day       { border: 1px solid var(--border); border-radius: 6px; padding: 6px; min-height: 80px; background: #fff; }
.cal-day.other-month { background: #fafafa; opacity: .5; }
.cal-day.today { border-color: var(--primary); border-width: 2px; }
.cal-date      { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.cal-event     { background: var(--primary); color: #fff; font-size: 11px; padding: 2px 5px; border-radius: 3px; margin-bottom: 2px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event.complete { background: var(--accent); }
.cal-event.in-progress { background: var(--warning); }

/* ─── Filters & search ────────────────────────────────────────────────────── */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { max-width: 200px; }
.search-input { max-width: 260px !important; }

/* ─── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 17px; color: var(--text); margin-bottom: 8px; }

/* ─── Misc ────────────────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); font-size: 13px; }
.divider  { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.mt-16    { margin-top: 16px; }
.mb-16    { margin-bottom: 16px; }
.flex     { display: flex; }
.flex-1   { flex: 1; }
.gap-10   { gap: 10px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ─── Control Center ──────────────────────────────────────────────────────── */
.cc-quick-capture { display: flex; gap: 8px; margin-bottom: 18px; padding: 10px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.cc-quick-capture input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.cc-quick-capture select { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: #fff; }

.cc-section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-light); margin: 20px 4px 10px; font-weight: 600; }

.cc-top-row     { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 8px; }
.cc-project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.cc-ops-grid    { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.cc-tile { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 540px; overflow: hidden; }
.cc-tile-today { border-top: 3px solid var(--primary); }
.cc-tile-due   { border-top: 3px solid var(--warning); }
.cc-project-tile { border-top: 3px solid var(--accent); }

.cc-tile-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.cc-tile-title  { font-weight: 600; font-size: 14px; }
.cc-tile-count  { background: #eef2f7; color: var(--text-light); padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.cc-tile-count-red    { background: #fee2e2; color: #b91c1c; }
.cc-tile-count-orange { background: #ffedd5; color: #c2410c; }
.cc-tile-count-grey   { opacity: .5; }
.cc-tile-body   { padding: 6px 6px 10px; overflow-y: auto; flex: 1; }
.cc-tile-links  { padding: 8px 10px 4px; font-size: 12px; }
.cc-tile-links a { color: var(--info); margin-right: 4px; }
.cc-tile-add    { padding: 8px 10px; font-size: 12px; }
.cc-tile-add a  { color: var(--info); }

.cc-subhead { font-size: 11px; text-transform: uppercase; color: var(--text-light); padding: 10px 10px 4px; font-weight: 600; letter-spacing: .4px; display: flex; justify-content: space-between; align-items: center; }
.cc-subhead a { color: var(--info); text-transform: none; font-weight: normal; }

.cc-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; font-size: 13px; color: var(--text); text-decoration: none; }
.cc-row + .cc-row { border-top: 1px solid #f3f4f6; }
.cc-row-clickable { cursor: pointer; }
.cc-row-clickable:hover { background: #f8fafc; }
.cc-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.cc-row-time { min-width: 50px; text-align: center; font-weight: 600; color: var(--primary); font-size: 13px; flex-shrink: 0; }
.cc-row-time small { display: block; font-size: 10px; color: var(--text-light); font-weight: 400; }
.cc-row-date { min-width: 60px; text-align: center; flex-shrink: 0; }
.cc-row-date strong { display: block; font-size: 12px; color: var(--primary); }
.cc-row-date small { font-size: 10px; color: var(--text-light); }
.cc-row-main { flex: 1; min-width: 0; }
.cc-row-main > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-row-sub  { font-size: 11px; color: var(--text-light); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-row-tag  { font-size: 11px; color: var(--text-light); flex-shrink: 0; }
.cc-row-x    { background: none; border: none; color: #ccc; cursor: pointer; font-size: 12px; padding: 2px 4px; }
.cc-row-x:hover { color: var(--danger); }

.cc-prio-high { background: var(--danger); color: #fff; font-weight: 700; width: 18px; height: 18px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }

.cc-sha { background: #eef2f7; color: var(--primary); padding: 1px 5px; border-radius: 3px; font-size: 11px; font-family: 'SF Mono', Menlo, monospace; flex-shrink: 0; }
.cc-commit { text-decoration: none; }
.cc-commit-msg { font-size: 12px; color: var(--text); }
.cc-pr-num { background: #e3f2fd; color: #1565c0; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.cc-draft  { background: #f3f4f6; color: #6b7280; font-size: 10px; padding: 1px 5px; border-radius: 3px; font-weight: 600; text-transform: uppercase; }

.cc-empty { padding: 14px 10px; color: var(--text-light); font-size: 12px; text-align: center; font-style: italic; }
.cc-empty-soft { font-style: normal; opacity: .7; }
.cc-warn  { color: #b91c1c; font-style: normal; background: #fef2f2; border-radius: 4px; }

.cc-weather-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 8px; }
.cc-weather-day { text-align: center; padding: 8px 4px; background: #f8fafc; border-radius: 6px; }
.cc-weather-wd  { font-size: 11px; color: var(--text-light); font-weight: 600; }
.cc-weather-emoji { font-size: 22px; margin: 4px 0; }
.cc-weather-temp { font-size: 12px; }
.cc-weather-temp small { color: var(--text-light); }
.cc-weather-rain { font-size: 10px; color: var(--info); height: 14px; }

.cc-footer-meta { margin-top: 20px; padding: 12px; text-align: center; color: var(--text-light); font-size: 12px; }
.cc-footer-meta a { color: var(--info); }

@media (max-width: 1000px) {
  .cc-top-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .cc-quick-capture { flex-direction: column; }
  .cc-quick-capture select { max-width: none !important; }
  .cc-project-grid, .cc-ops-grid { grid-template-columns: 1fr; }
  .cc-weather-row { grid-template-columns: repeat(5, 1fr); }
  .cc-tile { max-height: none; }
}

/* ─── SMS Replies (chat-style) ──────────────────────────────────────────── */
.sms-pane { display: grid; grid-template-columns: 320px 1fr; gap: 16px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; height: calc(100vh - var(--topbar-h) - 64px); }
.sms-list { border-right: 1px solid var(--border); overflow-y: auto; background: #fafbfc; }
.sms-list-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 14px; background: #fff; position: sticky; top: 0; }
.sms-list-meta { color: var(--text-light); font-size: 12px; }
.sms-empty { padding: 30px 16px; text-align: center; color: var(--text-light); font-size: 13px; }
.sms-list-item { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid #eef1f4; transition: background .15s; }
.sms-list-item:hover { background: #f1f5f9; }
.sms-list-item.active { background: #e3f2fd; border-left: 3px solid var(--primary); padding-left: 11px; }
.sms-list-item.unread .sms-list-name { font-weight: 700; color: var(--text); }
.sms-list-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.sms-list-body { flex: 1; min-width: 0; }
.sms-list-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sms-list-row2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.sms-list-name { font-size: 14px; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sms-list-time { font-size: 11px; color: var(--text-light); flex-shrink: 0; }
.sms-list-preview { font-size: 12px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sms-list-you { color: #6b7280; font-style: italic; }
.sms-list-badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 600; flex-shrink: 0; }

.sms-thread { display: flex; flex-direction: column; min-width: 0; }
.sms-thread-empty { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--text-light); font-size: 13px; padding: 40px; text-align: center; }
.sms-thread-header { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fff; }
.sms-thread-back { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--primary); padding: 4px 8px; }
.sms-thread-name { font-weight: 600; font-size: 15px; }
.sms-thread-phone { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.sms-thread-phone a { color: var(--info); }

.sms-bubbles { flex: 1; overflow-y: auto; padding: 16px; background: #f5f7fa; display: flex; flex-direction: column; gap: 6px; }
.sms-day-divider { text-align: center; font-size: 11px; color: var(--text-light); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .5px; }
.sms-bubble-row { display: flex; }
.sms-bubble-in  { justify-content: flex-start; }
.sms-bubble-out { justify-content: flex-end; }
.sms-bubble { max-width: 70%; padding: 8px 12px; border-radius: 16px; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.sms-bubble-in  .sms-bubble { background: #fff; color: var(--text); border: 1px solid #e5e7eb; border-bottom-left-radius: 4px; }
.sms-bubble-out .sms-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.sms-bubble-time { font-size: 10px; opacity: .7; margin-top: 4px; }

@media (max-width: 768px) {
  .sms-pane { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - 28px); position: relative; }
  .sms-list, .sms-thread { grid-column: 1; grid-row: 1; }
  .sms-thread { display: none; }
  .sms-pane.show-thread .sms-list { display: none; }
  .sms-pane.show-thread .sms-thread { display: flex; }
  .sms-thread-back { display: inline-flex; }
  .sms-bubble { max-width: 85%; }
}

/* ─── Tab Navigation ──────────────────────────────────────────────────────── */
.tab-link { cursor: pointer; transition: all .15s; }
.tab-link:hover { opacity: .8; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar     { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-wrap   { margin-left: 0; }
  .hamburger   { display: block; }
  .stats-grid  { grid-template-columns: 1fr 1fr; }
  .grid-2      { grid-template-columns: 1fr; }
  .form-row    { grid-template-columns: 1fr; }
  .form-row-3  { grid-template-columns: 1fr; }
  .filters     { gap: 6px; }
  .filters input, .filters select { max-width: 100%; }
  .content     { padding: 12px; }

  /* Modal goes full-screen on phone for working room */
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal         { max-width: 100%; max-height: 100vh; height: 100vh; border-radius: 0; }
  .modal-lg, .modal-wide { max-width: 100% !important; }
  .modal-body    { padding: 16px; }
  .modal-header  { padding: 12px 16px; }
  .modal-header h3 { font-size: 16px; }

  /* Stack the inline grids on Bookings + Quote Builder modal */
  .bookings-cols     { grid-template-columns: 1fr !important; gap: 12px !important; }
  .qb-customer-grid  { grid-template-columns: 1fr !important; }
  .qb-fence-grid     { grid-template-columns: 1fr 1fr !important; gap: 6px !important; }
  .qb-extras-row     { grid-template-columns: 1fr !important; gap: 4px !important; padding: 8px 0; border-bottom: 1px solid #f0f0f0; }
  .qb-extras-row label { font-weight: 600; font-size: 13px !important; color: #1a5276 !important; }

  /* Nuclear option — any inline multi-column grid stacks on mobile.
     Matches inline styles like style="grid-template-columns:1fr 1fr 1fr" regardless
     of spacing. Catches every old inline grid I might have missed. */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  /* Re-allow 2-col fence rows after the nuclear rule */
  .qb-fence-grid { grid-template-columns: 1fr 1fr !important; }

  /* Job tiles stack on mobile */
  .job-tiles { grid-template-columns: 1fr !important; }

  /* Force layout to fit viewport */
  .app, .main-wrap, .content, .topbar { max-width: 100vw; }
  .main-wrap { margin-left: 0 !important; }
  .content { padding: 12px !important; }
  body, .content, .card { overflow-x: hidden; }
  /* Re-enable horizontal scroll only inside table wrappers and the calendar */
  .table-wrap, .scroll-x, .cal-grid, table { overflow-x: auto; }

  /* Tables — wrap-and-scroll horizontally */
  .table-wrap, .scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 13px; min-width: 600px; }
  .topbar { padding: 8px 12px; gap: 6px; }
  .page-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right .btn { padding: 6px 10px; font-size: 12px; }

  /* Calendar widget — give it horizontal scroll so cells stay readable */
  .cal-grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Stop iOS Safari from auto-zooming when a small input gets focus */
  input, select, textarea { font-size: 16px !important; }

  /* Tighter card paddings */
  .card { padding: 14px; }
}
@media (max-width: 480px) {
  .stats-grid  { grid-template-columns: 1fr; }
  .qb-fence-grid { grid-template-columns: 1fr !important; }
}

/* Respect device safe areas (notches / home indicators) when installed as PWA */
@supports (padding: max(0px)) {
  .topbar  { padding-top: max(8px, env(safe-area-inset-top)); }
  .content { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .sidebar { padding-top: max(0px, env(safe-area-inset-top)); }
}

/* ─── Visual Sales Pipeline (Kanban) ──────────────────────────────────────── */
.pl-toolbar { display:flex; justify-content:space-between; align-items:center; gap:10px 16px; flex-wrap:wrap; margin-bottom:14px; }
.pl-hint { font-size:12px; color:#9ca3af; flex:1 1 220px; min-width:0; }
.pl-toolbar > span:last-child { flex-wrap:wrap; }
.pl-board { display:flex; gap:12px; overflow-x:auto; padding-bottom:14px; align-items:flex-start; }
.pl-col { flex:0 0 264px; width:264px; background:#f5f6f8; border-radius:12px; display:flex; flex-direction:column; max-height:calc(100vh - 190px); }
.pl-col.pl-over { outline:2px dashed #2563eb; outline-offset:-2px; background:#eef4ff; }
.pl-col-head { display:flex; justify-content:space-between; align-items:center; padding:10px 12px; font-weight:700; font-size:13px; color:#374151; border-top-left-radius:12px; border-top-right-radius:12px; background:#fff; }
.pl-count { font-size:12px; background:#e5e7eb; color:#374151; border-radius:20px; padding:1px 9px; font-weight:700; }
.pl-col-body { padding:10px; overflow-y:auto; display:flex; flex-direction:column; gap:9px; min-height:60px; }
.pl-empty { text-align:center; color:#c4c8cf; font-size:12px; padding:18px 0; }
.pl-card { background:#fff; border:1px solid #e5e7eb; border-radius:10px; padding:11px 12px; box-shadow:0 1px 2px rgba(0,0,0,0.05); cursor:pointer; transition:box-shadow .12s, transform .04s; }
.pl-card:hover { box-shadow:0 3px 10px rgba(0,0,0,0.10); }
.pl-card:active { transform:scale(0.99); }
.pl-card.pl-dragging { opacity:0.5; }
.pl-card-name { font-weight:700; font-size:14px; color:#111827; }
.pl-card-sub { font-size:12px; color:#6b7280; margin-top:2px; }
.pl-card-phone { font-size:12px; color:#9ca3af; margin-top:1px; }
.pl-card-ctx { font-size:12px; color:#374151; margin-top:5px; font-weight:600; }
.pl-chips { display:flex; gap:5px; flex-wrap:wrap; margin-top:7px; }
.pl-chip { font-size:11px; padding:1px 7px; border-radius:20px; background:#eef2f6; color:#475569; font-weight:600; }
.pl-chip-quote { background:#ecfeff; color:#0e7490; }
.pl-chip-sent { background:#dcfce7; color:#15803d; }
.pl-chip-unsent { background:#fef3c7; color:#b45309; }
.pl-chip-manual { background:#fef9c3; color:#a16207; }
.pl-card-actions { display:flex; gap:6px; flex-wrap:wrap; margin-top:9px; }
.pl-btn { font-size:11px; padding:4px 9px; border-radius:6px; border:1px solid #d1d5db; background:#fff; color:#374151; cursor:pointer; font-weight:600; }
.pl-btn:hover { background:#f3f4f6; }
.pl-btn-amber { background:#f59e0b; color:#fff; border-color:#f59e0b; }
.pl-btn-green { background:#10b981; color:#fff; border-color:#10b981; }
.pl-btn-blue  { background:#2563eb; color:#fff; border-color:#2563eb; }
.pl-btn-purple{ background:#a855f7; color:#fff; border-color:#a855f7; }
.pl-btn-red   { background:#fff; color:#dc2626; border-color:#fca5a5; }
.pl-btn-red:hover { background:#fef2f2; }
.pl-card-orphan { border-style:dashed; background:#fafafa; cursor:default; }
.pl-south { margin-top:18px; background:#f5f6f8; border-radius:12px; padding:14px 16px; }
.pl-south-head { font-weight:700; font-size:14px; color:#374151; display:flex; align-items:center; gap:8px; margin-bottom:12px; flex-wrap:wrap; }
.pl-south-body { display:flex; gap:10px; flex-wrap:wrap; }
.pl-card-south { width:220px; flex:0 0 220px; border-left:3px solid #d97706; }
@media (max-width:768px){ .pl-card-south { width:100%; flex-basis:100%; } }
.pl-modal-row { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
.pl-pill { display:inline-flex; align-items:center; font-size:12px; padding:3px 10px; border-radius:20px; background:#f3f4f6; border:1px solid #e5e7eb; color:#374151; text-decoration:none; }
.modal.modal-lg { max-width:620px; }

@media (max-width:768px) {
  .pl-col { flex-basis:80vw; width:80vw; max-height:none; }
  .pl-board { -webkit-overflow-scrolling:touch; }
}
