:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2733;
  --muted: #667085;
  --line: #d9dee7;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --danger: #b42318;
  --ok: #137333;
  --warn: #9a6700;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
.shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 0; }
.topnav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ph-topbar {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
}
.ph-brandline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
}
.ph-logo {
  width: 86px;
  height: 30px;
  object-fit: contain;
}
.ph-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 14px;
  justify-content: center;
}
.ph-actions { justify-content: flex-end; }
.container { width: min(1120px, 100%); margin: 0 auto; padding: 18px; }
.auth {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 18px;
  padding-top: max(76px, 12vh);
}
.login-wrap {
  display: grid;
  gap: 18px;
  justify-items: center;
  width: min(420px, 100%);
}
.login-logo {
  width: 92px;
  height: auto;
  display: block;
}
.auth-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.panel.grid { align-content: start; }
.auth-card { width: 100%; }
h1, h2, h3 { margin: 0 0 14px; line-height: 1.15; }
h1 { font-size: clamp(24px, 4vw, 34px); }
h2 { font-size: 21px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.store-results {
  display: grid;
  gap: 8px;
  max-height: 310px;
  overflow-y: auto;
  padding-right: 2px;
}
.store-result {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.store-result strong {
  font-size: 15px;
  line-height: 1.2;
}
.store-result span,
.store-result small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}
.store-result.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.14);
}
label { font-size: 14px; color: var(--muted); font-weight: 650; }
.label-action {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text);
  font-size: 14px;
}
.check-row input {
  width: 18px;
  min-height: 18px;
  flex: 0 0 auto;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover,
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.secondary { background: #fff; border-color: var(--line); color: var(--text); }
.btn.secondary:hover { background: #f8fafc; border-color: var(--line); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.small { min-width: 76px; min-height: 34px; padding: 6px 10px; font-size: 14px; }
.admin-dashboard .btn {
  min-width: 120px;
  justify-self: start;
}
.admin-dashboard .btn.small { min-width: 76px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}
.table-actions form { margin: 0; }
.password-action {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.password-action input {
  width: 150px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 14px;
}
.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.photo-pickers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.photo-picker-btn {
  gap: 8px;
  min-height: 48px;
}
.photo-picker-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}
.muted { color: var(--muted); }
.flash { padding: 12px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid var(--line); background: #fff; }
.flash.error { border-color: #f4b7b2; color: var(--danger); }
.flash.ok { border-color: #a8d8b9; color: var(--ok); }
.danger-zone { border-color: #f4b7b2; }
.page-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.admin-dashboard table { min-width: 860px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 13px; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.status.new { color: var(--warn); background: #fff4cf; }
.status.accepted { color: var(--ok); background: #dcf7e5; }
.status.rejected { color: var(--danger); background: #ffe4e1; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photo { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.photo img { width: 100%; height: 140px; object-fit: cover; display: block; }
.photo a { display: block; padding: 8px; font-size: 13px; }
.image-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
}
.image-load-error img {
  display: none !important;
}
.image-load-error .image-fallback {
  display: flex;
}
.photo.image-load-error .image-fallback {
  min-height: 140px;
  background: #fafbfc;
  font-size: 13px;
}
.photo-queue {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 72px));
  gap: 8px;
}
.queued-photo {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}
.queued-photo img {
  width: 72px !important;
  height: 72px !important;
  object-fit: cover !important;
  display: block !important;
}
.queued-photo-preview {
  display: block;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.queued-photo-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: rgba(29, 39, 51, 0.86);
  color: #fff;
  font-size: 18px;
  line-height: 24px;
  font-weight: 800;
  cursor: pointer;
}
.filters { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 10px; align-items: end; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.metric strong { display: block; font-size: 28px; margin-top: 4px; }
.metric-date { font-size: 20px !important; }
.period-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.period-tabs a {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 750;
  white-space: nowrap;
}
.period-tabs a.active {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}
.gallery-jump {
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}
.gallery-jump:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}
.gallery-jump svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.gallery-filter {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.gallery-filter form {
  flex: 1 1 320px;
  justify-content: flex-end;
}
.gallery-filter select {
  max-width: 260px;
}
.activity-summary {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(76px, 0.45fr) minmax(76px, 0.45fr);
  gap: 8px;
  align-items: stretch;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.summary-period,
.summary-count {
  display: grid;
  align-content: center;
  min-width: 0;
}
.summary-period span,
.summary-count span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}
.summary-period strong {
  margin-top: 3px;
  font-size: 14px;
  line-height: 1.2;
}
.summary-count {
  justify-items: center;
  padding: 8px 6px;
  border-radius: 6px;
  background: #fafbfc;
}
.summary-count strong {
  font-size: 30px;
  line-height: 0.95;
}
.activity-cards {
  display: grid;
  gap: 8px;
}
.activity-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.activity-person {
  min-width: 0;
}
.activity-card h2 {
  margin: 0 0 3px;
  overflow: hidden;
  font-size: 17px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-person span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-stats {
  display: grid;
  grid-template-columns: repeat(2, 68px);
  gap: 8px;
}
.activity-stats div {
  min-height: 58px;
  padding: 7px 6px;
  border-radius: 2px;
  background: #fafbfc;
  text-align: center;
}
.activity-stats strong {
  display: block;
  font-size: 31px;
  line-height: 0.95;
}
.activity-stats span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
}
.gallery-photos {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.gallery-photos img {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}
.gallery-photo-button {
  display: block;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: zoom-in;
  overflow: hidden;
}
.gallery-photo-button .image-fallback {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}
.activity-gallery h3 { margin-bottom: 0; }
.gallery-month {
  display: grid;
  gap: 8px;
}
.gallery-month h4 {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.gallery-visits {
  display: grid;
  gap: 8px;
}
.gallery-visit {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 2fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.gallery-visit span,
.gallery-visit small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}
.storechecks-section {
  margin-top: 8px;
}
.storechecks-list {
  display: grid;
  gap: 10px;
}
.storecheck-card {
  gap: 10px;
}
.storecheck-main,
.storecheck-meta {
  display: grid;
  gap: 3px;
}
.storecheck-main span,
.storecheck-main small,
.storecheck-meta {
  color: var(--muted);
}
.storecheck-meta {
  grid-template-columns: repeat(2, minmax(0, max-content));
  gap: 12px;
  font-size: 13px;
}
.kam-report-list {
  display: grid;
  gap: 8px;
}
.kam-report-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
}
.kam-report-main {
  display: grid;
  min-width: 0;
  gap: 3px;
}
.kam-report-main strong,
.kam-report-main span,
.kam-report-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kam-report-main span,
.kam-report-main small,
.kam-report-meta {
  color: var(--muted);
}
.kam-report-meta {
  display: grid;
  justify-items: end;
  gap: 5px;
  font-size: 13px;
}
.recipient-list {
  display: grid;
  gap: 8px;
}
.choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}
.choice-list.compact {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.choice-row,
.recipient-row {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}
.recipient-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.recipient-list.compact {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.recipient-chip {
  display: grid;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}
.recipient-chip span,
.recipient-chip small {
  color: var(--muted);
  font-size: 12px;
}
.attachment-list {
  display: grid;
  gap: 8px;
}
.attachment-link {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  overflow-wrap: anywhere;
}
.preline {
  white-space: pre-line;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(17, 24, 39, 0.78);
}
.lightbox-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
  width: min(920px, 100%);
  max-height: calc(100vh - 36px);
  padding: 12px;
  border-radius: 8px;
  background: #fff;
}
.lightbox-dialog img {
  width: 100%;
  max-height: calc(100vh - 120px);
  object-fit: contain;
  background: #f8fafc;
  border-radius: 6px;
}
.lightbox-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.lightbox-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(29, 39, 51, 0.88);
  color: #fff;
  font-size: 24px;
  line-height: 34px;
  cursor: pointer;
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .ph-topbar { display: flex; gap: 8px; }
  .ph-logo { width: 78px; height: 28px; }
  .ph-meta { justify-content: flex-start; font-size: 13px; }
  .auth {
    min-height: 100dvh;
    padding-top: max(70px, 11vh);
  }
  .login-wrap { gap: 16px; }
  .login-logo { width: 86px; }
  .photo-pickers { grid-template-columns: 1fr; }
  .container { padding: 14px; }
  .grid.two, .grid.three, .filters, .gallery-visit { grid-template-columns: 1fr; }
  .activity-summary {
    grid-template-columns: minmax(0, 1fr) 62px 62px;
    gap: 6px;
    padding: 8px;
  }
  .summary-period span,
  .summary-count span { font-size: 11px; }
  .summary-period strong { font-size: 12px; }
  .summary-count strong { font-size: 24px; }
  .activity-card {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px 10px;
  }
  .activity-card h2 { font-size: 15px; }
  .activity-person span { font-size: 13px; }
  .activity-stats {
    grid-template-columns: repeat(2, 54px);
    gap: 6px;
  }
  .activity-stats div {
    min-height: 50px;
    padding: 6px 4px;
  }
  .activity-stats strong { font-size: 25px; }
  .activity-stats span { font-size: 10px; }
  .period-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-tabs a { padding-inline: 8px; }
  .gallery-filter,
  .gallery-filter form {
    align-items: stretch;
    flex-direction: column;
  }
  .gallery-filter form {
    flex: 0 1 auto;
    width: 100%;
  }
  .gallery-filter select { max-width: none; }
  .storecheck-meta { grid-template-columns: 1fr; }
  .page-head { display: grid; }
  .label-action {
    align-items: stretch;
    flex-direction: column;
  }
  .label-action .btn {
    width: 100%;
  }
  .kam-report-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .kam-report-row > .btn {
    grid-column: 1 / -1;
    width: 100%;
  }
  table { min-width: 640px; }
}
