:root {
  --ink: #18231f;
  --muted: #65716c;
  --subtle: #87918d;
  --line: #dce5df;
  --paper: #ffffff;
  --soft: #f3f6f0;
  --forest: #18342f;
  --green: #26765f;
  --amber: #d9a632;
  --blue: #315f7b;
  --red: #c64d3e;
  --shadow: 0 18px 45px rgba(24, 52, 47, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
  line-height: 1.5;
}

a {
  color: inherit;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 104px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 760;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--subtle);
}

.public-frame {
  min-height: 100vh;
}

.app-frame {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: var(--forest);
  color: #fff;
  overflow-y: auto;
}

.app-brand,
.mini-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.app-brand {
  margin-bottom: 24px;
}

.app-brand img,
.mini-brand img {
  width: 46px;
  height: 46px;
}

.app-brand strong {
  display: block;
}

.app-brand small {
  display: block;
  color: rgba(255, 255, 255, 0.7);
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 40px;
  margin: 3px 0;
  padding: 9px 11px;
  border-radius: 7px;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  font-weight: 760;
}

.nav-link:hover,
.nav-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
}

.sidebar-foot {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  display: grid;
  gap: 8px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
}

.sidebar-foot a {
  color: #fff;
  font-weight: 780;
  text-decoration: none;
}

.app-main {
  min-width: 0;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 74px;
  padding: 15px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 246, 240, 0.94);
  backdrop-filter: blur(14px);
}

.app-topbar h1 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.15;
}

.app-topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 5px auto;
  background: var(--forest);
}

.page-content {
  width: min(100% - 36px, 1320px);
  margin: 0 auto;
  padding: 26px 0 54px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  align-items: center;
  gap: 34px;
  width: min(100% - 36px, 1120px);
  margin: 0 auto;
  padding: 48px 0;
}

.login-copy {
  padding: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #18342f, #2f7a67 68%, #315f7b);
  box-shadow: var(--shadow);
}

.login-copy h1 {
  max-width: 640px;
  margin: 42px 0 14px;
  font-size: 3rem;
  line-height: 1.02;
}

.login-copy p {
  max-width: 620px;
  color: rgba(255, 255, 255, 0.82);
}

.login-demo {
  display: grid;
  gap: 8px;
  max-width: 360px;
  margin-top: 30px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.login-demo span {
  color: rgba(255, 255, 255, 0.82);
}

.login-card,
.panel,
.stat-card,
.announcement-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 34px rgba(24, 52, 47, 0.06);
}

.login-card {
  display: grid;
  gap: 16px;
  padding: 28px;
}

.login-card h2,
.panel h2,
.announcement-card h2 {
  margin: 0;
  font-size: 1.08rem;
}

.panel {
  min-width: 0;
  padding: 20px;
}

