/* ============================================
   ASTRAPIA CRM — style.css
   Desktop + Tablet (11") + Mobile Responsive
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: #f0f2f5; color: #333; }

.wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 250px;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  top: 0; left: 0;
  z-index: 999;
  transition: left 0.3s ease;
  overflow-y: auto;
}
.sidebar-header { padding: 20px; background: #16213e; }
.sidebar-header h2 { font-size: 18px; color: #e94560; }
.sidebar-menu { list-style: none; flex: 1; padding: 20px 0; }
.sidebar-menu li a {
  display: block;
  padding: 12px 20px;
  color: #ccc;
  text-decoration: none;
  transition: 0.3s;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.sidebar-menu li a:hover, .sidebar-menu li a.active { background: #e94560; color: #fff; }
.sidebar-menu li a i { margin-right: 10px; }
.sidebar-footer { padding: 20px; }
.sidebar-footer a { color: #ccc; text-decoration: none; }
.sidebar-footer a:hover { color: #e94560; }

/* ── Main Content ── */
.main-content { margin-left: 250px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Topbar ── */
.topbar {
  background: #fff;
  padding: 15px 25px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* ── Hamburger — hidden on desktop ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  color: #333;
  font-size: 22px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

/* ── Sidebar overlay — NEVER blocks content when hidden ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 998;
  pointer-events: none;
}
.sidebar-overlay.active {
  display: block;
  pointer-events: auto;
}

/* ── Content area ── */
.content-area {
  padding: 25px;
  position: relative;
  z-index: 1;
}

/* ── Page header row ── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-title { font-size: 22px; font-weight: 700; color: #1a1a2e; }

/* ── Form card max-width for forms ── */
.form-card { max-width: 900px; }

/* ── Job number box ── */
.job-number-box {
  background: #f8f9fa;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}
.job-number-label { font-size: 12px; color: #888; margin-bottom: 4px; }
.job-number-input {
  font-size: 18px !important;
  font-weight: 700 !important;
  color: #e94560 !important;
  max-width: 340px;
}

/* ── Form submit row ── */
.form-submit-row {
  margin-top: 8px;
  padding-top: 8px;
}
.form-submit-row .btn {
  font-size: 16px;
  padding: 12px 32px;
  min-height: 48px;
}

/* ── Cards ── */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  margin-bottom: 20px;
  overflow-x: auto;
}
.card-title { font-size: 18px; font-weight: 600; margin-bottom: 15px; color: #1a1a2e; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 25px; }
.stat-card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); display: flex; align-items: center; gap: 15px; }
.stat-icon { width: 50px; height: 50px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff; flex-shrink: 0; }
.stat-icon.blue   { background: #4e73df; }
.stat-icon.green  { background: #1cc88a; }
.stat-icon.orange { background: #f6c23e; }
.stat-icon.red    { background: #e74a3b; }
.stat-info h3 { font-size: 24px; font-weight: 700; }
.stat-info p  { font-size: 13px; color: #888; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; min-width: 600px; }
table th { background: #f8f9fa; padding: 12px; text-align: left; font-weight: 600; border-bottom: 2px solid #dee2e6; white-space: nowrap; }
table td { padding: 12px; border-bottom: 1px solid #f0f0f0; }
table tr:hover { background: #f8f9fa; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 2;
  min-height: 40px;
}
.btn-primary   { background: #e94560; color: #fff; }
.btn-primary:hover, .btn-primary:active { background: #c73652; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #565e64; }
.btn-success   { background: #1cc88a; color: #fff; }
.btn-success:hover { background: #17a673; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  transition: 0.2s;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  min-height: 44px;
  background-color: #fff;
}
.form-control:focus { outline: none; border-color: #e94560; box-shadow: 0 0 0 3px rgba(233,69,96,0.1); }
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23666' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

/* ── Badges ── */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-new         { background: #e3f2fd; color: #1976d2; }
.badge-contacted   { background: #e8f5e9; color: #2e7d32; }
.badge-site_visit  { background: #fff3e0; color: #e65100; }
.badge-measurement { background: #f3e5f5; color: #6a1b9a; }
.badge-quoted      { background: #fff3e0; color: #f57c00; }
.badge-won         { background: #e8f5e9; color: #388e3c; }
.badge-lost        { background: #fce4ec; color: #c62828; }
.badge-admin       { background: #e94560; color: #fff; }
.badge-sales       { background: #4e73df; color: #fff; }
.badge-production  { background: #f6c23e; color: #333; }
.badge-technician  { background: #1cc88a; color: #fff; }

/* ── Alerts ── */
.alert { padding: 12px 18px; border-radius: 6px; margin-bottom: 20px; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ── Order status colours ── */
.status-ord-received      { background:#cfe2ff; color:#084298; }
.status-ord-in_production { background:#fff3cd; color:#856404; }
.status-ord-ready         { background:#d1e7dd; color:#0a3622; }
.status-ord-dispatched    { background:#e2d9f3; color:#432874; }
.status-ord-delivered     { background:#d1e7dd; color:#0a3622; }
.status-ord-cancelled     { background:#f8d7da; color:#842029; }

/* ── Quotation status colours ── */
.status-draft    { background:#fff3cd; color:#856404; }
.status-sent     { background:#cfe2ff; color:#084298; }
.status-approved { background:#d1e7dd; color:#0a3622; }
.status-rejected { background:#f8d7da; color:#842029; }

/* ============================================
   TABLET — 769px to 1200px (11-inch iPad/tab)
   ============================================ */
@media (min-width: 769px) and (max-width: 1200px) {

  /* Sidebar slides in like mobile on tablet */
  .hamburger { display: block; }
  .sidebar { left: -260px; }
  .sidebar.open { left: 0; }
  .main-content { margin-left: 0; }

  .topbar { padding: 12px 18px; }
  .content-area { padding: 18px; padding-bottom: 60px; }

  /* 2-column grid — clean on 11" portrait and landscape */
  .form-grid { grid-template-columns: 1fr 1fr !important; gap: 16px; }

  /* Stats 2-col on tablet */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 14px; }

  /* Submit button tap-friendly */
  .form-submit-row .btn {
    min-height: 52px !important;
    font-size: 16px !important;
    padding: 14px 36px !important;
    touch-action: manipulation !important;
  }

  /* All inputs and selects tap-friendly */
  .form-control {
    font-size: 16px !important;
    min-height: 48px !important;
    padding: 12px 14px !important;
  }

  /* Inline style grid overrides */
  div[style*="grid-template-columns:repeat(4,1fr)"],
  div[style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  div[style*="grid-template-columns:1fr 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Filter rows wrap */
  div[style*="display:flex"][style*="gap"],
  form[style*="display:flex"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  /* Page headers wrap */
  div[style*="display:flex;justify-content:space-between"],
  div[style*="display:flex; justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .card { overflow-x: auto; }
}

/* ============================================
   MOBILE — max-width: 768px
   ============================================ */
@media (max-width: 768px) {

  .hamburger { display: block; }
  .sidebar { left: -260px; }
  .sidebar.open { left: 0; }
  .main-content { margin-left: 0; }

  .topbar { padding: 10px 14px; gap: 8px; }
  .content-area { padding: 12px; padding-bottom: 40px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
  .stat-card  { padding: 14px; gap: 10px; }
  .stat-icon  { width: 38px; height: 38px; font-size: 16px; }
  .stat-info h3 { font-size: 20px; }

  /* Single column forms on mobile */
  .form-grid { grid-template-columns: 1fr !important; }

  .form-control { font-size: 16px !important; min-height: 48px !important; }

  /* Full-width submit on mobile */
  .form-submit-row .btn {
    width: 100% !important;
    min-height: 52px !important;
    font-size: 16px !important;
    justify-content: center;
  }

  div[style*="grid-template-columns:repeat(4,1fr)"],
  div[style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  div[style*="grid-template-columns:repeat(auto-fill,minmax(170px"],
  div[style*="grid-template-columns:repeat(auto-fill, minmax(170px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  div[style*="grid-template-columns:repeat(auto-fill,minmax(380px"],
  div[style*="grid-template-columns:repeat(auto-fill, minmax(380px"] {
    grid-template-columns: 1fr !important;
  }

  form[style*="display:flex"] {
    flex-direction: column !important;
    gap: 8px !important;
  }
  form .form-control,
  form select.form-control,
  form .btn {
    width: 100% !important;
    min-width: unset !important;
  }

  div[style*="display:flex;justify-content:space-between"],
  div[style*="display:flex; justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  td[style*="display:flex"] {
    flex-wrap: wrap !important;
    gap: 4px !important;
    white-space: normal !important;
  }

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

  div[id$="Modal"] > div,
  #emailModal > div {
    margin: 10px !important;
    padding: 20px !important;
    max-width: calc(100% - 20px) !important;
    width: 100% !important;
  }

  .topbar-welcome { display: none; }

  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ============================================
   VERY SMALL — max-width: 480px
   ============================================ */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns:repeat(4,1fr)"],
  div[style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
  div[style*="grid-template-columns:repeat(auto-fill,minmax(170px"] {
    grid-template-columns: 1fr !important;
  }
  .content-area { padding: 8px; }
  .card { padding: 12px; }
  .topbar { padding: 8px 10px; }
  table th, table td { padding: 8px; font-size: 12px; }
  .btn { padding: 8px 14px; font-size: 13px; }
  .btn-sm { padding: 4px 8px; font-size: 11px; }
}
