@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;600;700&family=DM+Sans:wght@300;400;500&display=swap');

:root {
  --blue: #0076a3;
  --blue-light: #e8f4fa;
  --blue-mid: #f0f7fa;
  --border: #e0ddd6;
  --bg: #f5f4f0;
  --dark: #111;
  --mid: #555;
  --light: #aaa;
  --white: #fff;
  --radius: 10px;
  --radius-sm: 4px;
  --sidebar-w: 56px;
}

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

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--dark);
  font-size: 14px;
}

h1, h2, h3, h4 {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  line-height: 1.1;
}

/* ── Layout ── */
.fh-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.fh-sidebar {
  width: var(--sidebar-w);
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  flex-shrink: 0;
  z-index: 10;
}

.fh-sidebar .sb-logo {
  width: 32px;
  height: 32px;
  margin-bottom: 20px;
  border-radius: 6px;
  overflow: hidden;
}

.fh-sidebar .sb-logo img { width: 100%; }

.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  width: 100%;
  padding: 0 6px;
}

.sb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px 8px;
  border-radius: var(--radius-sm);
  color: #888;
  text-decoration: none;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.03em;
  gap: 3px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  transition: color 0.15s, background 0.15s;
}

.sb-item i { font-size: 20px; }

.sb-item:hover, .sb-item.active {
  color: var(--white);
  background: rgba(255,255,255,0.08);
}

.sb-item.active { color: #4fc3f7; }

.sb-item.sb-logout { margin-top: auto; color: #666; }
.sb-item.sb-logout:hover { color: #ef5350; background: rgba(239,83,80,0.1); }

/* ── Main area ── */
.fh-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fh-topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.fh-topbar h1 { font-size: 22px; color: var(--dark); }

.fh-topbar-right { display: flex; align-items: center; gap: 10px; }

.fh-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.kpi-card .kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.kpi-card .kpi-value {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 36px;
  font-weight: 700;
  color: var(--dark);
  line-height: 1;
}

.kpi-card.kpi-emergency .kpi-value { color: #d32f2f; }
.kpi-card.kpi-completed .kpi-value { color: #388e3c; }

/* ── Dashboard grid ── */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
}

/* ── Filter chips ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 12px;
  font-weight: 500;
  color: var(--mid);
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.active { background: var(--blue); color: var(--white); border-color: var(--blue); }

/* ── Job board ── */
.job-board {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.job-board-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.job-board-header h3 { font-size: 16px; }

.job-list { overflow-y: auto; max-height: 520px; }

.job-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.job-row:last-child { border-bottom: none; }
.job-row:hover { background: var(--bg); }

.priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.job-row-info { flex: 1; min-width: 0; }

.job-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.job-customer { font-weight: 500; font-size: 14px; }
.job-equip { font-size: 12px; color: var(--mid); }
.job-meta { font-size: 11px; color: var(--light); }

.status-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  color: var(--white);
  white-space: nowrap;
  flex-shrink: 0;
}

.job-tech { font-size: 12px; color: var(--mid); flex-shrink: 0; }

/* ── Right panel (map + crew) ── */
.right-panel { display: flex; flex-direction: column; gap: 14px; }

.panel-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 15px;
  font-weight: 700;
}

.map-container { height: 220px; }

.crew-list { padding: 8px 0; }

.crew-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
}

.crew-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.crew-name { font-weight: 500; font-size: 13px; }
.crew-job  { font-size: 11px; color: var(--mid); }

.activity-feed { max-height: 180px; overflow-y: auto; padding: 8px 0; }

.feed-item {
  display: flex;
  gap: 10px;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--mid);
}

.feed-item-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  margin-top: 5px;
  flex-shrink: 0;
}

.feed-item-text { flex: 1; line-height: 1.4; }
.feed-item-time { color: var(--light); white-space: nowrap; }

