/* J&D Western Electric — Brand Tokens */
:root {
  --orange: #F47920;
  --orange-dark: #d4680f;
  --orange-light: #fde8d4;
  --black: #111111;
  --graphite: #2e3138;
  --dark: #1c1c1e;
  --gray-900: #1f1f1f;
  --gray-700: #3a3a3a;
  --gray-500: #6e6e6e;
  --gray-300: #c7c7cc;
  --gray-100: #f2f2f7;
  --gray-50: #f9f9fb;
  --white: #ffffff;
  --red: #d9342b;
  --green: #28a745;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--dark);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.app-header {
  background: var(--graphite);
  color: var(--white);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  min-width: 0;
  overflow: hidden;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0; /* brand never shrinks — logo + title stay visible */
}
.header-logo {
  height: 40px;
  width: 40px;
  object-fit: cover;
  border-radius: 8px;
  background: white;
  padding: 4px;
  flex-shrink: 0;
}
.header-title {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.header-title .company { font-size: 11px; color: var(--gray-300); letter-spacing: 0.05em; text-transform: uppercase; }
.header-title .module  { font-size: 15px; font-weight: 700; color: var(--white); letter-spacing: 0.02em; }
/* Nav scrolls horizontally on all screen sizes so links never get clipped */
.header-nav {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 1;
  min-width: 0;
  flex-wrap: nowrap !important;
}
.header-nav::-webkit-scrollbar { display: none; }
.header-nav a {
  color: var(--gray-300);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-nav a:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.header-nav a.active { background: var(--orange); color: var(--white); }

/* ── Landing page ── */
.landing {
  min-height: 100vh;
  background: var(--black);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.landing-logo { height: 160px; width: 160px; object-fit: contain; margin-bottom: 20px; background: white; border-radius: 20px; padding: 10px; }
.landing-subtitle { color: var(--gray-300); font-size: 15px; margin-top: 6px; letter-spacing: 0.03em; }
.landing h1 { color: var(--white); font-size: clamp(26px, 5vw, 40px); font-weight: 800; text-align: center; letter-spacing: -0.02em; }
.landing h1 span { color: #C1380A; }
.landing p { color: var(--gray-300); margin-top: 10px; text-align: center; font-size: 16px; }
.landing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 48px;
  width: 100%;
  max-width: 680px;
}
.landing-card {
  background: var(--dark);
  border: 1px solid var(--gray-700);
  border-radius: 16px;
  padding: 32px 28px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.2s;
  cursor: pointer;
}
.landing-card:hover { border-color: var(--orange); transform: translateY(-2px); box-shadow: 0 12px 40px rgba(244,121,32,0.2); }
.card-icon { width: 48px; height: 48px; background: var(--orange); border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.card-icon svg { width: 26px; height: 26px; fill: white; }
.landing-card h2 { color: var(--white); font-size: 20px; font-weight: 700; }
.landing-card p { color: var(--gray-300); font-size: 14px; line-height: 1.5; }
.card-arrow { color: var(--orange); font-size: 20px; margin-top: auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--orange); color: var(--white); }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { background: var(--gray-100); color: var(--dark); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #b82a22; }
.btn-ghost { background: transparent; color: var(--orange); border: 1px solid var(--orange); }
.btn-ghost:hover { background: var(--orange-light); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Form Elements ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--gray-700); letter-spacing: 0.02em; }
.form-label .required { color: var(--red); margin-left: 2px; }
.form-control {
  padding: 11px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  background: var(--white);
  color: var(--dark);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.form-control:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(244,121,32,0.15); }
.form-control::placeholder { color: var(--gray-300); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-hint { font-size: 12px; color: var(--gray-500); }
.form-error { font-size: 12px; color: var(--red); display: none; }
.form-control.error { border-color: var(--red); }

/* ── Cards / Sections ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { font-size: 16px; font-weight: 700; }
.card-body { padding: 20px; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-orange { background: var(--orange-light); color: var(--orange-dark); }
.badge-green  { background: #d4edda; color: #155724; }
.badge-gray   { background: var(--gray-100); color: var(--gray-500); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--dark);
  color: var(--white);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { background: #1a6e35; }
#toast.error   { background: var(--red); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--gray-500); padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--dark); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-100); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Misc utilities ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-sm   { font-size: 13px; }
.text-xs   { font-size: 11px; }
.text-muted { color: var(--gray-500); }
.text-orange { color: var(--orange); }
.font-bold  { font-weight: 700; }
.divider { height: 1px; background: var(--gray-100); margin: 20px 0; }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .modal { border-radius: 16px 16px 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}

/* ═══════════════════════════════════════════
   GLOBAL MOBILE OVERRIDES  ≤ 768px
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header: hide text, keep logo + minimal nav ── */
  .app-header { padding: 0 12px; height: 52px; }
  .header-title .company { display: none; }
  .header-title .module  { font-size: 13px; }
  .header-logo { height: 34px; width: 34px; }

  /* ── Nav: compress to icon-only or collapse ── */
  .header-nav { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .header-nav::-webkit-scrollbar { display: none; }
  .header-nav a { font-size: 12px; padding: 5px 8px; white-space: nowrap; }

  /* ── Body text sizes ── */
  body { font-size: 14px; }

  /* ── Buttons: bigger tap targets ── */
  .btn { padding: 11px 18px; font-size: 14px; }
  .btn-sm { padding: 8px 12px; font-size: 13px; }
  .btn-lg { padding: 15px 20px; font-size: 15px; }

  /* ── Form controls: larger for finger input ── */
  .form-control { padding: 13px 14px; font-size: 16px; } /* 16px prevents iOS zoom */
  select.form-control { font-size: 16px; }
  textarea.form-control { font-size: 16px; }

  /* ── Card body: less padding ── */
  .card-body { padding: 14px 16px; }
  .card-header { padding: 12px 16px; }

  /* ── Modal: slide up from bottom ── */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; max-width: 100%; }
  .modal-header { padding: 16px 18px 12px; }
  .modal-body   { padding: 14px 18px; }
  .modal-footer { padding: 12px 18px; flex-wrap: wrap; gap: 8px; }
  .modal-footer .btn { flex: 1; justify-content: center; min-width: 80px; min-height: 44px; font-size: 15px; }

  /* ── Grid utilities ── */
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 12px; }

  /* ── Landing cards: single column ── */
  .landing-cards { grid-template-columns: 1fr; gap: 12px; margin-top: 28px; }

  /* ── Toast: full-width ── */
  #toast { left: 12px; right: 12px; transform: translateX(0) translateY(80px); max-width: none; }
  #toast.show { transform: translateX(0) translateY(0); }

  /* ── Crew / data tables: horizontal scroll ── */
  .crew-table-wrap, .table-scroll-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Sidebar layouts: hide sidebar, show tab strip ── */
  .sidebar-layout-sidebar { display: none !important; }
  .sidebar-layout-tabstrip { display: flex !important; }
  .sidebar-layout-main { padding: 16px 14px 48px !important; }
}

/* ═══════════════════════════════════════════
   OFFICE DASHBOARD MOBILE  ≤ 768px
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

  .page-wrap { padding: 14px 12px 48px; }

  /* Stats grid: 2 cols */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-val  { font-size: 22px; }
  .stat-label{ font-size: 11px; }

  /* Filter bar: stack vertically */
  .filter-bar { flex-direction: column; gap: 8px; }
  .filter-bar .form-group { min-width: 0; }
  .filter-actions { width: 100%; justify-content: flex-start; }

  /* Ticket rows: simplified 2-col layout */
  .ticket-row {
    grid-template-columns: 80px 1fr 60px 36px !important;
    gap: 8px;
    padding: 10px 12px;
  }
  .ticket-supervisor { display: none; }
  .ticket-job .job-num { display: none; }

  /* PO table: horizontal scroll */
  .po-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .po-filter-bar { flex-direction: column; gap: 8px; }
  .po-filter-bar .form-group { min-width: 0; }

  /* Home cards: 1 col */
  .home-cards { grid-template-columns: 1fr; gap: 10px; }

  /* Project cards: stack */
  .project-card { padding: 14px; }

  /* Timesheets: scroll */
  #ts-employee-list { overflow-x: auto; }
  #ts-day-table { min-width: 600px; }

  /* Timeoff stats bar: 2×2 grid */
  #to-stats-bar { grid-template-columns: repeat(2,1fr) !important; }
}

/* ═══════════════════════════════════════════
   FIELD VIEW MOBILE  ≤ 480px
   ═══════════════════════════════════════════ */
@media (max-width: 480px) {
  .ticket-header-bar { padding: 14px 16px; }
  .form-section      { padding: 14px 16px; }

  /* Employee table: horizontal scroll on mobile */
  .employee-table { min-width: 480px; }
  .form-section > div[style*="overflow"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .submit-section { padding: 14px 16px 24px; }
}

/* ═══════════════════════════════════════════
   HAMBURGER NAV  ≤ 600px
   ═══════════════════════════════════════════ */
@media (max-width: 600px) {
  /* Show hamburger toggle button */
  .nav-hamburger { display: flex !important; }

  /* Mobile nav drawer (hidden by default, shown when .open) */
  .header-nav {
    position: fixed;
    top: 52px;
    left: 0; right: 0;
    background: var(--black);
    flex-direction: column;
    padding: 8px 12px 16px;
    gap: 2px;
    display: none !important;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    z-index: 99;
    overflow-x: unset;
  }
  .header-nav.nav-open { display: flex !important; }
  .header-nav a { padding: 10px 14px; border-radius: 8px; font-size: 14px; width: 100%; }
  .header-nav a.active { background: var(--orange); }

  /* Hamburger icon */
  .nav-hamburger {
    background: none; border: none; cursor: pointer;
    color: white; padding: 6px; display: none;
    flex-direction: column; gap: 4px;
  }
  .nav-hamburger span { display: block; width: 20px; height: 2px; background: white; border-radius: 2px; transition: .2s; }
}

/* ═══════════════════════════════════════════
   BACK BUTTON
   ═══════════════════════════════════════════ */
.back-bar {
  display: flex;
  align-items: center;
  padding: 8px 0 4px;
  margin-bottom: 4px;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  color: var(--gray-600);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px 6px 10px;
  cursor: pointer;
  min-height: 36px;
  line-height: 1;
  transition: border-color .15s, color .15s, background .15s;
}
.back-btn:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-light); }
.back-btn svg   { flex-shrink: 0; }
@media (max-width: 768px) {
  .back-bar { padding: 10px 0 6px; }
  .back-btn { min-height: 44px; font-size: 15px; padding: 10px 18px 10px 12px; }
}

