/* Shared stylesheet for every page */

:root {
  --bg: #f4f5f0;
  --bar: #ffffff;
  --panel: #ffffff;
  --panel-pressed: #eaffeb;
  --panel-text: #0b1136;
  --muted: #5d6480;
  --line: #dfe2d8;
  /* Too bright to read as text on white: use for lines and fills only. */
  --accent: #00ff0f;
  /* Fill and edge of a panel whose form is done. */
  --done: #b4f5b8;
  --done-line: #00c20c;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  /* dvh keeps the grid clear of the mobile browser's address bar */
  min-height: 100dvh;
  background: var(--bg);
  color: var(--panel-text);
  /* Century Gothic isn't on phones, so the next names are its closest stand-ins. */
  font-family: "Century Gothic", CenturyGothic, "URW Gothic", "Avant Garde", "Futura", "Trebuchet MS", system-ui, sans-serif;
}

.top-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  background: var(--bar);
  border-bottom: 3px solid var(--accent);
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}

.top-bar h1 {
  margin: 0;
  font-size: 1.25rem;
}

/* Small button on the right of the top bar, e.g. "Back to PIN". */
.top-bar-link {
  padding: 6px 12px;
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--accent);
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.top-bar-link:active {
  transform: scale(0.97);
  background: var(--panel-pressed);
}

.top-bar-link:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Store picker page: greeting and dropdown centred on the screen. */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.welcome-text {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.4;
}

.store-select {
  width: 100%;
  max-width: 360px;
  padding: 16px 44px 16px 16px;
  /* Drop the native arrow and draw our own so it looks the same on every phone. */
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%230b1136' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 16px center / 12px 8px;
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  font-family: inherit;
  /* Below 16px, iPhones zoom the page when the dropdown is tapped. */
  font-size: 1.1rem;
  font-weight: 600;
}

/* Greyed out until a region is chosen. */
.store-select:disabled {
  background-color: var(--line);
  color: var(--muted);
  border-bottom-color: var(--line);
}

/* Store picker: one logo button per region, side by side. */
.region-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: var(--gap);
  width: 100%;
  max-width: 420px;
}

.region-button {
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: opacity 0.2s;
}

.region-button img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
}

.region-button:active {
  transform: scale(0.97);
}

/* The chosen region: green like a finished form. Once one is chosen, the
   others fade back. */
.region-button[aria-pressed="true"] {
  background: var(--done);
  border-color: var(--done-line);
}

.region-buttons.chosen .region-button[aria-pressed="false"] {
  opacity: 0.45;
}

.region-button:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Master overview's region switcher: full width at the top of the page. */
.region-switch {
  max-width: none;
}

/* Login page: one dot per PIN digit, filled in as they're typed. */
.pin-dots {
  display: flex;
  gap: 16px;
}

.dot {
  width: 18px;
  height: 18px;
  border: 2px solid var(--panel-text);
  border-radius: 50%;
}

.dot.filled {
  background: var(--panel-text);
}

.login-error {
  /* Keeps its line even when empty, so the keypad doesn't jump. */
  min-height: 1.4em;
  margin: 0;
  color: #b3261e;
  font-size: 0.95rem;
  font-weight: 600;
}

/* Wrong PIN: the whole login screen shakes side to side. */
.wobble {
  animation: wobble 0.4s ease-in-out;
}

@keyframes wobble {
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  .wobble {
    animation: none;
  }
}

/* Login page keypad: 3 across, keys dressed like the panels. */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
  max-width: 320px;
}

.num {
  padding: 16px 0;
  background: var(--panel);
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  /* Stops a fast double tap zooming the page instead of typing two digits. */
  touch-action: manipulation;
}

.num:active {
  transform: scale(0.96);
  background: var(--panel-pressed);
}

/* Clear and delete: quieter than the digit keys. */
.num-action {
  color: var(--muted);
  border-bottom-color: var(--line);
}