/* ── Job workspace ── */
.job-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.job-header-info h2 { font-size: 24px; }
.job-header-info p  { font-size: 13px; color: var(--mid); margin-top: 2px; }

.tab-bar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 24px;
  gap: 0;
}

.tab {
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--mid);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--dark); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

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

/* ── Form fields (reused from main site) ── */
.form-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 30px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--mid);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--dark);
  transition: border-color 0.15s;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
}

.field textarea { resize: vertical; min-height: 80px; }

.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}

/* ── Buttons ── */
.btn-p {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-p:hover { background: #005f85; }

.btn-g {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  background: var(--white);
  color: var(--mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.btn-g:hover { border-color: var(--dark); color: var(--dark); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  background: var(--white);
  color: #d32f2f;
  border: 1px solid #ffcdd2;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover { background: #ffebee; }

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

/* ── Work log ── */
.work-log-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }

.work-log-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--white);
}

.wl-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.wl-type {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wl-type.work_performed { background: var(--blue-light); color: var(--blue); }
.wl-type.note { background: #fff8e1; color: #f57f17; }

.wl-author { font-weight: 500; font-size: 13px; }
.wl-time { font-size: 11px; color: var(--light); margin-left: auto; }
.wl-body { font-size: 13px; color: var(--dark); line-height: 1.5; }

.wl-delete {
  background: none; border: none; cursor: pointer;
  color: var(--light); font-size: 14px; padding: 2px;
  transition: color 0.15s;
}
.wl-delete:hover { color: #d32f2f; }

/* ── Photos ── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}

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

.photo-thumb .ph-delete {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.6);
  color: var(--white);
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}

.photo-thumb:hover .ph-delete { opacity: 1; }

.photo-label {
  font-size: 10px;
  color: var(--light);
  margin-top: 3px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.lightbox.open { display: flex; }

.lightbox img, .lightbox video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-sm);
}

.lightbox-close {
  position: fixed;
  top: 20px; right: 24px;
  color: var(--white);
  font-size: 28px;
  background: none;
  border: none;
  cursor: pointer;
}

/* ── Invoice ── */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
}

.invoice-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--mid);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.invoice-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.invoice-table input[type="text"],
.invoice-table input[type="number"] {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 13px;
  width: 100%;
  background: #fafafa;
}

.invoice-table input:focus {
  outline: none;
  border-color: var(--blue);
}

.taxable-toggle {
  width: 36px; height: 20px;
  appearance: none;
  background: var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.taxable-toggle::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--white);
  top: 3px; left: 3px;
  transition: left 0.15s;
}

.taxable-toggle:checked { background: var(--blue); }
.taxable-toggle:checked::after { left: 19px; }

.invoice-totals {
  max-width: 280px;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.totals-row:last-child {
  border-bottom: none;
  font-weight: 700;
  font-size: 15px;
  background: var(--blue-mid);
}

.invoice-status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: var(--radius);
}

.inv-status-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.inv-status-badge.draft { background: #fff3e0; color: #e65100; }
.inv-status-badge.sent  { background: var(--blue-light); color: var(--blue); }
.inv-status-badge.paid  { background: #e8f5e9; color: #2e7d32; }

/* ── Revisit tab ── */
.revisit-link-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 14px;
}

.revisit-link-card i { font-size: 24px; color: var(--blue); }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.login-box {
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img { height: 48px; }
.login-logo h2 { font-size: 26px; margin-top: 10px; }
.login-logo p { font-size: 13px; color: var(--mid); margin-top: 4px; }

.login-error {
  color: #d32f2f;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
  min-height: 18px;
}

.form-submit {
  width: 100%;
  padding: 11px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}

.form-submit:hover { background: #005f85; }

/* ── Utility ── */
.sec-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--light);
}

.empty-state i { font-size: 36px; margin-bottom: 10px; display: block; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .fields-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .fh-topbar { padding: 0 14px; }
  .fh-content { padding: 14px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
