:root {
  --navy: #0b3c5d;
  --blue: #1d6fa5;
  --sky: #2fa4d6;
  --accent: #16a34a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
a { cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--sky));
}
.login-card {
  background: #fff; padding: 40px; border-radius: 14px; width: 340px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); text-align: center;
}
.login-img { width: 200px; margin-bottom: 10px; }
.side-logo { display: block; width: calc(100% - 28px); margin: 0 14px 14px; padding: 10px; background: #fff; border-radius: 10px; }
.side-user { margin: 0 14px 14px; padding: 8px 12px; background: rgba(47,164,214,.18); border-radius: 8px; color: #fff; font-weight: 700; font-size: 14px; }
.login-logo { font-size: 26px; font-weight: 800; color: var(--navy); line-height: 1.05; }
.login-logo span { display: block; font-size: 15px; font-weight: 600; color: var(--sky); letter-spacing: .5px; }
.login-sub { color: var(--muted); margin: 6px 0 24px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 8px; background: var(--blue);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: var(--navy); }
.login-err { color: var(--danger); margin-top: 12px; min-height: 18px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column;
  padding: 20px 0; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 20px; font-weight: 800; color: #fff; padding: 0 22px 20px; line-height: 1.1; }
.brand span { display: block; font-size: 12px; font-weight: 600; color: var(--sky); letter-spacing: .5px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  padding: 11px 22px; color: #cbd5e1; text-decoration: none; font-weight: 500; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: rgba(47,164,214,.18); color: #fff; border-left-color: var(--sky); }
.logout { margin: 12px 22px 0; padding: 9px; background: transparent; border: 1px solid rgba(255,255,255,.2);
  color: #cbd5e1; border-radius: 7px; cursor: pointer; }
.logout:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { flex: 1; padding: 28px 34px; max-width: 1200px; }

/* ---------- Common ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; margin: 0; }
.btn {
  background: var(--blue); color: #fff; border: 0; padding: 9px 16px; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--navy); }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 28px; font-weight: 800; color: var(--navy); margin-top: 6px; }
.stat .value.green { color: var(--accent); }
.stat .value.red { color: var(--danger); }

table { width: 100%; border-collapse: collapse; background: #fff; }
.table-card { overflow: hidden; }
th { text-align: left; padding: 12px 16px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); border-bottom: 1px solid var(--line); background: #f8fafc; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #f8fafc; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #e2e8f0; color: #475569; }
.badge.sent { background: #dbeafe; color: #1d4ed8; }
.badge.accepted { background: #dcfce7; color: #15803d; }
.badge.declined { background: #fee2e2; color: #b91c1c; }
.status-select { padding: 5px 10px; border-radius: 8px; border: 0; font-weight: 700; cursor: pointer; text-transform: capitalize; font-size: 13px; }
.badge.scheduled { background: #dbeafe; color: #1d4ed8; }
.badge.in-progress { background: #fef9c3; color: #a16207; }
.badge.done { background: #dcfce7; color: #15803d; }
.badge.unpaid { background: #fee2e2; color: #b91c1c; }
.badge.paid { background: #dcfce7; color: #15803d; }

.empty { text-align: center; padding: 50px; color: var(--muted); }
.link { color: var(--blue); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---------- Forms / modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; font-family: inherit;
}
.field textarea { min-height: 70px; resize: vertical; }
#f_address { min-height: 46px; }

/* Address autocomplete dropdown */
.ac-dd {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 60;
  background: #fff; border: 1px solid var(--line); border-radius: 0 0 8px 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.14); max-height: 240px; overflow-y: auto; margin-top: -1px;
}
.ac-item { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.active { background: #eff6ff; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* Line items editor */
.li-table { width: 100%; margin-top: 6px; }
.li-table th, .li-table td { padding: 6px; font-size: 13px; border: 0; background: none; }
.li-table input, .li-table select { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; }
.li-total { text-align: right; font-weight: 600; }
.totals { text-align: right; margin-top: 14px; font-size: 15px; }
.totals .grand { font-size: 22px; font-weight: 800; color: var(--navy); }

/* Quote detail line items (responsive, no horizontal scroll) */
.qline { display: flex; justify-content: space-between; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.qline:last-of-type { border-bottom: 0; }
.qline-info { min-width: 0; }
.qline-name { font-weight: 700; color: #0f172a; }
.qline-desc { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: pre-line; line-height: 1.45; }
.qline-right { text-align: right; white-space: nowrap; flex-shrink: 0; }
.qline-calc { color: var(--muted); font-size: 12px; }
.qline-amt { font-weight: 700; color: #0f172a; margin-top: 2px; }
.qline.opt .qline-name, .qline.opt .qline-amt { color: var(--muted); }
.qtotals { padding: 12px 16px; border-top: 1px solid var(--line); }
.qtotals .row { display: flex; justify-content: space-between; padding: 3px 0; }
.qtotals .grand { font-weight: 800; font-size: 18px; color: var(--navy); }

/* Job detail: photos, checklist, time/expense, costing */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo-cell { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #f1f5f9; }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }
.photo-label { position: absolute; top: 5px; left: 5px; background: rgba(11,60,93,.85); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; text-transform: uppercase; letter-spacing: .3px; }
.photo-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(220,38,38,.9); color: #fff; font-size: 15px; line-height: 1; cursor: pointer; }
.check-item { display: flex; align-items: center; gap: 9px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.check-item:last-child { border-bottom: 0; }
.check-item span { flex: 1; }
.check-item.done span { text-decoration: line-through; color: var(--muted); }
.check-item input { width: 17px; height: 17px; cursor: pointer; }
.check-del { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.te-head { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .4px; margin-bottom: 6px; }
.te-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.te-row:last-child { border-bottom: 0; }
.te-del { border: 0; background: none; color: var(--danger); font-size: 15px; cursor: pointer; margin-left: 4px; }
.te-add { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.te-add input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.cost-row { display: flex; justify-content: space-between; padding: 3px 0; }

/* Dashboard reminders */
.rem-item { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.rem-item:last-child { border-bottom: 0; }
.rem-item:hover { background: #f8fafc; }
.rem-text { flex: 1; }
.rem-go { color: var(--muted); font-size: 18px; }
.rem-item.rem-red { border-left: 3px solid var(--danger); }
.rem-item.rem-amber { border-left: 3px solid #d97706; }
.rem-item.rem-blue { border-left: 3px solid var(--sky); }

/* Schedule */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-head { font-weight: 700; color: var(--muted); text-align: center; font-size: 12px; text-transform: uppercase; padding-bottom: 4px; }
.cal-cell { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 96px; padding: 6px; }
.cal-cell.dim { background: #f8fafc; }
.cal-cell.today { border-color: var(--sky); box-shadow: 0 0 0 1px var(--sky); }
.cal-date { font-size: 12px; color: var(--muted); font-weight: 600; }
.cal-job { background: var(--blue); color: #fff; font-size: 11px; padding: 3px 6px; border-radius: 5px; margin-top: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-job.done { background: var(--accent); }
.cal-nav { display: flex; align-items: center; gap: 12px; }

@media print {
  .sidebar, .page-head .btn, .modal-foot, .modal-close { display: none !important; }
}

/* ---------- Mobile / phone ---------- */
@media (max-width: 820px) {
  html, body { overflow-x: hidden; }
  .app { flex-direction: column; }
  .main { min-width: 0; }   /* let the flex column shrink so wide tables scroll, not stretch the page */
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 40;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px;
  }
  .side-logo { width: 120px; margin: 0 6px 0 2px; padding: 5px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; flex: 1; gap: 4px; }
  .sidebar nav a { padding: 8px 10px; font-size: 13px; border-left: 0; border-radius: 6px; }
  .sidebar nav a.active { border-left: 0; background: rgba(47,164,214,.28); }
  .logout { margin: 0 2px; padding: 8px 12px; }

  .main { padding: 16px 14px; max-width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 22px; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head h1 { font-size: 20px; }
  .row-actions { flex-wrap: wrap; }

  /* wide tables scroll sideways instead of squishing */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-card table { min-width: 560px; }

  /* modals go full-width and edge-to-edge */
  .modal-backdrop { padding: 10px; }
  .modal { max-width: 100%; }
  .field-row { flex-direction: column; gap: 0; }
  .li-table { min-width: 500px; }
  .modal-body { overflow-x: auto; }

  /* quote detail: stack the two columns (minmax(0,..) lets content shrink instead of overflowing) */
  .detail-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .detail-client { grid-template-columns: minmax(0, 1fr) !important; }

  .cal-cell { min-height: 64px; }
  .cal-job { font-size: 10px; }
}