/* ═══════════════════════════════════════════
   DAILY TICKET EDIT MODAL — MOBILE  ≤ 600px
   Employee table rows stack vertically
   ═══════════════════════════════════════════ */
@media (max-width: 600px) {
  /* Date / Job-number 2-col grid → single column */
  .edit-ticket-date-grid { grid-template-columns: 1fr !important; }

  /* Employee table wrapper already has overflow-x:auto — on mobile,
     switch to a card-stack layout instead */
  .edit-emp-table-wrap { overflow-x: visible !important; }
  .edit-emp-table { display: block; min-width: 0 !important; }
  .edit-emp-table thead { display: none; }
  .edit-emp-table tbody { display: block; }
  .edit-emp-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 4px;
  }
  .edit-emp-row td {
    display: flex;
    flex-direction: column;
    padding: 0;
  }
  /* Name spans full width */
  .edit-emp-row td:first-child { grid-column: 1 / -1; }
  /* Delete button: right-align, same row as last pair */
  .edit-emp-row td:last-child {
    grid-column: 2;
    align-items: flex-end;
    justify-content: flex-end;
  }
  /* Data-label pseudo-content above each cell */
  .edit-emp-row td[data-label]::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
    margin-bottom: 3px;
  }
  /* Inputs fill their cell */
  .edit-emp-row td .form-control { width: 100%; box-sizing: border-box; font-size: 16px !important; }
}