.submit-button {
  width: 100%;
  max-width: 360px;
  padding: 16px;
  background: var(--accent);
  color: var(--panel-text);
  border: 0;
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.submit-button:active {
  transform: scale(0.98);
}

/* Greyed out until a store is chosen. */
.submit-button:disabled {
  background: var(--line);
  color: var(--muted);
}

.submit-button:focus-visible,
.num:focus-visible,
.store-select:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Anything marked hidden in the HTML stays out of sight, whatever its other styles. */
[hidden] {
  display: none !important;
}

/* Wiki banner: full width across the top of the homepage, above the panels. */
.wiki-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  /* No gap underneath: the panel grid's own top padding spaces it. */
  margin: var(--gap) var(--gap) 0;
  padding: 12px;
  background: var(--panel);
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  font-size: 1.05rem;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.wiki-banner:active {
  transform: scale(0.98);
  background: var(--panel-pressed);
}

.wiki-banner:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Always 2 across, filling whatever screen is left. Rows share the height
   equally, so the grid is 2x2 with four panels and one tall row with two. */
.panel-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom));
}

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 12px;
  background: var(--panel);
  color: var(--panel-text);
  border-radius: 14px;
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
  text-align: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.panel-title {
  font-size: 1.2rem;
  font-weight: 600;
}

/* Splits one grid cell into equal boxes, top to bottom. */
.panel-stack {
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
  gap: var(--gap);
  min-height: 0;
}

/* The targets column: targets take two thirds, the button under them one. */
.panel-stack-data {
  grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
}

.panel-stack .panel {
  padding: 4px 12px;
}

.panel-stack .panel-data {
  padding: 12px;
}

.panel-stack .panel-title {
  font-size: 1.05rem;
}

/* Green: a form that has already been sent today. */
.panel-done,
a.panel-done:active {
  background: var(--done);
  border-color: var(--done-line);
}

/* The "Completed by ... at ..." line under a done panel's title. */
.panel-note {
  margin-top: 2px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Greyed out: a panel that isn't switched on yet. */
.panel-disabled {
  background: var(--line);
  color: var(--muted);
  border-bottom-color: var(--muted);
  box-shadow: none;
}

a.panel:active {
  transform: scale(0.98);
  background: var(--panel-pressed);
}

a.panel:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Data panel: title pinned to the top, figures scroll underneath if they overflow. */
.panel-data {
  justify-content: flex-start;
}

.panel-data .panel-title {
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* "safe" stops the top rows being cut off when there are too many to fit */
  justify-content: safe center;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
}

/* One figure from the sheet, as a tile: small heading above a big number.
   The tiles share the panel's height equally. */
.target-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 0;
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--bg);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  text-align: left;
  animation: target-in 0.35s ease-out both;
}

/* Tiles arrive one after another. */
.target-row:nth-child(2) { animation-delay: 0.06s; }
.target-row:nth-child(3) { animation-delay: 0.12s; }
.target-row:nth-child(n + 4) { animation-delay: 0.18s; }

@keyframes target-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .target-row {
    animation: none;
  }
}

