:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #eef5ed;
  --text: #172017;
  --muted: #66706a;
  --line: #d9e0d8;
  --brand: #166534;
  --brand-2: #0f766e;
  --warn: #b45309;
  --danger: #b91c1c;
  --soft: #f3f7f1;
  --shadow: 0 6px 18px rgba(22, 40, 26, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body:has(.login-screen:not(.hidden)) {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: linear-gradient(180deg, #f0f7ef 0, var(--bg) 170px);
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}

.app-shell.locked {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, #eef7ee 0, #f7f8f5 100%);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  width: 164px;
  min-height: 68px;
  margin-bottom: 2px;
}

.login-brand img {
  display: block;
  width: 100%;
  height: auto;
}

.login-card h1 {
  margin-bottom: 4px;
}

.language-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.login-language {
  justify-self: end;
  margin-bottom: -4px;
}

.language-select {
  width: auto;
  min-width: 76px;
  min-height: 40px;
  padding: 8px 28px 8px 10px;
  border-radius: 7px;
  background-color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.header-language {
  min-width: 72px;
  max-width: 90px;
}

.hint-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(247, 250, 246, 0.94);
  border-bottom: 1px solid rgba(217, 224, 216, 0.75);
  backdrop-filter: blur(14px);
}

.topbar-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.header-logo {
  display: grid;
  flex: 0 0 76px;
  min-height: 38px;
  place-items: center;
  padding: 4px 5px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.header-logo img {
  display: block;
  width: 100%;
  height: auto;
}

.topbar-title {
  min-width: 0;
}

.topbar-title h1,
.topbar-title .eyebrow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.05;
}

h2 {
  font-size: 22px;
  line-height: 1.1;
}

h3 {
  font-size: 15px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

main {
  padding: 16px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading,
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric,
.route-panel,
.history-panel,
.visit-form,
.admin-form,
.account-panel,
.outlet-card,
.manager-card,
.staff-card,
.history-card,
.job-card,
.job-prefill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.metric {
  min-height: 82px;
  padding: 13px 10px;
}

.metric span {
  display: block;
  color: var(--brand);
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.metric p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.route-panel,
.history-panel,
.account-panel {
  margin-bottom: 14px;
  padding: 13px;
}

.account-panel strong {
  display: block;
  margin-top: 5px;
  font-size: 16px;
}

.account-panel p:last-child {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.route-list,
.visit-list,
.outlet-list,
.manager-list,
.staff-list,
.assignment-list,
.repeat-list,
.job-list,
.history-list {
  display: grid;
  gap: 10px;
}

.route-item,
.visit-item,
.repeat-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.route-item:first-child,
.visit-item:first-child,
.repeat-card:first-child {
  border-top: 0;
  padding-top: 0;
}

.route-item strong,
.visit-item strong,
.repeat-card strong,
.outlet-card strong,
.manager-card strong,
.staff-card strong {
  display: block;
  font-size: 15px;
}

.route-item p,
.visit-item p,
.repeat-card p,
.outlet-card p,
.manager-card p,
.staff-card p,
.history-card p,
.location-box p,
.job-prefill p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-2);
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
}

.status.warn {
  background: #fff7ed;
  color: var(--warn);
}

.status.danger {
  background: #fef2f2;
  color: var(--danger);
}

.visit-form,
.admin-form {
  display: grid;
  gap: 13px;
  padding: 13px;
  margin-bottom: 16px;
}

label,
legend {
  display: grid;
  gap: 7px;
  color: #27332b;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--text);
  font-weight: 600;
}

.assignment-row {
  align-items: flex-start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.assignment-row span {
  display: grid;
  gap: 3px;
}

.assignment-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.check-row input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--brand);
}

.photo-box,
.location-box,
.order-box,
.inline-add,
.add-grid {
  display: grid;
  gap: 8px;
}

.photo-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.photo-box-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.photo-box-head strong {
  display: block;
  font-size: 14px;
}

.photo-box-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.photo-box-head .secondary-button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 12px;
}

.camera-input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.camera-button {
  min-height: 48px;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #f0fdfa;
  color: var(--brand-2);
  font-weight: 800;
}

.inline-add {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.inline-add summary {
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.add-grid {
  margin-top: 10px;
}

.fixed-staff {
  display: grid;
  gap: 4px 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.time-box {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.time-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.time-box strong {
  font-size: 15px;
}

.time-box p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.time-box.validated {
  border-color: #86efac;
  background: #f0fdf4;
}

.time-box.invalid {
  border-color: #fca5a5;
  background: #fef2f2;
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #9ca3af;
  opacity: 0.75;
}

.performance-grid .metric span {
  font-size: 23px;
}

.fixed-staff span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.fixed-staff strong {
  font-size: 15px;
}

.fixed-staff .link-button {
  grid-row: 1 / span 2;
  grid-column: 2;
  color: var(--brand);
}

.job-prefill {
  display: grid;
  gap: 5px;
  padding: 12px;
  background: #f0fdfa;
  border-color: #99f6e4;
}

.job-prefill span {
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.job-prefill .link-button {
  justify-self: start;
  color: var(--brand-2);
}

.photo-grid {
  display: grid;
  gap: 12px;
}

.photo-section {
  display: grid;
  gap: 10px;
}

.photo-requirement {
  padding: 10px 12px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.outcome-box {
  padding: 12px;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #f0fdfa;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.photo-preview img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.order-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.order-help {
  margin: -4px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.product-order-list,
.product-admin-list,
.gps-outlet-list {
  display: grid;
  gap: 8px;
}

.gps-outlet-item {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) repeat(3, minmax(100px, 1fr));
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.gps-outlet-item > strong {
  align-self: center;
  font-size: 14px;
}

.product-order-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 92px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.product-order-row input[type="checkbox"] {
  width: 20px;
  min-height: 20px;
  accent-color: var(--brand);
}

.product-order-row input[type="number"] {
  min-height: 42px;
}

.product-order-row strong,
.product-admin-item strong {
  display: block;
  font-size: 14px;
}

.product-order-row small,
.product-admin-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.product-admin-list {
  margin-top: 4px;
}

.product-admin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.link-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  background: var(--brand);
  color: #ffffff;
}

.secondary-button {
  background: var(--surface-2);
  color: var(--brand);
}

.ghost-button {
  padding: 0 14px;
  background: #e4f1e3;
  color: var(--brand);
}

.icon-button {
  width: 44px;
  background: var(--brand);
  color: #ffffff;
}

.link-button {
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: var(--danger);
}

.outlet-card,
.manager-card,
.staff-card,
.history-card {
  padding: 13px;
}

.history-card {
  display: grid;
  gap: 10px;
}

.history-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.job-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.job-card:not(.job-card-static) {
  border-color: #99f6e4;
  background: #f0fdfa;
}

.job-card strong {
  display: block;
  font-size: 15px;
}

.job-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.job-reschedule {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.job-reschedule input,
.job-reschedule button {
  min-height: 40px;
}

.password-reset {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 8px;
  margin-top: 12px;
}

.password-reset input,
.password-reset button {
  min-height: 42px;
}

.nav-item[hidden] {
  display: none;
}

.outlet-meta,
.manager-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.manager-photos {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.manager-photo-group {
  display: grid;
  gap: 7px;
}

.manager-photo-group strong {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.manager-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.manager-photo-grid img {
  width: 100%;
  aspect-ratio: 1.15;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.manager-photo-grid span,
.photo-note {
  color: var(--muted);
  font-size: 13px;
}

.pill {
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-2);
  color: #2f4938;
  font-size: 12px;
  font-weight: 700;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 140px 140px;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-row.single {
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.quick-filter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.quick-filter-row .secondary-button {
  min-height: 40px;
  padding: 0 8px;
  font-size: 13px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  width: min(560px, 100%);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 56px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.nav-item.active {
  background: #e4f1e3;
  color: var(--brand);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: currentColor;
  color: #ffffff;
  font-size: 12px;
}

.nav-item.active .nav-icon {
  background: var(--brand);
}

.empty {
  padding: 16px 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 30;
  width: min(520px, calc(100% - 28px));
  padding: 13px 14px;
  border-radius: 8px;
  background: #172017;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 720px) {
  body {
    background: #e8ece6;
  }

  .app-shell {
    min-height: calc(100dvh - 32px);
    margin: 16px auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
  }
}

@media (min-width: 900px) {
  body {
    background: #eef1ed;
  }

  body:has(.login-screen:not(.hidden)) {
    overflow: auto;
  }

  .app-shell {
    display: grid;
    grid-template-columns: 208px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    width: calc(100% - 40px);
    max-width: 1280px;
    min-height: calc(100dvh - 40px);
    margin: 20px auto;
    padding-bottom: 0;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 14px 40px rgba(22, 40, 26, 0.08);
    overflow: clip;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 104px;
    padding: 18px 24px;
    background: rgba(255, 255, 255, 0.96);
  }

  .topbar-brand {
    gap: 20px;
  }

  .header-logo {
    flex-basis: 150px;
    min-height: 66px;
    padding: 10px 12px;
    border-color: #ced8ce;
    border-radius: 8px;
  }

  .topbar-title {
    display: grid;
    gap: 5px;
  }

  .topbar-title h1 {
    font-size: 30px;
    line-height: 1.08;
  }

  .topbar-title .eyebrow {
    font-size: 13px;
  }

  .bottom-nav {
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-height: calc(100dvh - 145px);
    padding: 18px 12px;
    background: #ffffff;
    border-top: 0;
    border-right: 1px solid var(--line);
    transform: none;
    backdrop-filter: none;
  }

  .nav-item {
    grid-template-columns: 32px minmax(0, 1fr);
    justify-items: start;
    gap: 10px;
    min-height: 48px;
    padding: 0 12px;
    font-size: 13px;
    text-align: left;
  }

  .nav-icon {
    width: 28px;
    height: 28px;
  }

  main {
    grid-column: 2;
    grid-row: 2;
    width: 100%;
    max-width: none;
    padding: 24px;
    overflow: hidden;
  }

  .view.active {
    animation: desktop-view-in 160ms ease-out;
  }

  #view-today.active,
  #view-admin.active,
  #view-manager.active,
  #view-jobs.active {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 16px;
  }

  #view-today > .section-heading,
  #view-today > .account-panel,
  #view-today > .metric-grid,
  #view-today > .history-panel:last-child,
  #view-admin > .section-heading,
  #view-manager > .section-heading,
  #view-manager > .filter-row,
  #view-manager > .quick-filter-row,
  #view-manager > .metric-grid,
  #view-manager > .manager-list,
  #view-jobs > .section-heading,
  #view-jobs > .history-panel {
    grid-column: 1 / -1;
  }

  #view-today .route-panel,
  #view-today .history-panel,
  #view-admin .admin-form,
  #view-admin .history-panel,
  #view-manager .history-panel,
  #view-jobs .admin-form,
  #view-jobs .history-panel {
    margin-bottom: 0;
  }

  #view-visit,
  #view-history,
  #view-outlets {
    max-width: 1040px;
    margin: 0 auto;
  }

  #view-visit .visit-form {
    padding: 18px;
  }

  .photo-grid,
  .add-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .photo-box {
    min-width: 0;
  }

  .outlet-list,
  .history-list,
  .manager-list,
  .staff-list,
  .job-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .filter-row {
    grid-template-columns: minmax(220px, 1fr) 180px 180px;
  }

  .quick-filter-row {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .login-screen {
    padding: 40px;
  }

  .login-card {
    width: min(460px, 100%);
    padding: 26px;
  }

  .toast {
    bottom: 24px;
  }
}

@keyframes desktop-view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 390px) {
  main,
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .filter-row,
  .two-col,
  .order-row,
  .password-reset {
    grid-template-columns: 1fr;
  }

  .quick-filter-row {
    grid-template-columns: 1fr;
  }

  .order-row .icon-button {
    width: 100%;
  }

  .product-order-row {
    grid-template-columns: 24px minmax(0, 1fr) 78px;
  }

  .gps-outlet-item {
    grid-template-columns: 1fr;
  }

  .metric {
    padding: 12px 8px;
  }

  .topbar {
    gap: 8px;
  }

  .topbar-brand {
    gap: 8px;
  }

  .header-logo {
    flex-basis: 62px;
    min-height: 34px;
  }

  .topbar-title h1 {
    font-size: 19px;
  }

  .topbar .header-actions {
    gap: 5px;
  }

  .header-language {
    min-width: 60px;
    max-width: 68px;
    min-height: 40px;
    padding-left: 7px;
    padding-right: 22px;
  }

  .topbar .ghost-button {
    padding: 0 10px;
  }
}
