/* ========== Variables ========== */
:root {
  --blue-primary: #003087;
  --blue-accent: #009CDE;
  --blue-light: #e8f4fb;
  --bg: #F8F9FC;
  --surface: #ffffff;
  --border: #e2e6ea;
  --border-strong: #c8cdd4;
  --text-primary: #1a2332;
  --text-secondary: #5a6472;
  --text-muted: #9ba3af;
  --green: #22c55e;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --orange: #f59e0b;
  --orange-bg: #fef3c7;
  --orange-text: #92400e;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --header-height: 60px;
  --tabs-height: 52px;
  --font: 'Inter', system-ui, sans-serif;
}

/* ========== Reset ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ========== Header ========== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--blue-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow-md);
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.logo { display: flex; align-items: center; gap: 12px; }
.logo-mw-block {
  width: 52px; height: 40px;
  background: #0033A0;
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 4px 6px;
  flex-shrink: 0;
}
.logo-mw-mars {
  font-size: 13px; font-weight: 800; color: #fff;
  letter-spacing: 1.5px; line-height: 1;
}
.logo-mw-wrigley {
  font-size: 8px; font-weight: 800; color: #fff;
  letter-spacing: 0.5px; line-height: 1;
}
.logo-text { display: flex; flex-direction: column; }
.logo-title { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.2; }
.logo-sub { font-size: 11px; color: rgba(255,255,255,0.65); }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; font-family: var(--font);
  cursor: pointer; border: none; transition: all 0.15s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:active { transform: scale(0.97); }

.btn-sync {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}
.btn-sync:hover { background: rgba(255,255,255,0.25); }
.btn-sync.syncing svg { animation: spin 1s linear infinite; }

.btn-export {
  background: var(--blue-accent);
  color: #fff;
}
.btn-export:hover { background: #007ab8; }

.btn-icon {
  width: 34px; height: 34px; padding: 0;
  background: rgba(255,255,255,0.12);
  color: #fff; border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,0.22); }
.btn-icon svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--blue-primary); color: #fff;
  width: 100%; justify-content: center; padding: 10px;
}
.btn-primary:hover { background: #00235e; }

.btn-danger {
  background: var(--red-bg); color: var(--red-text);
  border: 1px solid #fca5a5; width: 100%;
  justify-content: center; margin-top: 8px;
}
.btn-danger:hover { background: #fecaca; }

.btn-toggle-pw {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 12px; color: var(--text-secondary);
  cursor: pointer; padding: 2px 6px; font-family: var(--font);
}
.btn-toggle-pw:hover { color: var(--blue-primary); }

/* ========== Sync area ========== */
.sync-area { display: flex; align-items: center; gap: 8px; }
.sync-timestamp { font-size: 11px; color: rgba(255,255,255,0.55); }

/* ========== Tabs ========== */
.tabs-nav {
  height: var(--tabs-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: stretch;
  padding: 0 24px; gap: 0;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.tabs-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
  font-size: 14px; font-weight: 500; font-family: var(--font);
  color: var(--text-secondary);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--blue-primary); }
