:root {
  --ford-blue: #003499;
  --ford-light: #0066cc;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #dde3ee;
  --text: #1a1a2e;
  --muted: #6b7280;
  --accent: #e8f0fe;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--ford-blue);
  color: #fff;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 64px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
header svg { flex-shrink: 0; }
header h1  { font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; }
header .subtitle { font-size: .8rem; opacity: .75; margin-top: 2px; }

/* ── Layout ── */
.page-wrap { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.5rem 3rem; }

/* ── Controls card ── */
.controls {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* Row 1 — year pills (full width) */
.ctrl-years { display: flex; flex-direction: column; gap: .4rem; width: 100%; }

.label-hint { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .7rem; color: #aab; margin-left: .3rem; }

.year-pills { display: flex; flex-wrap: wrap; gap: .45rem; }

.year-pill {
  padding: .35rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  background: #fff;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.year-pill:hover  { border-color: var(--ford-light); color: var(--ford-light); }
.year-pill.active { background: var(--ford-blue); border-color: var(--ford-blue); color: #fff; }

/* Row 2 — vehicle, month, search, view toggle */
.ctrl-row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.ctrl-group { display: flex; flex-direction: column; gap: .35rem; min-width: 150px; }
.ctrl-group label { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ctrl-group select,
.ctrl-group input[type=text] {
  padding: .42rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .88rem;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.ctrl-group select:focus,
.ctrl-group input:focus { border-color: var(--ford-light); }
.ctrl-search { min-width: 190px; }

/* View toggle */
.view-toggle { display: flex; gap: .45rem; margin-left: auto; align-self: flex-end; }
.view-toggle button {
  padding: .42rem .9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
  display: flex; align-items: center; gap: .35rem;
  transition: all .15s;
}
.view-toggle button.active { background: var(--ford-blue); color: #fff; border-color: var(--ford-blue); }

/* ── Summary Cards ── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card .card-label { font-size: .71rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .35rem; }
.card .card-value { font-size: 1.5rem; font-weight: 700; color: var(--ford-blue); }
.card .card-sub   { font-size: .77rem; color: var(--muted); margin-top: .25rem; }

/* ── Chart panel ── */
.chart-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chart-panel h2 { font-size: .95rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; }
.chart-wrap { position: relative; height: 340px; }
canvas { width: 100% !important; }

/* ── Table panel ── */
.table-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.table-panel h2 { font-size: .95rem; font-weight: 700; padding: 1rem 1.5rem .6rem; border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th {
  background: var(--accent);
  color: var(--ford-blue);
  font-weight: 700;
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .6rem 1rem;
  text-align: right;
  position: sticky; top: 0;
  white-space: nowrap;
}
th:first-child { text-align: left; }
td {
  padding: .52rem 1rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td:first-child { text-align: left; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--accent); }
.null-cell  { color: #c0c8d8; }
.total-row td { font-weight: 700; background: #f8faff; border-top: 2px solid var(--border); }


/* ── Badge ── */
.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 99px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: #dbeafe;
  color: #1e40af;
  margin-left: .5rem;
  vertical-align: middle;
}

/* ══════════════════════════════════════════════════════════════
   TAB BAR
   ══════════════════════════════════════════════════════════════ */
.tab-bar {
  display: flex;
  background: #fff;
  border-bottom: 2px solid var(--border);
  padding: 0 1.5rem;
  gap: .25rem;
}
.tab-btn {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .75rem 1.2rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -2px;          /* overlap the nav border-bottom */
  transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--ford-blue); }
.tab-btn.active { color: var(--ford-blue); border-bottom-color: var(--ford-blue); }

/* ── Tab content visibility ── */
.tab-content         { display: none; }
.tab-content.active  { display: block; }

/* ══════════════════════════════════════════════════════════════
   PLANT MAP LAYOUT
   ══════════════════════════════════════════════════════════════ */
#tab-plantmap { height: calc(100vh - 112px); } /* viewport minus header + tab-bar */

.map-layout {
  display: flex;
  height: 100%;
}

/* Leaflet map */
#plant-map {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  z-index: 0;
}

/* ── Plant panel (right sidebar) ── */
.plant-panel {
  width: 340px;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.plant-panel-header {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}
.plant-panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.plant-panel-header h2 { font-size: 1rem; font-weight: 700; color: var(--text); }
.plant-panel-sub { font-size: .75rem; color: var(--muted); margin-top: .2rem; }

.reset-map-btn {
  flex-shrink: 0;
  padding: .28rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.reset-map-btn:hover { border-color: var(--ford-light); color: var(--ford-light); }

.plant-panel-loading {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

/* ── Legend ── */
.map-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.legend-item { display: flex; align-items: center; gap: .35rem; font-size: .73rem; font-weight: 600; color: var(--muted); }
.legend-dot  { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ── Plant list ── */
.plant-list { padding: .75rem .75rem 1.5rem; display: flex; flex-direction: column; gap: .5rem; }

/* ── Plant card ── */
.plant-card {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: .75rem 1rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
  background: #fff;
}
.plant-card:hover  { border-color: var(--ford-light); box-shadow: 0 2px 8px rgba(0,52,153,.1); }
.plant-card.active { border-color: var(--ford-blue); background: var(--accent); box-shadow: 0 2px 12px rgba(0,52,153,.18); }

.plant-card-top {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  margin-bottom: .55rem;
}
.plant-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}
.plant-dot.americas { background: var(--ford-blue); }
.plant-dot.europe   { background: #c8102e; }
.plant-dot.asia     { background: #27ae60; }
.plant-dot.africa   { background: #e67e22; }

.plant-card-info { flex: 1; min-width: 0; }
.plant-name { font-size: .86rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.plant-city { font-size: .74rem; color: var(--muted); margin-top: .1rem; }

.country-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: .15rem .5rem;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}
.country-badge.americas { background: #dbeafe; color: #1e40af; }
.country-badge.europe   { background: #fee2e2; color: #991b1b; }
.country-badge.asia     { background: #dcfce7; color: #166534; }
.country-badge.africa   { background: #fef3c7; color: #92400e; }

/* ── Vehicle list inside card ── */
.vehicle-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.vehicle-tag {
  font-size: .75rem;
  padding: .2rem .55rem;
  background: #f1f5fd;
  border: 1px solid #c7d7f5;
  border-radius: 6px;
  color: var(--ford-blue);
  font-weight: 600;
  white-space: nowrap;
}
.plant-card.active .vehicle-tag { background: #dbeafe; border-color: #93c5fd; }

/* ── Custom Leaflet marker ── */
.map-marker-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  transition: transform .15s;
  cursor: pointer;
}
.map-marker.americas { background: var(--ford-blue); }
.map-marker.europe   { background: #c8102e; }
.map-marker.asia     { background: #27ae60; }
.map-marker.africa   { background: #e67e22; }
.map-marker.active {
  width: 20px; height: 20px;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--ford-blue), 0 2px 8px rgba(0,0,0,.4);
}

/* Leaflet popup tweak */
.leaflet-popup-content-wrapper { border-radius: 8px; font-family: inherit; font-size: .84rem; }
.leaflet-popup-content { margin: .6rem .9rem; }
.popup-plant-name { font-weight: 700; color: var(--ford-blue); margin-bottom: .25rem; }
.popup-city { font-size: .75rem; color: var(--muted); margin-bottom: .4rem; }
.popup-vehicles { font-size: .78rem; line-height: 1.7; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 750px) {
  header { padding: 0 1rem; }
  .tab-bar { padding: 0 .5rem; }
  .page-wrap { padding: 1rem .75rem 2rem; }
  .controls { padding: .9rem 1rem; }
  .view-toggle { margin-left: 0; }
  .chart-wrap { height: 240px; }

  #tab-plantmap { height: auto; }
  .map-layout   { flex-direction: column; }
  #plant-map    { height: 50vh; }
  .plant-panel  { width: 100%; height: auto; border-left: none; border-top: 1px solid var(--border); }
}
