/* --primary and --accent change with each business's config file.
   The rest are the shared brand colors. */
:root {
  --primary: #1B6E1B;
  --accent: #D6B588;
  --forest: #228B22;
  --tan: #D6B588;
  --brown: #705E46;
  --dark-brown: #422701;
  --gray: #C6C0B9;
  --mint: #CFFFDC;
  --sage: #68BA7F;
  --near-white: #FAFFFA;
  --white: #FFFFFF;
  --line: rgba(198, 192, 185, 0.6);
  --primary-soft: color-mix(in srgb, var(--primary) 10%, white);

  --radius: 14px;
  --shadow: 0 1px 3px rgba(66, 39, 1, 0.06), 0 6px 20px rgba(66, 39, 1, 0.06);
  --topbar-height: 64px;
  --sidebar-width: 220px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--near-white);
  color: var(--dark-brown);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

h1, h2, p { margin: 0; }

/* Make sure anything marked hidden stays hidden, even with display rules below. */
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--primary);
  color: var(--white);
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 30;
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 3px solid var(--sage);
  outline-offset: 2px;
}

select, button { font: inherit; color: inherit; }

select {
  min-height: 40px;
  padding: 6px 34px 6px 12px;
  border: 1px solid var(--gray);
  border-radius: 10px;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23705E46' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  appearance: none;
  cursor: pointer;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--topbar-height);
  padding: 10px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--primary);
}

.brand { flex: 1; min-width: 0; }

.business-name {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.powered-by {
  font-size: 0.82rem;
  color: var(--brown);
  text-decoration: none;
}
.powered-by:hover { text-decoration: underline; }

.viewing-as {
  display: flex;
  align-items: center;
  gap: 10px;
}
.viewing-as label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brown);
  white-space: nowrap;
}

.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  padding: 9px;
  border: 1px solid var(--gray);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
}
.menu-button svg, .page-nav svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 14px;
  background: var(--white);
  border-right: 1px solid var(--line);
}

.page-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--brown);
  font-weight: 600;
  text-decoration: none;
}
.page-nav a svg { width: 20px; height: 20px; flex: none; }
.page-nav a:hover { background: var(--near-white); color: var(--dark-brown); }
.page-nav a[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary);
}

.demo-note {
  font-size: 0.85rem;
  color: var(--brown);
  padding: 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 25%, white);
}

.menu-backdrop { display: none; }

.content {
  min-width: 0;
  padding: 24px 32px 48px;
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 24px;
  margin-bottom: 24px;
}

.filter { display: flex; flex-direction: column; gap: 6px; }
.filter label, .filter-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brown);
}

.range-buttons {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--gray);
  border-radius: 10px;
  background: var(--white);
  overflow: hidden;
}
.range-buttons button {
  min-height: 40px;
  padding: 6px 14px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  color: var(--brown);
}
.range-buttons button:last-child { border-right: 0; }
.range-buttons button:hover { background: var(--near-white); }
.range-buttons button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--white);
}

/* Page */
.page:focus { outline: none; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 18px;
}
.page-header h1 { font-size: 1.7rem; color: var(--dark-brown); }
.page-dates { color: var(--brown); font-weight: 600; }

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

.kpi {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 4px solid var(--accent);
  padding: 16px 18px;
}
.kpi-label { font-size: 0.88rem; font-weight: 600; color: var(--brown); }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--dark-brown); margin-top: 4px; }
.kpi-value.is-muted { font-size: 1.05rem; font-weight: 600; color: var(--brown); padding: 6px 0 5px; }
.kpi-value.is-loading { color: var(--gray); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) {
  .kpi-value.is-loading, .chart-empty.is-loading { animation: none; }
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.chart-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.chart-card.is-wide { grid-column: 1 / -1; }
.chart-title { font-size: 1.05rem; }
.chart-subtitle { font-size: 0.86rem; color: var(--brown); margin: 2px 0 12px; min-height: 1.3em; }
.chart-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chart-canvas { position: relative; height: 280px; }
.chart-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brown);
  min-height: 200px;
}
.chart-empty.is-loading { color: var(--gray); animation: pulse 1.2s ease-in-out infinite; }

.kpi-note { font-size: 0.8rem; color: var(--brown); margin-top: 2px; }

.table-scroll {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.data-table th, .data-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--primary-soft);
  color: var(--dark-brown);
  font-size: 0.82rem;
}
.data-table tbody th { font-weight: 600; }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table td:nth-child(n+2):nth-child(-n+5) { font-variant-numeric: tabular-nums; }

.chart-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 10px;
  background: var(--near-white);
  border: 2px dashed var(--line);
  color: var(--brown);
  padding: 24px;
  text-align: center;
}
.chart-placeholder svg { width: 120px; fill: color-mix(in srgb, var(--primary) 30%, white); }

.notice {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  color: var(--brown);
  margin-bottom: 20px;
}
.notice-error {
  border-left: 5px solid #B3261E;
  color: var(--dark-brown);
}
.notice-error p { margin-bottom: 12px; }
.retry {
  padding: 8px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--white);
  font-weight: 700;
  cursor: pointer;
}

/* Tablets and phones: the side menu slides in from the menu button. */
@media (max-width: 860px) {
  .menu-button { display: block; }
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    visibility: hidden;
  }
  .menu-open .sidebar { transform: none; visibility: visible; }
  .menu-open .menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(66, 39, 1, 0.3);
  }

  .content { padding: 20px 16px 40px; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px 12px; }
  .viewing-as { width: 100%; }
  .viewing-as select { flex: 1; }
  .kpi-row { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi-value { font-size: 1.3rem; }
  .filters { gap: 12px; }
  .filter { width: 100%; }
  .range-buttons { display: grid; grid-template-columns: repeat(4, 1fr); }
  .range-buttons button { padding: 6px 4px; }
  .page-header h1 { font-size: 1.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
