/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #1e50a0;
  --blue-light: #e8effe;
  --blue-mid:   #3b6cc7;
  --red:        #c0392b;
  --red-light:  #fdecea;
  --orange:     #d35400;
  --orange-light: #fef0e6;
  --green:      #1a7a4a;
  --purple:     #6b21a8;
  --purple-light:#f3e8ff;
  --teal:       #0f766e;
  --teal-light: #ccfbf1;
  --green-light:#e5f6ee;
  --yellow:     #b7791f;
  --yellow-light:#fef9e7;
  --grey-50:    #f8f9fb;
  --grey-100:   #eef0f4;
  --grey-200:   #dde1e8;
  --grey-400:   #9aa3b0;
  --grey-700:   #4a5568;
  --grey-900:   #1a202c;
  --radius:     8px;
  --shadow:     0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }
body { font-family: var(--font); color: var(--grey-900); background: var(--grey-50); font-size: 14px; line-height: 1.5; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Screens ────────────────────────────────────────────────────────────── */
.screen { height: 100%; }
.hidden { display: none !important; }

/* ── Loading ────────────────────────────────────────────────────────────── */
#screen-loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; background: linear-gradient(135deg, #1e3a6e 0%, #2d6cbf 100%);
}
#screen-loading .auth-logo { color: #fff; }
.loading-center {
  display: flex; flex-direction: column; align-items: center; gap: 24px;
}
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 6px;
}

/* ── Auth ───────────────────────────────────────────────────────────────── */
#screen-auth {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; background: linear-gradient(135deg, #1e3a6e 0%, #2d6cbf 100%);
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 40px 44px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-size: 20px; font-weight: 700; color: var(--blue); }
.auth-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { color: var(--grey-400); margin-bottom: 28px; font-size: 13px; }
.auth-error { color: var(--red); font-size: 13px; background: var(--red-light); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.auth-success { color: var(--green); font-size: 13px; background: var(--green-light); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.auth-forgot { text-align: right; margin: -6px 0 14px; font-size: 13px; }
.auth-forgot a { color: var(--blue); font-weight: 600; }
.auth-toggle { margin-top: 20px; text-align: center; color: var(--grey-400); font-size: 13px; }
.auth-toggle a { color: var(--blue); font-weight: 600; }
.auth-privacy { margin-top: 14px; text-align: center; font-size: 12px; color: var(--grey-400); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { font-size: 13px; font-weight: 600; color: var(--grey-700); }
.optional { font-weight: 400; color: var(--grey-400); }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
select, textarea {
  border: 1.5px solid var(--grey-200); border-radius: var(--radius);
  padding: 9px 12px; font-size: 14px; font-family: var(--font);
  background: #fff; color: var(--grey-900); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(59,108,199,.12);
}
textarea { resize: vertical; min-height: 72px; }
.input-readonly { background: var(--grey-50); color: var(--grey-400); cursor: default; }

.specialty-checkboxes { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; font-size: 13px; }
.checkbox-label input { width: auto; accent-color: var(--blue); }
.radio-group { display: flex; gap: 20px; }
.radio-label { display: flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; font-size: 13px; }
.radio-label input { width: auto; accent-color: var(--blue); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); font-size: 14px;
  font-weight: 600; font-family: var(--font); cursor: pointer;
  border: 1.5px solid transparent; transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { background: var(--blue-mid); border-color: var(--blue-mid); }
.btn-outline { background: #fff; color: var(--blue); border-color: var(--grey-200); }
.btn-outline:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-light); }
.btn-ghost { background: transparent; color: var(--grey-400); border-color: transparent; }
.btn-ghost:hover { color: var(--grey-700); background: var(--grey-100); }
.btn-full { width: 100%; justify-content: center; padding: 10px 16px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Manager sidebar layout ─────────────────────────────────────────────── */
#screen-manager { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 220px; min-width: 220px; background: #fff; border-right: 1px solid var(--grey-100);
  display: flex; flex-direction: column; padding: 20px 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px; padding: 0 18px 20px;
  font-size: 15px; font-weight: 700; color: var(--blue);
  border-bottom: 1px solid var(--grey-100); margin-bottom: 12px;
}
.nav-links { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-link {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border-radius: var(--radius); color: var(--grey-700); font-size: 14px; font-weight: 500;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--grey-50); color: var(--blue); text-decoration: none; }
.nav-link.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }
.sidebar-footer { padding: 16px 18px 4px; border-top: 1px solid var(--grey-100); display: flex; flex-direction: column; gap: 8px; }
.user-email { font-size: 12px; color: var(--grey-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.main-content { flex: 1; overflow-y: auto; padding: 32px 36px; }

/* ── View header ────────────────────────────────────────────────────────── */
.view-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.view-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 2px; }
.view-sub { color: var(--grey-400); font-size: 13px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Stats row ──────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
}
.stat-card-red { border-left: 3px solid var(--red); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--blue); line-height: 1; margin-bottom: 4px; }
.stat-card-red .stat-value { color: var(--red); }
.stat-label { font-size: 12px; color: var(--grey-400); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* ── Filter row ─────────────────────────────────────────────────────────── */
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-btn {
  padding: 5px 14px; border-radius: 20px; border: 1.5px solid var(--grey-200);
  background: #fff; font-size: 13px; font-weight: 500; cursor: pointer;
  color: var(--grey-700); transition: all .12s; font-family: var(--font);
}
.filter-btn:hover { border-color: var(--blue); color: var(--blue); }
.filter-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.filter-btn-red.active { background: var(--red); border-color: var(--red); }
.filter-btn-red:hover { border-color: var(--red); color: var(--red); }

/* ── Filter search bar ──────────────────────────────────────────────────── */
.filter-search-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.filter-search-input {
  flex: 1; min-width: 0; padding: 6px 12px; border: 1.5px solid var(--grey-200);
  border-radius: var(--radius); font-size: 13px; font-family: var(--font);
  color: var(--grey-700); background: #fff;
}
.filter-search-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.08); }
.filter-select {
  padding: 6px 10px; border: 1.5px solid var(--grey-200); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); color: var(--grey-700); background: #fff; cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--blue); }