.tab-btn.active {
  color: var(--blue-primary);
  border-bottom-color: var(--blue-primary);
  font-weight: 600;
}
.tab-flag { font-size: 18px; line-height: 1; }
.tab-badge {
  min-width: 20px; height: 20px;
  background: var(--green-bg); color: var(--green-text);
  border-radius: 10px; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.tab-btn.active .tab-badge { background: var(--blue-light); color: var(--blue-primary); }

/* ========== Main content ========== */
.main-content {
  padding: 20px 24px;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ========== Summary section ========== */
.summary-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-sub { font-size: 12px; color: var(--text-muted); }

.stat-card.green { border-left: 3px solid var(--green); }
.stat-card.orange { border-left: 3px solid var(--orange); }
.stat-card.blue { border-left: 3px solid var(--blue-accent); }
.stat-card.primary { border-left: 3px solid var(--blue-primary); }
.stat-card.status-orange { border-left: 3px solid var(--orange); background: var(--orange-bg); }
.stat-card.status-green  { border-left: 3px solid var(--green);  background: var(--green-bg);  }

/* ========== Progress bars ========== */
.job-progress-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  grid-column: 1 / -1;
  box-shadow: var(--shadow-sm);
}
.job-progress-title { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.progress-row {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 8px;
}
.progress-row:last-child { margin-bottom: 0; }
.progress-job-name { font-size: 13px; font-weight: 500; color: var(--text-primary); min-width: 180px; flex-shrink: 0; }
.progress-bar-wrap {
  flex: 1; height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-bar-fill.done { background: var(--green); }
.progress-bar-fill.in-progress { background: var(--blue-accent); }
.progress-bar-fill.behind { background: var(--red); }
.progress-bar-fill.not-started { background: var(--border-strong); }
.progress-pct { font-size: 12px; font-weight: 600; color: var(--text-secondary); min-width: 36px; text-align: right; }
.progress-status-badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px;
  min-width: 80px; text-align: center;
}
.progress-status-badge.done { background: var(--green-bg); color: var(--green-text); }
.progress-status-badge.in-progress { background: var(--orange-bg); color: var(--orange-text); }
.progress-status-badge.behind { background: var(--red-bg); color: var(--red-text); }
.progress-status-badge.not-started { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ========== Table ========== */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 200px;
  position: relative;
}

.tracker-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}

/* Sticky first column */
.tracker-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 2px solid var(--border-strong);
}

.tracker-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f1f3f7;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
/* Top-left corner cell: sticky both axes */
.tracker-table th:first-child {
  left: 0;
  z-index: 5;
  border-right: 2px solid var(--border-strong);
}

.tracker-table td {
  padding: 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  height: 44px;
}
.tracker-table tbody tr:hover td { background: #fafbfc; }
.tracker-table tbody tr:hover td:first-child { background: #f5f7fa; }

/* Job name cell */
.cell-job-name {
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 16px;
  font-size: 13px;
  white-space: nowrap;
  min-width: 180px;
  display: flex; align-items: center; height: 44px;
}

/* Generic editable cell */
.cell-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 10px;
  cursor: pointer;
  transition: background 0.1s;
}
.cell-inner:hover { background: rgba(0,144,222,0.06); }

/* Y/N toggle */
.yn-cell {
  width: 80px; min-width: 80px; max-width: 80px;
}
.yn-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px; cursor: pointer;
  transition: background 0.1s;
}
.yn-inner:hover { background: rgba(0,144,222,0.06); }

.yn-badge {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  transition: all 0.15s;
}
.yn-badge.yes { background: var(--green-bg); color: var(--green); }
.yn-badge.no { background: var(--red-bg); color: var(--red); }
.yn-badge.empty { background: var(--border); color: var(--text-muted); }

/* Date cell */
.date-cell { min-width: 130px; }
.date-input-styled {
  width: 100%; height: 44px;
  border: none; background: transparent;
  font-size: 12px; font-family: var(--font);
  color: var(--text-primary); cursor: pointer;
  padding: 0 10px; text-align: center;
}
.date-input-styled:focus {
  outline: none;
  background: var(--blue-light);
}
.date-input-styled::-webkit-calendar-picker-indicator {
  opacity: 0.4; cursor: pointer;
  padding: 0;
}
.date-input-styled:hover::-webkit-calendar-picker-indicator { opacity: 0.8; }

/* Number input cell */
.num-cell { min-width: 90px; }
.num-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px;
}
.num-input {
  width: 100%; height: 100%;
  border: none; background: transparent;
  text-align: center; font-size: 13px; font-family: var(--font);
  color: var(--text-primary); cursor: text;
  padding: 0 10px;
}
.num-input:focus {
  outline: none;
  background: var(--blue-light);
}
.num-input::placeholder { color: var(--text-muted); }

/* Text input cell */
.text-cell { min-width: 120px; }
.text-input {
  width: 100%; height: 44px;
  border: none; background: transparent;
  font-size: 13px; font-family: var(--font);
  color: var(--text-primary); cursor: text;
  padding: 0 12px;
}
.text-input:focus {
  outline: none;
  background: var(--blue-light);
}
.text-input::placeholder { color: var(--text-muted); }

