/* =====================================================
   FAMILIFOOD SALES PORTAL — Global Styles
   Colour palette matched to www.familifood.com
   ===================================================== */

:root {
  --ff-red:        #C0272D;
  --ff-red-dark:   #8B0000;
  --ff-red-light:  #E53935;
  --ff-black:      #0D0D0D;
  --ff-dark:       #1A1A1A;
  --ff-dark2:      #242424;
  --ff-dark3:      #2E2E2E;
  --ff-mid:        #3A3A3A;
  --ff-border:     #3D3D3D;
  --ff-text:       #F0F0F0;
  --ff-text-muted: #A0A0A0;
  --ff-white:      #FFFFFF;
  --ff-cream:      #F8F4EF;
  --ff-success:    #2E7D32;
  --ff-warning:    #E65100;
  --ff-info:       #1565C0;
  --ff-btn-text:   #FFFFFF;
  --radius:        8px;
  --shadow:        0 4px 20px rgba(0,0,0,0.5);
  --transition:    all 0.2s ease;
}

/* Light theme — swaps the same palette variables everything else already
   uses, so it applies portal-wide without touching individual components.
   Toggled by setting data-theme="light" on <html> (see api.js applyBranding). */
:root[data-theme="light"] {
  --ff-black:      #F4F4F4;
  --ff-dark:       #FFFFFF;
  --ff-dark2:      #FFFFFF;
  --ff-dark3:      #F0F0F0;
  --ff-mid:        #E0E0E0;
  --ff-border:     #DADADA;
  --ff-text:       #1A1A1A;
  --ff-text-muted: #6B6B6B;
  --ff-white:      #111111;
  --shadow:        0 4px 20px rgba(0,0,0,0.1);
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--ff-black);
  color: var(--ff-text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--ff-red-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--ff-dark); }
::-webkit-scrollbar-thumb { background: var(--ff-mid); border-radius: 3px; }

/* ===================== LAYOUT ===================== */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh; /* phones: visible area only, excluding browser toolbars */
  overflow: hidden;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--ff-dark);
  border-right: 1px solid var(--ff-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--ff-border);
  text-align: center;
}

.sidebar-logo img {
  max-width: 140px;
  height: auto;
}

.sidebar-logo .portal-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ff-red-light);
  margin-top: 6px;
}

.sidebar-user {
  padding: 14px 20px;
  border-bottom: 1px solid var(--ff-border);
}

.sidebar-user .user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ff-white);
}

.sidebar-user .user-role {
  font-size: 12px;
  color: var(--ff-text-muted);
  text-transform: capitalize;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ff-text-muted);
  padding: 12px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--ff-text-muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: var(--transition);
  font-size: 14px;
}

.nav-item:hover {
  background: var(--ff-dark2);
  color: var(--ff-white);
}

.nav-item.active {
  background: rgba(192, 39, 45, 0.12);
  color: var(--ff-red-light);
  border-left-color: var(--ff-red);
}

.nav-item .nav-icon { font-size: 17px; }

.nav-badge {
  margin-left: auto;
  background: var(--ff-red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--ff-border);
}

.btn-logout {
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--ff-border);
  color: var(--ff-text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
}

.btn-logout:hover {
  border-color: var(--ff-red);
  color: var(--ff-red-light);
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ff-black);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  border-bottom: 1px solid var(--ff-border);
  background: var(--ff-dark);
  flex-shrink: 0;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ff-white);
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ===================== CARDS ===================== */
.card {
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ff-white);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .card-icon { color: var(--ff-red-light); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ff-red-light);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--ff-text-muted);
  margin-top: 4px;
}

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--ff-red);
  color: var(--ff-btn-text);
}

.btn-primary:hover { background: var(--ff-red-dark); }

.btn-secondary {
  background: var(--ff-dark3);
  color: var(--ff-text);
  border: 1px solid var(--ff-border);
}

.btn-secondary:hover { background: var(--ff-mid); }

.btn-success {
  background: var(--ff-success);
  color: var(--ff-white);
}

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

