:root {
  --sidebar-width: 220px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active: #3b82f6;
  --accent: #3b82f6;
  --header-height: 0px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f8fafc;
  color: #1e293b;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #f1f5f9;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo i { font-size: 1.5rem; }

.sidebar-nav {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  flex: 1;
}
.sidebar-nav li { margin: 2px 8px; }
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: #f1f5f9; }
.sidebar-nav .nav-link.active { background: var(--accent); color: #fff; }
.sidebar-nav .nav-link i { font-size: 1rem; width: 18px; text-align: center; }

/* ── Sidebar user footer ─────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid #1e293b;
  margin-top: auto;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-company-name {
  font-size: 0.72rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-logout {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  font-size: 1.1rem;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.btn-logout:hover { color: #f87171; background: rgba(239,68,68,.1); }

/* ── Main content ────────────────────────── */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 24px;
  max-width: calc(100vw - var(--sidebar-width));
}

.page { display: none; }
.page.active { display: block; }

/* ── Page headers ────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e2e8f0;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: #0f172a;
}

/* ── Stat cards ──────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  border: 1px solid #e2e8f0;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.stat-value { font-size: 2rem; font-weight: 700; color: #0f172a; line-height: 1; }
.stat-label { font-size: 0.8rem; color: #64748b; margin-top: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-icon  { font-size: 1.5rem; opacity: .6; }

/* ── Cards ───────────────────────────────── */
.card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: 12px 12px 0 0;
}

/* ── Tables ──────────────────────────────── */
.table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
  font-weight: 600;
  background: #f8fafc;
}
.table td { vertical-align: middle; font-size: 0.88rem; }
.table-hover tbody tr:hover { background: #f0f9ff; cursor: pointer; }

/* ── Status badges ───────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}
.status-unscheduled { background: #f1f5f9; color: #475569; }
.status-scheduled   { background: #dbeafe; color: #1d4ed8; }
.status-en_route    { background: #fef3c7; color: #92400e; }
.status-in_progress { background: #ede9fe; color: #5b21b6; }
.status-completed   { background: #dcfce7; color: #15803d; }
.status-invoiced    { background: #e0f2fe; color: #0369a1; }
.status-paid        { background: #bbf7d0; color: #14532d; }
.status-cancelled   { background: #fee2e2; color: #b91c1c; }
.status-draft       { background: #f1f5f9; color: #475569; }
.status-sent        { background: #dbeafe; color: #1d4ed8; }
.status-approved    { background: #dcfce7; color: #15803d; }
.status-declined    { background: #fee2e2; color: #b91c1c; }
.status-converted   { background: #f0fdf4; color: #166534; }
.status-partial     { background: #fef9c3; color: #713f12; }
.status-overdue     { background: #fee2e2; color: #b91c1c; }

/* ── Unsent invoice indicator ────────────── */
.badge-unsent {
  display: inline-flex;
  align-items: center;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  margin-left: 6px;
  vertical-align: middle;
}
.tr-unsent { background: #fffbeb !important; }

/* ── Job type chips ──────────────────────── */
.job-type-chip {
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.jt-test_short, .jt-test_long, .jt-test_crm { background: #e0f2fe; color: #0369a1; }
.jt-mitigation  { background: #ede9fe; color: #5b21b6; }
.jt-post_mit_test { background: #f0fdf4; color: #166534; }
.jt-maintenance, .jt-warranty { background: #fef9c3; color: #713f12; }

/* ── Search bar ──────────────────────────── */
.search-bar {
  position: relative;
  max-width: 320px;
}
.search-bar input { padding-left: 36px; }
.search-bar i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
}

/* ── Calendar ────────────────────────────── */
#calendar-container {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.fc-event { cursor: pointer; border-radius: 4px !important; font-size: 0.78rem; }
.fc-toolbar-title { font-size: 1.1rem !important; font-weight: 700 !important; }

/* ── Forms ───────────────────────────────── */
.form-label { font-weight: 500; font-size: 0.85rem; color: #374151; margin-bottom: 4px; }
.form-control, .form-select {
  border-color: #d1d5db;
  border-radius: 8px;
  font-size: 0.88rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ── Buttons ─────────────────────────────── */
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn { border-radius: 8px; font-size: 0.875rem; font-weight: 500; }

/* ── Today schedule list ─────────────────── */
.schedule-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
}
.schedule-item:last-child { border-bottom: none; }
.schedule-time {
  min-width: 70px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  padding-top: 2px;
}
.schedule-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

/* ── Line items ──────────────────────────── */
.line-items-table input, .line-items-table select {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.84rem;
  width: 100%;
}
.line-items-table input:focus { outline: none; border-color: var(--accent); }

/* ── Detail page grid ────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
}
.detail-label { font-size: 0.78rem; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .04em; }
.detail-value { font-size: 0.9rem; color: #1e293b; }

/* ── Mobile top bar ──────────────────────── */
#mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  z-index: 300;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#mobile-menu-btn {
  background: none;
  border: none;
  color: #f1f5f9;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  flex-shrink: 0;
}
#mobile-menu-btn:hover { background: var(--sidebar-hover); }
#mobile-topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f1f5f9;
  flex: 1;
}
#mobile-topbar-title i { color: var(--accent); }

/* ── Sidebar overlay (mobile) ────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
}

@media (max-width: 768px) {
  /* Show mobile top bar */
  #mobile-topbar { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  #sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 200;
  }
  #sidebar.sidebar-open {
    transform: translateX(0);
  }
  #sidebar-overlay.open { display: block; }

  /* Main content: no left margin, top padding for topbar */
  #main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: calc(52px + 16px);
    max-width: 100vw;
  }

  /* Detail grid: single column */
  .detail-grid { grid-template-columns: 1fr; }

  /* Page header wraps on narrow screens */
  .page-header { flex-wrap: wrap; gap: 8px; }
  .page-header h1 { font-size: 1.25rem; }

  /* Full-screen modals on mobile */
  #mainModal .modal-dialog {
    margin: 0;
    max-width: 100vw;
    min-height: 100dvh;
    width: 100vw;
  }
  #mainModal .modal-content {
    border-radius: 0;
    min-height: 100dvh;
  }

  /* Filters stack nicely */
  .search-bar { max-width: 100%; }

  /* Stat cards: 2-up stays fine */

  /* Modal body scrolls inside full-screen modal */
  #mainModal .modal-body { overflow-y: auto; }

  /* Table cells clip less aggressively */
  .table td, .table th { font-size: 0.8rem; }

  /* Calendar toolbar shrinks */
  .fc-toolbar { flex-wrap: wrap; gap: 4px; }
  .fc-toolbar-title { font-size: 0.95rem !important; }
}

/* ── Inline sub-panels ───────────────────── */
#nj-new-customer-panel, #nj-new-property-panel { animation: slideDown .15s ease; }
@keyframes slideDown { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }

/* ── Misc ────────────────────────────────── */
.clickable { cursor: pointer; }
.text-money { font-variant-numeric: tabular-nums; }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}
.empty-state i { font-size: 3rem; display: block; margin-bottom: 12px; }
.section-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: #94a3b8; margin-bottom: 8px; }
