:root {
  --bg: #f8f9fa;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text: #1a1f36;
  --muted: #6b7280;
  --muted-header: #9ca3af;
  --accent-title: #1a2332;
  --teal: #2a9d8f;
  --teal-light: #e6f5f3;
  --nav-active-bg: #e8f4fc;
  --nav-active-bar: #2563eb;
  --failed: #c62828;
  --failed-bar: #b71c1c;
  --partial: #ef6c00;
  --partial-bar: #e65100;
  --passed: #2e7d32;
  --passed-bar: #1b5e20;
  --border: #e5e7eb;
  --link: #1565c0;
  --avatar-bg: #7c3aed;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-title);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  font-size: 0.9rem;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
  filter: brightness(1.05);
}

.btn-primary {
  background: var(--accent-title);
  color: #fff;
}

.btn-secondary {
  background: #fff;
  color: var(--accent-title);
  border-color: var(--border);
}

.btn-danger {
  background: var(--failed);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.pillar-tabs {
  margin-top: 0.25rem;
}

.pillar-tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.pillar-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--accent-title);
  box-shadow: none;
}

.pillar-tab:hover {
  border-color: var(--muted-header);
  color: var(--accent-title);
}

.pillar-tab[aria-selected="true"] {
  border-color: var(--link);
  color: var(--link);
  background: #e3f2fd;
  box-shadow: 0 0 0 1px rgba(21, 101, 192, 0.15);
}

.pillar-tab:focus-visible {
  outline: 2px solid var(--nav-active-bar);
  outline-offset: 2px;
}

.pillar-tab__count {
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 1.25rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
}

.pillar-tab[aria-selected="true"] .pillar-tab__count {
  background: rgba(21, 101, 192, 0.12);
  color: var(--link);
}

.pillar-tabpanel {
  scroll-margin-top: 1rem;
  padding-top: 0.25rem;
}

.pillar-tabpanel[hidden] {
  display: none !important;
}

.pillar-tabpanel__empty {
  margin: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1rem 1rem 1.35rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  min-height: 140px;
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 8px 0 0 8px;
}

.card--failed::before {
  background: var(--failed-bar);
}

.card--partial::before {
  background: var(--partial-bar);
}

.card--passed::before {
  background: var(--passed-bar);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.card-meta {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.card--failed .card-meta {
  color: var(--failed);
}

.card--partial .card-meta {
  color: var(--partial);
}

.card--passed .card-meta {
  color: var(--passed);
}

.card-title {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-title);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
  color: #fff;
}

.badge--failed {
  background: var(--failed);
}

.badge--partial {
  background: var(--partial);
}

.badge--passed {
  background: var(--passed);
}

.card-head-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex-shrink: 0;
}

.card-menu {
  position: relative;
  z-index: 1;
}

.card-menu[open] {
  z-index: 30;
}

.card-menu-trigger {
  list-style: none;
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-menu-trigger::-webkit-details-marker {
  display: none;
}

.card-menu-trigger::marker {
  display: none;
}

.card-menu-trigger:hover {
  border-color: var(--muted-header);
  color: var(--accent-title);
}

.card-menu-trigger:focus-visible {
  outline: 2px solid var(--nav-active-bar);
  outline-offset: 2px;
}

.card-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  min-width: 9.5rem;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.card-menu-list a {
  display: block;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
}

.card-menu-list a:hover {
  background: #f3f4f6;
  text-decoration: none;
}

.card-menu-list__danger a {
  color: #c62828;
}

.card-menu-list__danger a:hover {
  background: #ffebee;
}

.thumb--static {
  cursor: default;
}

.card-body ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.card-body li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.92rem;
  color: var(--text);
}

.card-body li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 5px;
  height: 5px;
}

.card--failed .card-body li::before {
  background: var(--failed);
}

.card--partial .card-body li::before {
  background: var(--partial);
}

.card--passed .card-body li::before {
  background: var(--passed);
}

