:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a1f2e;
  --muted: #5c6578;
  --border: #dde3ea;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(180deg, #eef2f7 0%, var(--bg) 240px);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.site-header {
  padding: 2rem 0 1.25rem;
}

.site-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.02em;
}

.site-header p {
  margin: 0;
  color: var(--muted);
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters {
  padding: 1rem;
  margin-bottom: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--accent);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field-wide {
  grid-column: 1 / -1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #f8fafc;
}

.btn-danger {
  background: #fff;
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger:hover {
  background: #fef2f2;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.stats-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.stats-bar strong {
  color: var(--text);
}

.residents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  padding-bottom: 2.5rem;
}

.resident-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.resident-card-top {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.avatar {
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #eef2f7;
  border: 1px solid var(--border);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar--sm {
  width: 44px;
  height: 44px;
}

.avatar--md {
  width: 56px;
  height: 56px;
}

.avatar--empty {
  background:
    linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  position: relative;
}

.avatar--empty::after {
  content: "";
  position: absolute;
  inset: 22% 28%;
  border: 2px solid #cbd5e1;
  border-radius: 999px 999px 0 0;
}

.avatar--empty::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 16%;
  width: 58%;
  height: 34%;
  transform: translateX(-50%);
  border: 2px solid #cbd5e1;
  border-radius: 999px 999px 0 0;
}

.profile-photo {
  width: 120px;
  height: 120px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #eef2f7;
  flex-shrink: 0;
}

.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-photo--empty {
  background:
    linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  position: relative;
}

.profile-photo--empty::after {
  content: "";
  position: absolute;
  inset: 24% 30%;
  border: 2px solid #cbd5e1;
  border-radius: 999px 999px 0 0;
}

.profile-photo--empty::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 18%;
  width: 56%;
  height: 32%;
  transform: translateX(-50%);
  border: 2px solid #cbd5e1;
  border-radius: 999px 999px 0 0;
}

.profile-photo--loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2f7;
}

.profile-photo--loading::after {
  content: "";
  width: 24px;
  height: 24px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: photo-preview-spin 0.7s linear infinite;
}

@keyframes photo-preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.photo-editor {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.photo-editor .profile-photo {
  width: 88px;
  height: 88px;
}

.admin-photo-cell {
  width: 52px;
}

.family-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.family-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 0.65rem;
  align-items: end;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fbfdff;
}

.cars-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.car-row {
  display: grid;
  grid-template-columns: minmax(0, 220px) auto;
  gap: 0.65rem;
  align-items: end;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fbfdff;
}

@media (max-width: 720px) {
  .family-row {
    grid-template-columns: 1fr;
  }

  .car-row {
    grid-template-columns: 1fr auto;
  }
}

.family-row .family-remove {
  min-width: 36px;
  padding-inline: 0.5rem;
  margin-bottom: 0.1rem;
}

.detail-family-list {
  margin: 0;
  padding-left: 1.1rem;
}

.detail-family-list li {
  margin-bottom: 0.25rem;
}

@media (max-width: 720px) {
  .family-row {
    grid-template-columns: 1fr;
  }
}

.resident-card:hover {
  transform: translateY(-2px);
  border-color: #bfd3ff;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.12);
}

.resident-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.apartment-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.card-meta {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.card-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--surface);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  padding: 1.25rem;
}

.modal-resident {
  width: min(720px, 100%);
}

.modal-header--close-only {
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.modal-resident-head {
  margin-bottom: 1.25rem;
}

.modal-resident-head h2 {
  margin: 0.5rem 0 0;
  font-size: 1.5rem;
}

.modal-resident-head .apartment-badge {
  margin-bottom: 0;
}

.modal-resident-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.modal-resident-layout #modal-photo .profile-photo {
  width: 220px;
  height: 280px;
  border-radius: 18px;
}

.modal-wide {
  width: min(720px, 100%);
}

@media (max-width: 560px) {
  .modal-resident-layout {
    grid-template-columns: 1fr;
  }

  .modal-resident-layout #modal-photo .profile-photo {
    width: 100%;
    max-width: 240px;
    height: 300px;
    margin: 0 auto;
  }
}

.modal-subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.modal-close {
  border: none;
  background: #f1f5f9;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.detail-list {
  display: grid;
  gap: 0.85rem;
}

.detail-item {
  display: grid;
  gap: 0.2rem;
}

.detail-item dt {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.detail-item dd {
  margin: 0;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.chip-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 600;
}

.chip-link:hover {
  background: var(--accent-soft);
  border-color: #bfdbfe;
  text-decoration: none;
}

/* Admin */

.admin-layout {
  padding-bottom: 3rem;
}

.login-box {
  width: min(420px, 100%);
  margin: 4rem auto;
  padding: 1.5rem;
}

.login-box h2 {
  margin: 0 0 0.5rem;
}

.login-box p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.admin-table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

tr:hover td {
  background: #fbfdff;
}

.table-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  padding: 1rem;
}

.form-grid .field-wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0 1rem 1rem;
}

.form-hint {
  margin: 0 1rem 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.form-notice {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a5f;
  font-size: 0.92rem;
  line-height: 1.45;
}

.section-header {
  padding: 1rem 1rem 0.5rem;
}

.section-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1;
}

.requests-list {
  display: grid;
  gap: 0.85rem;
  padding: 0.75rem 1rem 1rem;
}

.request-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  background: #fbfdff;
}

.request-card-header h3 {
  margin: 0.35rem 0 0.15rem;
}

.request-card-header {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}
.profile-photo--sm {
  width: 72px;
  height: 72px;
}

.request-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.request-type {
  display: inline-flex;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.request-type.is-new {
  background: #dcfce7;
  color: var(--success);
}

.request-type.is-update {
  background: #fef3c7;
  color: #b45309;
}

.request-type.is-reset {
  background: #ede9fe;
  color: #6d28d9;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.6rem;
}

.checkbox-field input {
  width: auto;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #111827;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr;
  }
}