.panel + .panel,
.grid + .panel,
.stat-grid + .panel,
.panel + .grid,
.sos-trigger + .sos-grid {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head span,
.panel-head a,
.fineprint {
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-head a {
  font-weight: 780;
  text-decoration: none;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat-grid.compact {
  margin-bottom: 12px;
}

.stat-grid.compact .stat-card {
  min-height: 96px;
}

.stat-card {
  min-height: 120px;
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 780;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.9rem;
  line-height: 1;
}

.stat-card small {
  display: block;
  margin-top: 9px;
  color: var(--subtle);
}

.stat-card.green {
  border-color: rgba(38, 118, 95, 0.34);
}

.stat-card.amber {
  border-color: rgba(217, 166, 50, 0.45);
}

.stat-card.red {
  border-color: rgba(198, 77, 62, 0.32);
}

.table-wrap {
  overflow-x: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 13px;
  align-items: end;
}

.form-grid .wide {
  grid-column: span 2;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.filters,
.inline-form,
.button-row,
.mini-search {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.filters label {
  min-width: min(260px, 100%);
}

.inline-form {
  align-items: center;
}

.wide-inline {
  margin-top: 12px;
}

.wide-inline input {
  max-width: 240px;
}

.button-row.tight {
  gap: 6px;
}

.family-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.action-details summary {
  list-style: none;
  cursor: pointer;
}

.action-details summary::-webkit-details-marker {
  display: none;
}

.family-edit-form {
  display: grid;
  gap: 8px;
  width: min(340px, 78vw);
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.family-edit-form label {
  font-size: 0.8rem;
}

.attachment-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--forest);
  font-size: 0.78rem;
  font-weight: 820;
  text-decoration: none;
  max-width: 240px;
  overflow-wrap: anywhere;
}

.attachment-link span {
  color: var(--subtle);
  font-weight: 760;
  white-space: nowrap;
}

.receipt-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.receipt-action-form input {
  min-width: 180px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--forest);
  background: #fff;
  text-decoration: none;
  font-weight: 820;
  cursor: pointer;
}

.button.primary {
  border-color: var(--forest);
  color: #fff;
  background: var(--forest);
}

.button.danger {
  border-color: var(--red);
  color: #fff;
  background: var(--red);
}

.button.quiet {
  background: transparent;
}

.button.small {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 0.82rem;
}

.button.full {
  width: 100%;
}

.pill,
.readonly-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 6px;
  background: #eef4f0;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 840;
  white-space: nowrap;
}

.status-pending,
.status-partial,
.status-open,
.status-scheduled,
.status-in_review,
.status-assigned,
.status-in_progress,
.status-checked_in,
.status-acknowledged {
  background: #fff4d9;
  color: #876100;
}

.status-rejected,
.status-expired,
.status-cancelled,
.status-blacklisted,
.status-inactive,
.status-lost_rfid,
.status-denied,
.status-active {
  background: #ffe8e3;
  color: var(--red);
}

.status-exit,
.status-entered,
.status-approved,
.status-paid,
.status-completed,
.status-resolved,
.status-entry,
.status-checked_out,
.status-closed {
  background: #e6f4ef;
  color: var(--green);
}

.vehicle-gate-actions {
  display: grid;
  gap: 7px;
}

.warning-text {
  display: block;
  color: var(--red);
  font-weight: 760;
}

.flash {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 7px;
  font-weight: 760;
}

.flash.ok {
  color: var(--green);
  background: #eaf6f1;
}

.flash.error {
  color: var(--red);
  background: #fff0ec;
}

.notice-list,
.complaint-list,
.incident-list,
.checkpoint-list,
.sos-grid,
.announcement-grid,
.notification-list {
  display: grid;
  gap: 14px;
}

.account-summary {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.account-summary p {
  margin: 0;
}

.aging-table {
  margin-top: 12px;
}

.patrol-shift-action {
  margin-top: 12px;
}

.receipt-doc {
  max-width: 820px;
  margin: 0 auto;
}

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

.notice-item,
.announcement-card {
  padding: 16px;
}

.notice-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.notice-item span,
.announcement-card span,
.complaint-card span {
  color: var(--subtle);
  font-size: 0.82rem;
}

.notice-item strong {
  display: block;
  margin-top: 4px;
}

.notice-item p,
.announcement-card p,
.complaint-card p,
.sos-card p {
  color: var(--muted);
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.announcement-card.pinned {
  border-color: rgba(217, 166, 50, 0.5);
}

.notification-card.unread {
  border-color: rgba(49, 95, 123, 0.36);
  background: #fbfdfc;
}

.notification-card.priority-urgent {
  border-color: rgba(198, 77, 62, 0.44);
}

.notification-card.priority-high {
  border-color: rgba(217, 166, 50, 0.52);
}

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

.check input {
  width: auto;
  min-height: auto;
}

.alert-panel {
  border-color: rgba(198, 77, 62, 0.28);
}

.scan-panel {
  border-color: rgba(49, 95, 123, 0.28);
}

.scan-result.ok {
  border-color: rgba(38, 118, 95, 0.38);
}

.scan-result.warn {
  border-color: rgba(217, 166, 50, 0.48);
}

.scan-result.danger {
  border-color: rgba(198, 77, 62, 0.45);
}

.scan-result.muted {
  border-color: var(--line);
}

.scan-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.scan-qr {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.scan-qr img {
  width: 190px;
  height: 190px;
}

.scan-actions {
  margin-top: 14px;
}

.detail-list {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 12px 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
}

.sos-list {
  display: grid;
  gap: 10px;
}

.sos-item {
  padding: 13px;
  border: 1px solid #ffd7cf;
  border-radius: 7px;
  background: #fff4f1;
}

.sos-item span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.sos-trigger {
  border-color: rgba(198, 77, 62, 0.35);
}

.sos-trigger form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.sos-trigger .fineprint {
  grid-column: 1 / -1;
}

.sos-hold {
  min-height: 58px;
  border: 0;
  border-radius: 7px;
  color: #fff;
  background: var(--red);
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
}

.sos-hold.arming {
  background: #9f362c;
}

.sos-card {
  border-color: rgba(198, 77, 62, 0.24);
}

.pass-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.pass-card {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}

.pass-card > img:first-child {
  width: 68px;
  height: 68px;
}

.pass-qr {
  width: 220px;
  height: 220px;
  margin: 20px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pass-code {
  color: var(--forest);
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.pass-card dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px;
  text-align: left;
}

.pass-card dt {
  color: var(--muted);
  font-weight: 780;
}

.pass-card dd {
  margin: 0;
}

@media (max-width: 1180px) {
  .stat-grid,
  .grid.three,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .login-shell,
  .grid.two,
  .announcement-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    display: none;
    position: fixed;
    inset: 74px 12px auto 12px;
    z-index: 20;
    height: auto;
    max-height: calc(100vh - 88px);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .app-sidebar.open {
    display: block;
  }

  .icon-button {
    display: block;
  }

  .app-topbar {
    padding: 13px 16px;
  }

  .app-topbar .button {
    display: none;
  }

  .topbar-actions .button.primary {
    display: inline-flex;
  }

  .page-content {
    width: min(100% - 26px, 1320px);
    padding-top: 18px;
  }

  .stat-grid,
  .form-grid,
  .sos-trigger form {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .login-copy {
    padding: 28px;
  }

  .login-copy h1 {
    font-size: 2.2rem;
  }

  .scan-layout {
    grid-template-columns: 1fr;
  }

  .filters,
  .inline-form,
  .button-row,
  .mini-search {
    align-items: stretch;
  }

  .inline-form input,
  .inline-form select,
  .inline-form button,
  .button-row .button,
  .button-row form,
  .family-actions,
  .family-actions form,
  .family-actions details {
    width: 100%;
  }

.family-edit-form {
    width: 100%;
  }
}

.offline-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.offline-page .panel {
  max-width: 520px;
}

.community-switcher {
  display: flex;
  gap: 8px;
  align-items: center;
}

.community-switcher select {
  min-width: 180px;
}