/* ═══════════════════════════════════════════
   TEAM TABLE — MOBILE  ≤ 768px
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Wrap team table in horizontal scroll */
  .team-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .team-table      { min-width: 560px; }
}

/* ═══════════════════════════════════════════
   TIME OFF ARCHIVE / REQUESTS TABLE — MOBILE
   ═══════════════════════════════════════════ */
@media (max-width: 600px) {
  .to-archive-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .to-archive-table      { min-width: 520px; }
  /* Time-off calendar: shrink day cells */
  .to-cal-cell { padding: 4px 2px !important; min-height: 50px !important; }
  .to-cal-event { font-size: 10px !important; padding: 1px 3px !important; }
  /* Admin calendar filters: stack */
  #admin-cal-filter-bar { flex-direction: column !important; gap: 8px !important; }
}

/* ═══════════════════════════════════════════
   DATE INPUT OVERFLOW FIX (iOS Safari)
   Ensure date inputs never overflow their grid cell
   ═══════════════════════════════════════════ */
input[type="date"].form-control {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}
/* Ensure grid cells with date inputs don't overflow */
.grid-2, .grid-3, .date-grid {
  min-width: 0;
}
.grid-2 > *, .grid-3 > *, .date-grid > * {
  min-width: 0;
  overflow: hidden;
}