.card-foot {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.thumb {
  max-width: 100%;
  max-height: 160px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.thumb-trigger {
  display: block;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  border-radius: 6px;
  line-height: 0;
  font: inherit;
}

.thumb-trigger:focus-visible {
  outline: 2px solid var(--nav-active-bar);
  outline-offset: 2px;
}

.thumb-trigger .thumb {
  display: block;
}

.thumb-trigger:hover .thumb {
  border-color: var(--link);
}

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

/* Closed <dialog> must stay display:none — do not set display:flex without [open] or the
   UA hidden state is overridden and fixed children (e.g. close) can remain visible. */
.image-view-dialog:not([open]) {
  display: none;
}

.image-view-dialog[open] {
  position: relative;
  width: min(100vw, 100%);
  height: min(100vh, 100%);
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  padding: 3rem 1.5rem 1.5rem;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.image-view-dialog::backdrop {
  background: rgba(15, 23, 42, 0.82);
  cursor: pointer;
}

.image-view-img {
  max-width: 100%;
  max-height: calc(100vh - 5rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  cursor: default;
}

.image-view-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-view-close:hover {
  background: rgba(0, 0, 0, 0.65);
}

.image-view-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.empty-pillar {
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0.5rem 0;
}

.checks-table-wrap {
  overflow-x: auto;
  margin: 0 -0.25rem;
}

.checks-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.checks-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.checks-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.checks-table tbody tr:hover {
  background: #f9fafb;
}

.checks-table__actions {
  white-space: nowrap;
  text-align: right;
}

.checks-table__actions .btn {
  margin-left: 0.35rem;
}

.checks-table__actions .btn:first-child {
  margin-left: 0;
}

.detail-back {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.detail-back a {
  font-weight: 600;
}

.detail-dl {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.5rem 1rem;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.detail-dl dt {
  margin: 0;
  font-weight: 600;
  color: var(--muted);
}

.detail-dl dd {
  margin: 0;
  color: var(--text);
}

.detail-findings {
  margin-bottom: 1.5rem;
}

.detail-findings__title {
  margin: 0 0 0.65rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-title);
}

.detail-findings__list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.95rem;
}

.detail-shot {
  margin-bottom: 1.5rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 560px) {
  .detail-dl {
    grid-template-columns: 1fr;
  }

  .detail-dl dt {
    padding-top: 0.35rem;
  }
}

/* Forms */
.form-page {
  max-width: 720px;
}

.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.form-row {
  margin-bottom: 1rem;
}

.form-row label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--accent-title);
}

.input,
.textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.input-file {
  font-size: 0.9rem;
}

.errorlist {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: var(--failed);
  font-size: 0.85rem;
}

.formset h3 {
  margin: 1rem 0 0.5rem;
  font-size: 1rem;
  color: var(--accent-title);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.login-brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal) 0%, #1e6b62 100%);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.login-brand-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-lead {
  margin: 0 0 1.25rem;
}

.login-card p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-card .btn-primary {
  width: 100%;
  margin-top: 0.5rem;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.messages li {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: #e8f5e9;
  color: #1b5e20;
  font-size: 0.9rem;
}

.messages .error {
  background: #ffebee;
  color: #b71c1c;
}

/* App shell (sidebar + main) */
.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
  background: var(--bg);
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1.25rem;
  text-decoration: none;
  color: inherit;
}

.sidebar-brand:hover {
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal) 0%, #1e6b62 100%);
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.sidebar-brand-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-brand-main {
  color: var(--accent-title);
}

.sidebar-brand-accent {
  color: var(--teal);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0 0.75rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  margin-left: 0;
}

.sidebar-link:hover {
  background: #f3f4f6;
  text-decoration: none;
  color: var(--accent-title);
}

.sidebar-link.is-active {
  background: var(--nav-active-bg);
  color: var(--nav-active-bar);
  border-left-color: var(--nav-active-bar);
}

.sidebar-link-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.75rem 2.5rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-title);
  letter-spacing: -0.02em;
}

.page-header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.user-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.user-role {
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-logout {
  padding: 0.45rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid #e53935;
  color: #c62828;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.btn-logout:hover {
  background: #ffebee;
  text-decoration: none;
  color: #b71c1c;
}

.messages--main {
  margin: 0 0 1rem;
}

.page-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  padding: 1.5rem 1.75rem 1.75rem;
}

.card-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.card-section-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent-title);
}

.btn-outline-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--link);
  color: var(--link);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.btn-outline-primary:hover {
  background: #e3f2fd;
  text-decoration: none;
  color: #0d47a1;
}

.btn-outline-teal {
  border-color: var(--teal);
  color: #1e7168;
}

.btn-outline-teal:hover {
  background: var(--teal-light);
  text-decoration: none;
  color: #145a52;
}

.btn-outline-danger {
  border-color: #e53935;
  color: #c62828;
}

.btn-outline-danger:hover {
  background: #ffebee;
  text-decoration: none;
  color: #b71c1c;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-primary-solid {
  padding: 0.5rem 1.15rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
}

.btn-primary-solid:hover {
  filter: brightness(1.05);
}

.btn-danger-solid {
  padding: 0.5rem 1.15rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  background: var(--failed);
  color: #fff;
  cursor: pointer;
}

.btn-danger-solid:hover {
  filter: brightness(1.05);
}

.card-foot--actions {
  gap: 0.5rem;
}

.form-row--nested {
  border-left: 3px solid var(--border);
  padding-left: 0.85rem;
  margin-bottom: 0.75rem;
}

.form-delete-label {
  font-weight: 400;
  margin-top: 0.35rem;
  display: block;
}

.finding-lines {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.btn-add-finding {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.45rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--link);
  color: var(--link);
  background: #fff;
  cursor: pointer;
}

.btn-add-finding:hover {
  background: #e3f2fd;
}

.btn-add-finding:focus-visible {
  outline: 2px solid var(--nav-active-bar);
  outline-offset: 2px;
}

.btn-add-finding__icon {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
}

.delete-lead {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  color: var(--text);
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    padding: 0;
  }

  .sidebar-link {
    flex: 1 1 auto;
    min-width: 140px;
    justify-content: center;
  }

  .page-header-user {
    width: 100%;
    justify-content: flex-end;
  }
}