/* ===================== TABLE ===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead tr {
  background: var(--ff-dark3);
  border-bottom: 2px solid var(--ff-border);
}

thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--ff-text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--ff-border);
  transition: background .15s;
}

tbody tr:hover { background: var(--ff-dark3); }

tbody td { padding: 11px 14px; color: var(--ff-text); }

/* ===================== FORMS ===================== */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 13px;
  color: var(--ff-text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--ff-dark3);
  border: 1px solid var(--ff-border);
  border-radius: var(--radius);
  color: var(--ff-text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--ff-red);
}

input::placeholder { color: var(--ff-text-muted); }

select option { background: var(--ff-dark3); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ===================== BADGES ===================== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green  { background: rgba(46,125,50,.25);  color: #66BB6A; }
.badge-red    { background: rgba(192,39,45,.25);  color: #EF5350; }
.badge-orange { background: rgba(230,81,0,.25);   color: #FFA726; }
.badge-gray   { background: rgba(100,100,100,.25);color: #9E9E9E; }
.badge-blue   { background: rgba(21,101,192,.25); color: #42A5F5; }
.badge-purple { background: rgba(142,36,170,.25); color: #CE93D8; }

/* ===================== PIN COLOURS ===================== */
.pin-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.pin-red    { background: #E53935; }
.pin-green  { background: #2E7D32; }
.pin-orange { background: #E65100; }
.pin-black  { background: #757575; }
.pin-purple { background: #8E24AA; }

/* ===================== MODAL ===================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  border-radius: 12px;
  width: min(560px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--ff-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ff-white);
}

.modal-close {
  background: none;
  border: none;
  color: var(--ff-text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--ff-white); }

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--ff-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===================== ALERTS ===================== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error   { background: rgba(192,39,45,.2);  border: 1px solid var(--ff-red);    color: #EF9A9A; }
.alert-success { background: rgba(46,125,50,.2);  border: 1px solid var(--ff-success); color: #A5D6A7; }
.alert-info    { background: rgba(21,101,192,.2); border: 1px solid var(--ff-info);   color: #90CAF9; }

/* ===================== INVENTORY BARS ===================== */
.inv-bar-wrap {
  background: var(--ff-dark3);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
  margin-top: 4px;
  width: 120px;
  display: inline-block;
}

.inv-bar-fill {
  height: 100%;
  background: var(--ff-red);
  border-radius: 4px;
  transition: width .4s;
}

.inv-bar-fill.mid  { background: var(--ff-warning); }
.inv-bar-fill.high { background: var(--ff-success); }

/* ===================== LOADING ===================== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--ff-border);
  border-top-color: var(--ff-red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== BLINKING PIN ===================== */
@keyframes blink-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(1.4); }
}

.blink-marker { animation: blink-pulse 1.2s ease-in-out infinite; }

/* ===================== MAP PAGE ===================== */
#map { width: 100%; height: 100%; }

.map-layout {
  display: flex;
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  overflow: hidden;
}

.map-sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--ff-dark2);
  border-right: 1px solid var(--ff-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.map-sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--ff-border);
}

.map-sidebar-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--ff-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.map-container { flex: 1; position: relative; }

.locate-fab {
  display: none; /* shown only on mobile, where the sidebar's own button is hidden */
  position: absolute;
  bottom: 16px;
  left: 16px; /* right side is Google Maps' own zoom +/- controls — don't cover them */
  z-index: 15;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--ff-border);
  background: var(--ff-dark2);
  color: var(--ff-text);
  font-size: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.map-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 8px;
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.pin-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pin-btn {
  flex: 1 1 calc(50% - 6px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
  transition: var(--transition);
  color: #fff;
  touch-action: none; /* so pointerdown-drag isn't hijacked by page scroll */
}

.pin-btn:active { cursor: grabbing; }
.pin-btn.active { border-color: #fff; }

.pin-btn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  flex-shrink: 0;
}

.pin-btn-red    { background: #C62828; }
.pin-btn-green  { background: #2E7D32; }
.pin-btn-orange { background: #E65100; }
.pin-btn-black  { background: #424242; }
.pin-btn-purple { background: #6A1B9A; }

/* ===================== MY CUSTOMERS LIST ===================== */
.cust-list { display: flex; flex-direction: column; gap: 8px; }

.cust-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--ff-dark3);
  border: 1px solid var(--ff-border);
  border-radius: var(--radius);
}

.cust-main { flex: 1; min-width: 0; }
.cust-name { font-weight: 600; color: var(--ff-white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cust-town { font-weight: 400; color: var(--ff-text-muted); }
.cust-sub { font-size: 12px; color: var(--ff-text-muted); margin-top: 2px; }

.cust-card.deleted { border-style: dashed; opacity: 0.7; }
.cust-deleted-note { font-size: 12px; color: var(--ff-warning); margin-top: 2px; }

.cust-actions { display: flex; gap: 6px; flex-shrink: 0; }

.cust-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--ff-border);
  background: var(--ff-dark2);
  font-size: 17px;
  text-decoration: none;
  cursor: pointer;
}
.cust-act:hover { border-color: var(--ff-red); text-decoration: none; }
.cust-act.disabled { opacity: 0.25; cursor: not-allowed; filter: grayscale(1); }

@media (max-width: 480px) {
  .cust-card { flex-wrap: wrap; }
  .cust-actions { width: 100%; justify-content: space-between; }
  .cust-act { flex: 1; border-radius: var(--radius); }
}

.voice-wrap { position: relative; display: block; }

.voice-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--ff-border);
  background: var(--ff-dark3);
  color: var(--ff-text);
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}

/* Multi-line notes: keep the mic in the bottom corner, not mid-height */
.voice-wrap.is-textarea .voice-btn { top: auto; bottom: 8px; transform: none; }

.voice-btn.listening {
  background: var(--ff-red);
  border-color: var(--ff-red);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.drag-ghost {
  position: fixed;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 500;
}

.visit-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 320px;
  max-width: calc(100vw - 32px);
  overflow-y: auto;
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  z-index: 20;
}

/* ===================== LOGIN PAGE ===================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ff-black);
  background-image: radial-gradient(ellipse at 30% 20%, rgba(192,39,45,.15) 0%, transparent 60%);
}

.login-box {
  width: min(420px, 95vw);
  background: var(--ff-dark2);
  border: 1px solid var(--ff-border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo img { max-width: 160px; }
.login-logo p { color: var(--ff-text-muted); font-size: 13px; margin-top: 8px; }

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--ff-white);
  margin-bottom: 24px;
  text-align: center;
}

/* ===================== MOBILE NAV ===================== */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--ff-border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
}

.hamburger-btn span {
  display: block;
  width: 16px;
  height: 2px;
  margin: 0 auto;
  background: var(--ff-text);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .app-shell { position: relative; }

  .hamburger-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.open { display: block; }

  .main-area { width: 100%; }

  .topbar { padding: 0 16px; gap: 12px; }

  .content { padding: 16px; }

  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }

  /* Canvassing map: the sidebar becomes a bottom bar of just the pin-drop
     buttons (the reason a rep opens this page); Options/Recent Visits move
     out of the way, and the floating recentre button takes over from the
     one that lived in the now-hidden Options section. */
  .map-layout { flex-direction: column; }
  .map-sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
    border-right: none;
    border-top: 1px solid var(--ff-border);
    order: 2;
    flex-shrink: 0;
  }
  .map-container { order: 1; flex: 1; min-height: 0; }
  .map-sidebar-pins { padding: 8px; }
  .map-sidebar-pins h3, .pins-hint { display: none; }
  .pin-btn-row { flex-wrap: nowrap; gap: 4px; }
  /* Icon-only on phones — a colour dot with no label, so all 5 fit in one
     row without pushing the map down or needing a scroll. */
  .pin-btn {
    flex: 1 1 0;
    justify-content: center;
    padding: 10px 4px;
    min-width: 0;
  }
  .pin-btn-label { display: none; }
  .pin-btn-dot { width: 16px; height: 16px; }
  .map-sidebar-extra { display: none; }
  .locate-fab { display: flex; align-items: center; justify-content: center; }

  .visit-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 75vh;
    border-radius: 16px 16px 0 0;
  }
}