/* ── Card list ──────────────────────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.empty-state { text-align: center; color: var(--grey-400); padding: 48px 0; font-size: 14px; }

.bulk-invoice-bar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  padding: 10px 16px; background: var(--blue-light); border: 1.5px solid var(--blue-mid);
  border-radius: var(--radius); font-size: 13px; font-weight: 500; color: var(--blue);
}
.bulk-invoice-bar span { flex: 1; }

.job-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 14px 18px; display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: box-shadow .12s, border-color .12s; box-shadow: var(--shadow);
}
.job-card:hover { border-color: var(--blue-mid); box-shadow: 0 4px 16px rgba(30,80,160,.1); }
.job-card.flagged { border-left: 3px solid var(--red); }
.job-card.selected { background: var(--blue-light); border-color: var(--blue-mid); }

.job-card-checkbox { display: flex; align-items: center; flex-shrink: 0; cursor: default; }
.job-card-checkbox input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--blue); cursor: pointer; }

.job-priority-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.priority-low    { background: var(--grey-400); }
.priority-normal { background: var(--blue); }
.priority-high   { background: var(--orange); }
.priority-urgent { background: var(--red); }

.job-card-main { flex: 1; min-width: 0; }
.job-card-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card-sub { font-size: 12px; color: var(--grey-400); margin-top: 2px; }
.job-card-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.job-flag-icon { color: var(--red); font-size: 14px; }

.tradesman-card, .property-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 14px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.tradesman-card-clickable, .property-card-clickable, .team-card-clickable { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.tradesman-card-clickable:hover, .property-card-clickable:hover, .team-card-clickable:hover { border-color: var(--blue); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.tradesman-card-main, .property-card-main { flex: 1; min-width: 0; }
.tradesman-card-name, .property-card-name { font-weight: 600; font-size: 14px; }
.tradesman-card-sub, .property-card-sub { font-size: 12px; color: var(--grey-400); margin-top: 2px; }

.report-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 14px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.report-card-clickable { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.report-card-clickable:hover { border-color: var(--blue); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.report-card-main { flex: 1; min-width: 0; }
.report-card-title { font-weight: 600; font-size: 14px; }
.report-card-sub { font-size: 12px; color: var(--grey-400); margin-top: 2px; }
.report-card-error { font-size: 12px; color: var(--red); margin-top: 4px; }
.report-card-right { flex-shrink: 0; }

.draft-job-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 14px 16px; display: flex; gap: 12px; box-shadow: var(--shadow);
}
.draft-job-checkbox { display: flex; align-items: flex-start; padding-top: 4px; flex-shrink: 0; }
.draft-job-checkbox input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
.draft-job-checkbox input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .5; }
.draft-job-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.draft-job-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.draft-job-row .draft-title { flex: 1; min-width: 160px; font-weight: 600; }
.draft-job-row .draft-specialty, .draft-job-row .draft-priority, .draft-job-row .draft-property { flex: 1; min-width: 140px; }
.draft-desc { width: 100%; min-height: 56px; }
.draft-apt-section { display: flex; }
.draft-apt-section input { max-width: 220px; }
.draft-creation-error { font-size: 12px; color: var(--red); margin-top: 2px; }

.review-modal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

/* ── Status badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge-red    { background: var(--red-light);    color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-blue   { background: var(--blue-light);   color: var(--blue); }
.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-grey   { background: var(--grey-100);     color: var(--grey-700); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-teal   { background: var(--teal-light);   color: var(--teal); }

.badge-count { background: var(--red); color: #fff; border-radius: 10px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
.nav-link .badge { margin-left: auto; }

/* Deadline badges */
.badge-deadline-ok       { background: var(--green-light);  color: var(--green); }
.badge-deadline-warning  { background: var(--orange-light); color: var(--orange); }
.badge-deadline-critical { background: var(--red-light);    color: var(--red); font-weight: 700; }
.badge-deadline-overdue  { background: var(--red);          color: #fff;       font-weight: 700; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-wide { max-width: 840px; }
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 0; gap: 12px;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 16px; cursor: pointer;
  color: var(--grey-400); padding: 2px 6px; line-height: 1;
  border-radius: 4px; flex-shrink: 0;
}
.modal-close:hover { background: var(--grey-100); color: var(--grey-700); }
.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--grey-100); }

