:root {
  --ink: #15222b;
  --muted: #5b6b75;
  --line: #d6e0e5;
  --surface: #ffffff;
  --surface-soft: #f3f7f9;
  --brand: #0b4f6c;
  --brand-dark: #07384c;
  --accent: #f2a900;
  --danger: #a12622;
  --success: #1d6b42;
  --warning: #8a5a00;
  --shadow: 0 10px 28px rgba(14, 47, 63, 0.09);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-soft); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #eef5f8 0, var(--surface-soft) 240px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: var(--brand); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  color: #fff;
  background: rgba(7, 56, 76, 0.97);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(12px);
}
.header-inner {
  width: min(1120px, calc(100% - 28px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--brand-dark);
  background: var(--accent);
  border-radius: 50%;
  font-weight: 900;
}
.main-nav { display: flex; align-items: center; gap: 6px; }
.main-nav a, .link-button {
  border: 0;
  padding: 9px 11px;
  color: #eaf5f8;
  background: transparent;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}
.main-nav a:hover, .main-nav a.active, .link-button:hover { background: rgba(255,255,255,0.12); color: #fff; }
.logout-form { margin: 0; }

.page-shell { width: min(1120px, calc(100% - 28px)); margin: 0 auto; padding: 24px 0 56px; }
.signed-in-as { margin-bottom: 12px; color: var(--muted); font-size: 0.9rem; }
.site-footer { min-height: 70px; display: grid; place-items: center; color: var(--muted); font-size: 0.88rem; }

.page-heading { margin: 12px 0 22px; }
.page-heading.compact { margin-top: 0; }
.page-heading.with-action { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.page-heading h1 { margin: 0; font-size: clamp(1.9rem, 5vw, 2.8rem); letter-spacing: -0.035em; line-height: 1.1; }
.page-heading p { max-width: 720px; margin: 8px 0 0; color: var(--muted); }
.eyebrow { color: var(--brand) !important; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }

.panel, .auth-card, .report-list-item, .stat-card {
  background: var(--surface);
  border: 1px solid rgba(11, 79, 108, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { margin-bottom: 18px; padding: clamp(18px, 4vw, 28px); }
.panel h2 { margin: 0 0 16px; font-size: 1.2rem; }
.auth-card { width: min(470px, 100%); margin: 42px auto; padding: clamp(24px, 6vw, 40px); }

.alert { margin: 0 0 18px; padding: 13px 16px; border-radius: 10px; border: 1px solid; }
.alert-success { color: #155232; background: #e9f7ef; border-color: #a9d8bb; }
.alert-error { color: #7d1c19; background: #fcebea; border-color: #e2aaa7; }
.alert-warning { color: #684400; background: #fff4d6; border-color: #e5c66e; }
.alert-info { color: #174f67; background: #e8f3f8; border-color: #add2e1; }

.stack-form { display: grid; gap: 16px; }
.report-form { display: block; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.admin-create-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.admin-edit-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.site-fields-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.site-import-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 16px; }
.full-width { grid-column: 1 / -1; }
label { display: grid; gap: 7px; font-weight: 700; color: #2b3b44; }
label > span:first-child { font-size: 0.92rem; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid #b9c9d1;
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11, 79, 108, 0.14); }
textarea { resize: vertical; min-height: 88px; }
input[readonly] { background: #edf2f4; color: #44555e; }
select:disabled { opacity: 0.7; }
.check-row { display: inline-flex; grid-auto-flow: column; justify-content: start; align-items: center; gap: 9px; font-weight: 600; }
.check-row input { width: 20px; min-height: 20px; height: 20px; }
.file-picker { padding: 18px; border: 1px dashed #91aebc; border-radius: 11px; background: #f8fbfc; }
.file-picker input { min-height: auto; border: 0; padding: 4px 0; background: transparent; }
.file-picker small, .help-text, .photo-selection-status { color: var(--muted); font-size: 0.88rem; }
.photo-selection-status { margin: 12px 0; }

.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 16px; }
.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 16px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.button:disabled { opacity: 0.65; cursor: wait; }
.button-primary { color: #fff; background: var(--brand); }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { color: var(--brand); background: #fff; border-color: #9bb7c4; }
.button-secondary:hover { background: #eef5f8; }
.button-danger { color: #fff; background: var(--danger); }
.button-danger:hover { background: #7d1c19; }
.button-block { width: 100%; }

.photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.photo-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.photo-card img, .detail-photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #e8eef1; }
.photo-card > span { padding: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.removable-photo .check-row { padding: 10px; }
.detail-photos a { overflow: hidden; border-radius: 10px; border: 1px solid var(--line); }

.report-list { display: grid; gap: 12px; }
.report-list-item { display: block; padding: 18px; color: inherit; text-decoration: none; transition: transform 120ms ease, box-shadow 120ms ease; }
.report-list-item:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(14, 47, 63, 0.14); }
.report-list-topline, .report-list-bottom, .record-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.report-list-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; color: var(--muted); font-size: 0.9rem; }
.report-list-meta span { padding-right: 8px; border-right: 1px solid var(--line); }
.report-list-meta span:last-child { border: 0; }
.report-list-bottom { color: var(--muted); font-size: 0.88rem; }

.priority-badge, .status-badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; padding: 4px 9px; font-size: 0.78rem; font-weight: 800; text-transform: capitalize; }
.priority-critical { color: #fff; background: #9b1c1c; }
.priority-high { color: #6f1b00; background: #ffd9c7; }
.priority-medium { color: #704b00; background: #ffe7a6; }
.priority-low { color: #155232; background: #d9f1e3; }
.status-sent { color: #155232; background: #dff3e7; }
.status-pending { color: #664500; background: #fff0bd; }
.status-failed { color: #7d1c19; background: #f8dedd; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 18px; }
.detail-list { margin: 0; }
.detail-list > div { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.error-text { color: var(--danger); font-size: 0.88rem; }
.pre-wrap { white-space: pre-wrap; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { padding: 20px; color: inherit; text-decoration: none; }
.stat-card strong { display: block; font-size: 2rem; color: var(--brand); }
.stat-card span { color: var(--muted); }
.stat-card.has-warning strong { color: var(--danger); }
.admin-link-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.admin-link { color: inherit; text-decoration: none; }
.admin-link p { margin-bottom: 0; color: var(--muted); }
.admin-records { display: grid; gap: 14px; }
.admin-record-form { margin: 0; }
.record-heading { margin-bottom: 16px; }
.record-heading h2 { margin: 0; }
.record-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 0.88rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.csv-help { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.csv-help summary { color: var(--brand); font-weight: 800; cursor: pointer; }
.csv-help p { color: var(--muted); }
.csv-columns { overflow-wrap: anywhere; }
code { padding: 2px 5px; border-radius: 5px; background: #edf2f4; font-size: 0.9em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }
.empty-state { text-align: center; padding-block: 50px; }
.error-page { width: min(620px, 100%); margin: 36px auto; text-align: center; }
.error-code { font-size: 4rem; font-weight: 900; color: var(--brand); }

@media (max-width: 840px) {
  .header-inner { min-height: auto; padding: 12px 0; align-items: flex-start; flex-direction: column; }
  .main-nav { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .main-nav a, .link-button { white-space: nowrap; }
  .detail-grid, .admin-link-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-create-grid, .admin-edit-grid, .site-fields-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 580px) {
  .page-shell, .header-inner { width: min(100% - 20px, 1120px); }
  .page-shell { padding-top: 16px; }
  .page-heading.with-action { align-items: stretch; flex-direction: column; }
  .page-heading.with-action > .button { align-self: flex-start; }
  .form-grid.two-columns, .admin-create-grid, .admin-edit-grid, .site-fields-grid, .site-import-grid { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-list-topline, .report-list-bottom { align-items: flex-start; flex-direction: column; gap: 7px; }
  .detail-list > div { grid-template-columns: 1fr; gap: 3px; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .site-import-grid .button, .button-row .button { width: 100%; }
  .sticky-actions { position: sticky; bottom: 0; z-index: 10; margin-inline: -10px; padding: 12px 10px max(12px, env(safe-area-inset-bottom)); background: rgba(243, 247, 249, 0.96); backdrop-filter: blur(10px); }
}

/* v1.2.3 Site search, typeable selector and field alignment */
.site-search-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) minmax(190px, 0.8fr) auto;
  align-items: end;
  gap: 14px;
}
.site-result-summary {
  margin: 16px 0 0;
  color: var(--muted);
}
.pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
}
.pagination > :first-child { justify-self: start; }
.pagination > :nth-child(2) { text-align: center; color: var(--muted); }
.pagination > :last-child { justify-self: end; }
[data-site-input] { text-transform: uppercase; }
[data-site-input]:disabled { background: #edf2f4; cursor: wait; }
.site-guidance {
  display: grid;
  gap: 4px;
  margin-top: -6px;
  font-weight: 400;
}
.site-guidance .help-text { margin: 0; }

@media (max-width: 840px) {
  .main-nav { overflow-x: visible; flex-wrap: wrap; }
  .site-search-grid { grid-template-columns: 1fr 1fr; }
  .site-search-grid .button { grid-column: 1 / -1; }
}

@media (max-width: 580px) {
  .site-search-grid { grid-template-columns: 1fr; }
  .site-search-grid .button { grid-column: auto; width: 100%; }
  .pagination { grid-template-columns: 1fr 1fr; }
  .pagination > :nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
  .pagination > :first-child { grid-column: 1; grid-row: 2; width: 100%; }
  .pagination > :last-child { grid-column: 2; grid-row: 2; width: 100%; }
}