/* Auto/computed cell */
.auto-cell { min-width: 110px; }
.auto-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 10px;
  font-size: 12px; color: var(--text-secondary);
}

/* Status visits cell */
.status-cell { min-width: 100px; }
.status-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 8px;
}
.status-badge {
  padding: 3px 10px; border-radius: 10px;
  font-size: 12px; font-weight: 600;
}
.status-badge.done { background: var(--green-bg); color: var(--green-text); }
.status-badge.in-progress { background: var(--orange-bg); color: var(--orange-text); }
.status-badge.behind { background: var(--red-bg); color: var(--red-text); }
.status-badge.empty { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ========== Settings panel ========== */
.settings-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.settings-overlay.visible { opacity: 1; pointer-events: all; }

.settings-panel {
  position: fixed; top: 0; right: 0;
  width: 380px; height: 100vh;
  background: var(--surface);
  z-index: 201;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex; flex-direction: column;
}
.settings-panel.open { transform: translateX(0); }

.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 { font-size: 16px; font-weight: 700; color: var(--blue-primary); }
.settings-header .btn-icon {
  background: var(--bg); color: var(--text-secondary);
  border-color: var(--border);
}
.settings-header .btn-icon:hover { color: var(--red); border-color: var(--red); }

.settings-body { padding: 24px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.settings-divider { height: 1px; background: var(--border); margin: 4px 0; }

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.form-input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: var(--font); color: var(--text-primary);
  background: var(--bg); transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--blue-accent); background: #fff; }
.input-with-toggle { position: relative; }
.input-with-toggle .form-input { padding-right: 52px; }
.form-hint { font-size: 12px; color: var(--text-muted); }
.form-hint code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-family: monospace; }

/* ========== Toast ========== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text-primary); color: #fff;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 8px;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  pointer-events: all;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--orange); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ========== Animations ========== */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ========== Responsive ========== */
@media (max-width: 1200px) {
  .summary-section { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .summary-section { grid-template-columns: 1fr; }
  .header { padding: 0 16px; }
  .main-content { padding: 16px; }
  .logo-sub { display: none; }
  .settings-panel { width: 100%; }
}

/* ========== Filter bar ========== */
.filter-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}

.brand-filter-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Multi-select dropdown */
.multi-select-dd {
  position: relative;
}

.multi-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.multi-select-btn:hover { border-color: var(--blue-accent); }
.multi-select-btn:focus { outline: none; border-color: var(--blue-accent); box-shadow: 0 0 0 2px rgba(0,156,222,.15); }
.dd-arrow { font-size: 10px; color: var(--text-muted); }

.multi-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px 0;
  min-width: 180px;
}
.multi-select-menu.open { display: block; }

.dd-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.1s;
}
.dd-option:hover { background: var(--blue-light); }
.dd-option input[type="checkbox"] { accent-color: var(--blue-accent); width: 14px; height: 14px; }

/* ========== MW/KN select cell ========== */
.mwkn-cell { min-width: 90px; }
.mwkn-select {
  width: 100%; height: 44px;
  border: none; background: transparent;
  font-size: 13px; font-family: var(--font); font-weight: 500;
  color: var(--text-primary); cursor: pointer;
  padding: 0 8px; text-align: center;
  appearance: none; -webkit-appearance: none;
}
.mwkn-select:focus { outline: none; background: var(--blue-light); }
.mwkn-select option { font-family: var(--font); }

/* ========== Date-badge cells (Visits Completed, Report Delivered) ========== */
.date-badge-cell { transition: background 0.15s; }
.date-badge-cell.date-badge-filled { background: var(--green-bg); }
.date-badge-cell.date-badge-filled .date-input-styled {
  background: transparent;
  color: var(--green-text);
  font-weight: 600;
}

/* ========== Empty state ========== */
.empty-state-cell {
  padding: 48px 24px !important;
  text-align: center;
}
.empty-state-inner {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.7;
}
.empty-state-inner strong { color: var(--text-secondary); }

.no-jobs-hint {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}
.no-jobs-hint strong { color: var(--text-secondary); }