/* ── Job detail ─────────────────────────────────────────────────────────── */
.detail-body { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.detail-section { margin-bottom: 18px; }
.detail-section h4, .detail-right h4 { font-size: 12px; font-weight: 700; color: var(--grey-400); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.detail-section p { font-size: 14px; color: var(--grey-700); line-height: 1.6; }
.detail-info-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.detail-info-grid dt { color: var(--grey-400); font-weight: 600; }
.detail-info-grid dd { color: var(--grey-700); }
.detail-hint { color: var(--grey-400); font-size: 11px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.flag-box {
  display: flex; align-items: flex-start; gap: 8px; background: var(--red-light);
  color: var(--red); border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; font-weight: 500; margin-bottom: 14px;
}

/* ── Updates timeline ───────────────────────────────────────────────────── */
.updates-timeline { display: flex; flex-direction: column; gap: 10px; max-height: 380px; overflow-y: auto; padding-right: 4px; }
.update-entry {
  background: var(--grey-50); border-radius: var(--radius); padding: 10px 14px;
  border-left: 3px solid var(--grey-200);
}
.update-entry.source-agent      { border-left-color: var(--blue); }
.update-entry.source-tradesman  { border-left-color: var(--green); }
.update-entry.source-manager    { border-left-color: var(--orange); }
.update-entry.source-system     { border-left-color: var(--grey-400); }
.update-source { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--grey-400); margin-bottom: 3px; }
.update-content { font-size: 13px; color: var(--grey-700); }
.update-time { font-size: 11px; color: var(--grey-400); margin-top: 4px; }

/* ── Phone input ────────────────────────────────────────────────────────── */
.phone-input-row { display: flex; gap: 8px; }
.country-code-select { flex: 0 0 auto; width: auto; min-width: 110px; }
.phone-input-row input { flex: 1; }

/* ── Eircode lookup ─────────────────────────────────────────────────────── */
.eircode-input-row { display: flex; gap: 8px; }
.eircode-input { flex: 1; text-transform: uppercase; letter-spacing: .04em; }
.eircode-result {
  margin-top: 8px; padding: 10px 12px; background: var(--green-light);
  border: 1px solid var(--green); border-radius: var(--radius);
  display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap;
}
.eircode-result-text { flex: 1; font-size: 13px; color: var(--green); font-weight: 500; line-height: 1.4; }
.eircode-error {
  margin-top: 6px; font-size: 12px; color: var(--red);
  background: var(--red-light); border-radius: 6px; padding: 6px 10px;
}
.field-hint      { margin-top: 4px; font-size: 12px; color: var(--grey-500); }
.field-hint-link { display: inline-block; margin-top: 6px; font-size: 12px; color: var(--blue); }

/* ── Lobby ──────────────────────────────────────────────────────────────── */
#screen-lobby {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--bg);
}
.lobby-main {
  flex: 1; overflow-y: auto; padding: 40px 28px;
}
.lobby-body {
  max-width: 520px;
}

/* ── Invite cards (lobby + admin) ───────────────────────────────────────── */
.invite-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--grey-50); border: 1px solid var(--grey-200); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.invite-card-main { flex: 1; min-width: 0; }
.invite-agency-name { font-weight: 600; font-size: 14px; }
.invite-meta { font-size: 12px; color: var(--grey-400); margin-top: 2px; }
.invite-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Admin view ─────────────────────────────────────────────────────────── */
.admin-section { margin-bottom: 36px; }
.admin-section-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.admin-section-danger { padding-top: 28px; border-top: 1.5px solid var(--red-light); }