.target-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.target-value {
  /* Scales with the screen so "£1,071.03" still fits on a narrow phone. */
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The first figure is the headline one: green-tinted and a size up. */
.target-row:first-child {
  background: var(--panel-pressed);
}

.target-row:first-child .target-value {
  font-size: clamp(1.25rem, 6vw, 1.8rem);
}

.panel-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Notice banner: full width along the bottom, under the panels. As tall as
   its message needs, up to a third of the screen; longer messages scroll.
   On a short screen it gives way first, so the panels above stay readable. */
.notice {
  flex: 0 1 auto;
  min-height: 64px;
  max-height: 33dvh;
  overflow-y: auto;
  /* The panels above already leave room for the phone's bottom edge;
     pull the banner up into that room and leave it underneath instead. */
  margin: calc(-1 * env(safe-area-inset-bottom)) var(--gap) calc(var(--gap) + env(safe-area-inset-bottom));
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
}

.notice-title {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.notice-text {
  margin: 2px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  /* Keeps line breaks typed into the sheet's cell, and breaks very long words. */
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* Master overview: every store in the region, in tables down the page. */
.master {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom));
}

.master-section {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
}

.master-heading {
  display: inline-block;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  font-size: 1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* "Open 7 of 8 · Cleaning 2 of 8" under the forms heading. */
.master-count {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.master-count:empty {
  display: none;
}

.master-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.master-table th {
  padding: 6px;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.master-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  vertical-align: top;
}

.master-table tr:last-child td {
  border-bottom: 0;
}

/* Money columns line up on the right. */
.master-table .money {
  text-align: right;
  white-space: nowrap;
}

/* A form that's been sent: green, with the time underneath when there is one. */
.master-table .cell-done {
  background: var(--done);
}

.cell-time {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.master-table .cell-missing {
  color: var(--muted);
  font-weight: 400;
}

.master-links {
  display: flex;
  /* Three buttons don't fit across a narrow phone: let the last drop down. */
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
}

.master-link {
  padding: 12px 18px;
  background: var(--panel);
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.master-link:active {
  transform: scale(0.98);
  background: var(--panel-pressed);
}

.master-link:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

/* Tracker page: the sheet's tables as pictures, with Share and Download under each. */
.tracker-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* The page is wider than the store picker's button was built for. */
.tracker-share-all {
  max-width: none;
}

/* Shown at its true size, shrinking to fit on a narrow phone. */
.tracker-image {
  display: block;
  max-width: 100%;
  height: auto;
}

.tracker-buttons {
  display: flex;
  gap: var(--gap);
  margin-top: 10px;
}

.tracker-button {
  flex: 1;
  padding: 12px;
  background: var(--panel);
  color: var(--panel-text);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

/* Share is the main one: filled green like the Submit button. */
.tracker-button-share {
  background: var(--accent);
  border-color: var(--accent);
}

.tracker-button:active {
  transform: scale(0.98);
}

.tracker-button:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}

.tracker-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* Where tracker.js builds each table before taking its picture: laid out
   as normal so it can be measured, but parked off the side of the screen. */
.tracker-stage {
  position: absolute;
  top: 0;
  left: -9999px;
}

/* The tables themselves, dressed like the tracker sheet. The pictures copy
   whatever is set here, so this is the place to change a colour or a size.
   The black behind the table shows through the 1px gaps as the grid lines. */
.sheet-table {
  width: max-content;
  border-collapse: separate;
  border-spacing: 1px;
  background: #000000;
  color: #000000;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.sheet-table th,
.sheet-table td {
  min-width: 100px;
  padding: 4px 12px;
  font-weight: inherit;
  text-align: inherit;
}

/* Progress table (Target, Achieved, Left, Day, %target):
   bright green headings, stores in pale blue, rows taking turns in yellow and blue. */
.sheet-progress .sheet-head {
  background: #00ff00;
}

.sheet-progress td {
  background: #ffe599;
}

.sheet-progress .sheet-alt td {
  background: #a4c2f4;
}

.sheet-progress td.sheet-store {
  background: #c9daf8;
}

/* %target: green once the store has reached it, red until then. */
.sheet-progress td.sheet-good {
  background: #b7e1cd;
}

.sheet-progress td.sheet-bad {
  background: #ea9999;
}

/* Targets table (Daily, Own Brand, SPD):
   blue title, headings and stores, yellow figures. */
.sheet-targets th,
.sheet-targets td.sheet-store {
  background: #9fc5e8;
}

.sheet-targets td {
  background: #ffe599;
}

.sheet-targets .sheet-title {
  padding: 2px 12px;
  font-size: 28px;
  text-decoration: underline;
}

/* Form pages: the embedded form fills 90% of the screen, centred. */
.form-frame {
  width: 90vw;
  height: 90dvh;
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(11, 17, 54, 0.08);
}

/* Wiki page: the wiki fills the whole screen. It has its own top bar, which
   leaves room on the left for the back button. */
.wiki-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

/* Floats over the top-left corner of the form. */
.back-button {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  z-index: 1;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

/* The icon already has its own circle, so the button adds no border or fill. */
.back-button img {
  display: block;
  width: 100%;
  height: 100%;
}

.back-button:active {
  transform: scale(0.95);
}

.back-button:focus-visible {
  outline: 3px solid var(--panel-text);
  outline-offset: 2px;
}
