:root {
  --blue: #1a56db;
  --blue-dark: #123a94;
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e1e4e8;
  --text: #1f2430;
  --muted: #6b7280;
  --danger: #d92d20;
  --green: #067647;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

.wrap.wide {
  max-width: 980px;
}

.login-wrap {
  max-width: 380px;
  margin: 72px auto 0;
  text-align: center;
}
.login-logo {
  width: 84px;
  height: 84px;
  margin-bottom: 18px;
}

.header-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title-row h1 { margin: 0; }
.header-logo {
  width: 34px;
  height: 34px;
  border-radius: 6px;
}

.mission-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--blue);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}
.mission-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
  opacity: 0.85;
}
.mission-pill {
  background: rgba(255, 255, 255, 0.18);
  padding: 3px 12px;
  border-radius: 20px;
  font-weight: 600;
}
.mission-statement-label {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0;
}
.mission-statement {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--blue);
  max-width: 640px;
  margin: 2px auto 16px;
}

.two-col {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.two-col > .card {
  flex: 1;
  min-width: 280px;
}

h1 {
  font-size: 1.35rem;
  margin: 4px 0 2px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.field { margin-bottom: 14px; }

.row-grid {
  display: grid;
  grid-template-columns: 1fr 90px 32px;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

button {
  cursor: pointer;
  font-size: 0.95rem;
  border-radius: 8px;
  border: none;
  padding: 11px 16px;
  font-weight: 600;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #9ab3ea; cursor: default; }

.btn-secondary {
  background: #eef1f6;
  color: var(--text);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f3b0a8;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.btn-remove {
  background: #fff;
  color: var(--danger);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 42px;
}

.btn-link {
  background: none;
  color: var(--blue);
  padding: 8px 0;
  font-weight: 600;
}

.entry-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.entry-list-item:last-child { border-bottom: none; }

.store-checkbox-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  max-height: 140px;
  overflow-y: auto;
  padding: 6px 10px;
}
.store-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
  cursor: pointer;
}
.store-checkbox-row input { width: auto; }

.entry-main { font-size: 0.95rem; }
.entry-sub { font-size: 0.8rem; color: var(--muted); }

.total-line {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  padding-top: 10px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 50;
}
.toast.error { background: var(--danger); }

.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 6px; }

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.logout-link {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  font-weight: 500;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}
.filters .field { margin-bottom: 0; min-width: 150px; flex: 1; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.stat .label { font-size: 0.78rem; color: var(--muted); }
.stat .value { font-size: 1.3rem; font-weight: 700; margin-top: 2px; }

/* Per-store breakdown on hover, for splash KPI cards that roll up more than
   one store (OM/Director/Admin/SUPER_ADMIN) -- meaningless and unused for a
   single-store Manager. z-index 20 sits below .toast (50) and
   .modal-backdrop (100), the only two existing overlay tiers on this page. */
.stat-hoverable { position: relative; cursor: help; }
.stat-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 8px 10px;
  min-width: 200px;
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.1s;
}
.stat-hoverable:hover .stat-tooltip { opacity: 1; visibility: visible; }
.stat-tooltip-row { display: flex; justify-content: space-between; gap: 12px; font-size: 0.82rem; padding: 2px 0; white-space: nowrap; }

/* Hover-to-preview a photo (Check Request) without navigating away --
   the <img> only fetches its data-src on first hover (see the JS that
   wires .photo-hover), so rows with a photo never force-load it just by
   being rendered in a table. */
.photo-hover { position: relative; display: inline-block; }
.photo-hover-preview {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 6px;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.1s;
  background: var(--card);
}
.photo-hover:hover .photo-hover-preview { opacity: 1; visibility: visible; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  background: #eef1f6;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
}
.tab-btn.active { background: var(--blue); color: #fff; }

.pct-good { color: var(--green); font-weight: 600; }
.pct-bad { color: var(--danger); font-weight: 600; }
.pct-neutral { color: var(--muted); }

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 10px;
}

.trend-wrap { overflow-x: auto; }
.trend-wrap svg { display: block; }
.bar-chart-wrap { overflow-x: auto; }
.bar-chart-wrap svg { display: block; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--blue); }
th.sortable .sort-arrow { margin-left: 3px; opacity: 0.6; }
.rank-cell { color: var(--muted); font-weight: 600; width: 1%; white-space: nowrap; }

#nav-links {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 640px) {
  #nav-links { grid-template-columns: 1fr; }
}
.nav-link {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}
.nav-link:hover { border-color: var(--blue); }
.nav-link .nav-title { font-weight: 700; font-size: 0.95rem; }
.nav-link .nav-desc { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.nav-department-heading {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 14px 0 -2px;
}
.nav-department-heading:first-child { margin-top: 0; }

.store-pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.store-pill-link {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px; /* touch-target friendly on iPad/mobile, not just desktop */
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
}
.store-pill-link:hover { border-color: var(--blue); color: var(--blue); background: #f2f6ff; }

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.small-note { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

/* Floating AI Assistant chat widget -- injected by ai-chat-widget.js on
   every page, fixed bottom-right so it's always reachable without a nav click. */
#ai-chat-widget { position: fixed; right: 20px; bottom: 20px; z-index: 500; }
#ai-chat-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#ai-chat-bubble:hover { background: var(--blue-dark); }
#ai-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 88px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100vh - 120px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}
#ai-chat-close { background: none; border: none; color: #fff; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 2px; }
#ai-chat-not-configured { padding: 10px 14px; font-size: 0.8rem; color: var(--muted); }
#ai-chat-window { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; line-height: 1.4; white-space: pre-wrap; font-size: 0.86rem; }
.ai-chat-msg.user { align-self: flex-end; background: var(--blue); color: #fff; }
.ai-chat-msg.assistant { align-self: flex-start; background: #f2f4f7; }
.ai-chat-msg.error { align-self: flex-start; background: #fef2f2; color: var(--danger); }
#ai-chat-suggestions { padding: 0 12px; }
.ai-chat-chip { display: inline-block; background: #f2f4f7; border-radius: 16px; padding: 4px 10px; font-size: 0.76rem; margin: 0 6px 6px 0; cursor: pointer; }
#ai-chat-input-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
#ai-chat-input-row textarea { flex: 1; resize: none; min-height: 38px; max-height: 90px; font-family: inherit; font-size: 0.85rem; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
#ai-chat-input-row button { background: var(--blue); color: #fff; border: none; border-radius: 8px; padding: 0 14px; font-weight: 600; cursor: pointer; }
#ai-chat-input-row button:disabled { opacity: 0.5; cursor: default; }
@media (max-width: 480px) {
  #ai-chat-panel { right: 8px; left: 8px; width: auto; bottom: 80px; }
  #ai-chat-widget { right: 12px; bottom: 12px; }
}