/* ── User settings modal ────────────────────────────────────────────────── */
.settings-section { margin-bottom: 32px; padding-bottom: 28px; border-bottom: 1px solid var(--grey-100); }
.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--grey-400); margin-bottom: 14px; }
.settings-section-danger { padding-top: 4px; border-top: 1.5px solid var(--red-light); border-bottom: none; }
.settings-success { font-size: 13px; color: var(--green); background: var(--green-light); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.watcher-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 160px; overflow-y: auto; }
.watcher-item { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; border: 1px solid var(--grey-100); border-radius: var(--radius); font-size: 14px; cursor: pointer; }
.watcher-item input { width: 18px; height: 18px; }
.watcher-empty { font-size: 13px; color: var(--grey-400); padding: 6px 0; }
.btn-icon { width: 34px; height: 34px; padding: 0; justify-content: center; }
.admin-search-row { display: flex; gap: 8px; margin-bottom: 4px; }
.admin-search-input { flex: 1; }

.team-card {
  background: #fff; border: 1px solid var(--grey-100); border-radius: var(--radius);
  padding: 12px 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.team-card-info { flex: 1; min-width: 0; }
.team-card-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.team-card-email { font-size: 12px; color: var(--grey-400); margin-top: 2px; }
.team-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Billing section ────────────────────────────────────────────────────── */
.billing-status-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.billing-plan-name { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.billing-actions { display: flex; gap: 8px; flex-shrink: 0; }
.billing-plan-chooser { display: flex; gap: 16px; }
.billing-plan-card {
  flex: 1; background: #fff; border: 1.5px solid var(--grey-100);
  border-radius: var(--radius-lg, var(--radius)); padding: 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.billing-plan-card-current { border-color: var(--blue); background: #eff6ff; }
.billing-plan-card-header { display: flex; align-items: center; gap: 8px; }
.billing-plan-card-name { font-size: 15px; font-weight: 700; }

/* ── AI Chat view ───────────────────────────────────────────────────────── */
.chat-view { display: flex; flex-direction: column; height: 100%; padding: 0; overflow: hidden; }
.chat-view .view-header { padding: 32px 36px 16px; flex-shrink: 0; margin-bottom: 0; }

.upgrade-prompt {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 48px 24px; text-align: center; color: var(--grey-600);
}
.upgrade-prompt svg { color: var(--grey-300); }
.upgrade-prompt h2 { font-size: 18px; font-weight: 700; color: var(--grey-800); margin: 0; }
.upgrade-prompt p { font-size: 14px; margin: 0 0 8px; max-width: 360px; }

.chat-shell {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 0 36px 24px;
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 8px 0 16px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}

.chat-welcome {
  max-width: 480px; margin: 24px auto 0;
  background: #fff; border: 1px solid var(--grey-100);
  border-radius: 12px; padding: 24px 28px; text-align: center;
  box-shadow: var(--shadow);
}
.chat-welcome-icon {
  width: 52px; height: 52px; border-radius: 50%; background: var(--blue-light);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px; color: var(--blue);
}
.chat-welcome p { color: var(--grey-700); font-size: 14px; margin-bottom: 12px; }
.chat-welcome ul {
  text-align: left; list-style: none; display: flex; flex-direction: column; gap: 6px;
}
.chat-welcome li {
  font-size: 13px; color: var(--grey-400);
  padding: 5px 10px; background: var(--grey-50); border-radius: var(--radius);
}

.chat-bubble-wrap { display: flex; }
.chat-bubble-user { justify-content: flex-end; }
.chat-bubble-ai   { justify-content: flex-start; }

.chat-bubble {
  max-width: 72%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.55; word-wrap: break-word;
}
.chat-bubble code {
  background: rgba(0,0,0,.08); border-radius: 4px;
  padding: 1px 4px; font-size: 12.5px;
}
.chat-bubble-user .chat-bubble {
  background: var(--blue); color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble-ai .chat-bubble {
  background: #fff; color: var(--grey-900);
  border: 1px solid var(--grey-100); border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.chat-thinking {
  display: flex; align-items: center; gap: 5px; padding: 14px 16px;
}
.chat-thinking span {
  display: block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--grey-400);
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-thinking span:nth-child(2) { animation-delay: .2s; }
.chat-thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px; background: #fff;
  border: 1.5px solid var(--grey-200); border-radius: 12px;
  box-shadow: var(--shadow); flex-shrink: 0;
}
.chat-input {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 14px; font-family: var(--font); color: var(--grey-900);
  background: transparent; line-height: 1.5; max-height: 160px;
  padding: 0;
}
.chat-input::placeholder { color: var(--grey-400); }
.chat-send-btn {
  flex-shrink: 0; width: 38px; height: 38px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}

/* ── Chat inline cards ──────────────────────────────────────────────────── */
.chat-bubble-cards {
  max-width: min(640px, 92%) !important;
  padding: 10px 12px;
}

.chat-text { line-height: 1.55; }
.chat-text + .chat-cards-grid,
.chat-cards-grid + .chat-text { margin-top: 8px; }

.chat-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 6px 0;
}

.chat-cards-empty {
  font-size: 13px; color: var(--grey-400);
  padding: 6px 0;
}

.chat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--grey-50);
  border: 1px solid var(--grey-100);
  border-radius: var(--radius);
  padding: 9px 11px;
  transition: background .12s, border-color .12s;
}

.chat-card:hover {
  background: var(--blue-light);
  border-color: #c5d4f0;
}

.chat-card-body {
  flex: 1;
  min-width: 0;
}

.chat-card-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--grey-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-card-sub {
  font-size: 12px;
  color: var(--grey-400);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.chat-card-detail {
  font-size: 11px;
  color: var(--grey-400);
  background: var(--grey-100);
  border-radius: 4px;
  padding: 1px 5px;
}

.chat-card-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-card-btn {
  flex-shrink: 0;
  font-size: 11px !important;
  padding: 3px 9px !important;
  height: auto !important;
}

.chat-code-fallback {
  font-size: 11px; color: var(--grey-400);
  background: var(--grey-50); border-radius: var(--radius);
  padding: 8px; overflow-x: auto; white-space: pre-wrap;
}

/* ── Mobile navigation ──────────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--grey-100);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 50;
}
.mobile-topbar-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--blue);
}
.mobile-topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-user-email {
  font-size: 12px; color: var(--grey-400);
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.mobile-bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 64px;
  background: #fff;
  border-top: 1px solid var(--grey-100);
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  z-index: 100;
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--grey-400); font-size: 10px;
  font-family: var(--font); font-weight: 500;
  padding: 6px 4px; transition: color .12s;
  position: relative; text-decoration: none;
}
.mobile-nav-item:hover { color: var(--blue); text-decoration: none; }
.mobile-nav-item.active { color: var(--blue); }
.mobile-nav-badge {
  position: absolute; top: 5px; right: calc(50% - 20px);
  background: var(--red); color: #fff;
  border-radius: 8px; padding: 1px 5px;
  font-size: 10px; font-weight: 700;
  min-width: 16px; text-align: center; line-height: 1.4;
}

/* ── Responsive: mobile (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

  /* Show mobile nav, hide desktop sidebar */
  .mobile-topbar  { display: flex; }
  .mobile-bottom-nav { display: flex; }
  #screen-manager { flex-direction: column; }
  .sidebar { display: none; }

  /* Main content */
  .main-content { padding: 16px 16px 88px; }

  /* View header */
  .view-header { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
  .view-header h1 { font-size: 20px; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .header-actions .btn { flex: 1; min-width: 0; justify-content: center; font-size: 13px; }

  /* Stats grid – 2 columns */
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 22px; }

  /* Filter row – horizontal scroll */
  .filter-row {
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px; margin-bottom: 12px;
  }
  .filter-row::-webkit-scrollbar { display: none; }
  .filter-btn { flex-shrink: 0; }
  .filter-row-wrap { flex-wrap: wrap; overflow-x: visible; }
  .filter-row-wrap .filter-select { margin-left: 0 !important; width: 100%; margin-top: 6px; }
  .filter-search-bar { flex-wrap: wrap; margin-bottom: 10px; }
  .filter-search-bar .filter-select { width: 100%; }
  .filter-search-input { min-height: 44px; padding: 10px 14px; }
  .filter-btn { padding: 8px 16px; min-height: 36px; }
  .filter-select { min-height: 44px; padding: 10px 12px; }

  /* Bulk invoice bar */
  .bulk-invoice-bar { flex-wrap: wrap; gap: 8px; }
  .bulk-invoice-bar span { width: 100%; }

  /* Job cards */
  .job-card { padding: 12px 14px; gap: 10px; }
  .job-card-right { flex-wrap: wrap; gap: 6px; }

  /* Form field rows – single column */
  .field-row { grid-template-columns: 1fr; gap: 0; }

  /* Prevent iOS auto-zoom on input focus (triggers when font-size < 16px) */
  input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
  select, textarea { font-size: 16px; }

  /* Auth screen */
  .auth-card { padding: 28px 20px; margin: 20px 16px; }

  /* Modals – bottom sheet */
  .modal-overlay { padding: max(env(safe-area-inset-top), 52px) 0 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; max-height: 92dvh; max-width: 100%; }
  .modal-wide { max-width: 100%; }
  .modal-header { padding: 16px 16px 0; }
  .modal-body { padding: 16px; }

  /* Job detail – single column */
  .detail-body { grid-template-columns: 1fr; gap: 0; }
  .detail-right { border-top: 1px solid var(--grey-100); padding-top: 16px; margin-top: 4px; }
  .updates-timeline { max-height: 260px; }
  .detail-actions { flex-wrap: wrap; }
  .detail-actions .btn { flex: 1; min-width: 130px; }

  /* Phone input */
  .phone-input-row { flex-wrap: wrap; gap: 6px; }
  .country-code-select { width: 100%; min-width: 0; }

  /* Eircode row */
  .eircode-input-row { flex-direction: column; }
  .eircode-input-row .btn { width: 100%; justify-content: center; }

  /* AI Chat view */
  .chat-view .view-header { padding: 0 0 8px; }
  .chat-shell { padding: 0 0 72px; }
  .chat-bubble { max-width: 88%; }
  .chat-welcome { margin: 8px auto 0; padding: 16px 18px; }

  /* Admin view */
  .admin-search-row { flex-direction: column; gap: 6px; }
  .admin-search-row .btn { width: 100%; justify-content: center; }

  /* Billing */
  .billing-status-row { flex-direction: column; gap: 10px; }
  .billing-actions { width: 100%; }
  .billing-actions .btn { width: 100%; justify-content: center; }
  .billing-plan-chooser { flex-direction: column; }

  /* Team cards */
  .team-card { flex-wrap: wrap; gap: 8px; }
  .team-card-actions { width: 100%; justify-content: flex-end; }

  /* Invite cards */
  .invite-card { flex-direction: column; align-items: flex-start; gap: 8px; }
  .invite-actions { width: 100%; display: flex; gap: 8px; }
  .invite-actions .btn { flex: 1; justify-content: center; }

  /* Lobby */
  .lobby-main { padding: 24px 16px 88px; }

  /* Lobby + tradesman topbar */
  .topbar { padding: 12px 16px; }
  .topbar-right { gap: 6px; }
  .topbar-right .user-email { display: none; }

  /* Reassign picker */
  #reassign-picker { flex-wrap: wrap; }
  #reassign-picker select { width: 100%; }

  /* Specialty checkboxes */
  .specialty-checkboxes { gap: 10px 12px; }

  /* Radio group */
  .radio-group { flex-wrap: wrap; gap: 12px; }

  /* Reports */
  .report-card { padding: 12px 14px; gap: 10px; }
  .draft-job-card { padding: 12px; gap: 10px; }
  .draft-job-row .draft-specialty, .draft-job-row .draft-priority, .draft-job-row .draft-property { min-width: 100%; }
  .review-modal-footer { flex-wrap: wrap; gap: 8px; }
  .review-modal-footer > div { width: 100%; }
  .review-modal-footer > div .btn { flex: 1; justify-content: center; min-height: 44px; }
}

/* ── Tradesman portal ───────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: #fff; border-bottom: 1px solid var(--grey-100);
  box-shadow: var(--shadow);
}
.topbar-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--blue); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.ts-main { display: flex; align-items: center; justify-content: center; height: calc(100vh - 58px); height: calc(100dvh - 58px); }
.ts-placeholder { text-align: center; color: var(--grey-400); }
.ts-placeholder h2 { color: var(--grey-700); font-size: 18px; margin: 16px 0 8px; }
.ts-placeholder svg { display: block; margin: 0 auto; opacity: .5; }
