:root,
[data-theme='dark'] {
  --bg: #1c1d20;
  --surface: #24262a;
  --surface-soft: #2c2f34;
  --surface-hover: #343942;
  --border: #353940;
  --text: #e7e9ee;
  --text-soft: #aeb3bb;
  --text-muted: #7f858f;
  --accent: #7ea0e8;
  --accent-hover: #6f93de;
  --header-bg: rgba(24, 26, 29, 0.94);
  --footer-height: 86px;
}

[data-theme='light'] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #eef2fb;
  --surface-hover: #e5ecfb;
  --border: #d3ddee;
  --text: #222a37;
  --text-soft: #5c6983;
  --text-muted: #8893a8;
  --accent: #6f93de;
  --accent-hover: #6186d4;
  --header-bg: rgba(255, 255, 255, 0.94);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  overflow-x: hidden;
}

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.002em;
  background: radial-gradient(circle at 12% 0%, rgba(126, 160, 232, 0.08), transparent 40%), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.desktop-sidebar { display: none; }

.topbar {
  position: relative;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  min-height: 52px;
  padding: 0 14px;
  display: flex;
  align-items: center;
}

.topbar-inline {
  justify-content: space-between;
}

.brand {
  text-decoration: none;
  font-size: 1.03rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.topbar-right-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.logout-inline { margin: 0; }

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn:hover,
.icon-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.page-content {
  padding: 0;
  padding-bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0));
}

.card-soft {
  background: linear-gradient(180deg, var(--surface), var(--surface-soft));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}

.page-surface { margin: 0; }
.text-soft { color: var(--text-soft); }
.text-accent { color: var(--accent); }
.min-vh-70 { min-height: 70vh; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-accent:hover,
.btn-accent:focus {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-outline-light {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.btn-outline-light:hover,
.btn-outline-light:focus {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
}

[data-theme='light'] .btn-outline-light {
  border-color: #b7c5df;
  color: #4c5e7a;
}

[data-theme='light'] .btn-outline-light:hover,
[data-theme='light'] .btn-outline-light:focus {
  background: #eef3fc;
  border-color: var(--accent);
  color: #344866;
}

.form-control,
.form-select,
.input-group-text {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.form-control::placeholder { color: var(--text-muted); }
.input-group-text { color: var(--text-muted); }

.form-control:focus,
.form-select:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 0.18rem rgba(126, 160, 232, 0.14);
  color: var(--text);
}

.resident-list {
  display: grid;
  gap: 8px;
}

.resident-list-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  min-height: 64px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
}

.resident-list-item:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.resident-list-main { min-width: 0; }

.resident-list-name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resident-list-sphere {
  font-size: 0.86rem;
  color: var(--text-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resident-photo-wrap {
  width: 390px;
  max-width: 100%;
}

.resident-photo {
  width: 100%;
  height: 520px;
  object-fit: contain;
  object-position: center;
  border-radius: 0;
  border: none;
  background: transparent;
  display: block;
}

.resident-photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
}

.info-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.info-value { font-size: 0.96rem; }

.info-value-bio {
  white-space: pre-line;
}

.post-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
}

.post-image {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 12px;
  object-fit: cover;
}

.event-post-datetime {
  text-align: center;
  margin-top: -2px;
  margin-bottom: 12px;
}

.event-post-text {
  white-space: pre-line;
}

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

.calendar-row {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 12px;
}

.calendar-row-link {
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s ease;
}

.calendar-row-link:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
  color: var(--text);
}

.calendar-date {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
}

.partner-group-title {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 10px 2px 6px;
}

.view-toggle .btn { min-width: 42px; }

.list-group-soft .list-group-item {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.list-group-soft .list-group-item:hover {
  background: var(--surface-hover);
}

.mobile-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
}

.footer-btn {
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-soft);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 600;
}

.footer-btn i { font-size: 1.02rem; }

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

.events-submenu-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.26);
  z-index: 29;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.events-submenu-sheet.open {
  opacity: 1;
  visibility: visible;
}

.events-submenu-card {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.more-submenu-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.26);
  z-index: 29;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.more-submenu-sheet.open {
  opacity: 1;
  visibility: visible;
}

.more-submenu-card {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--footer-height) + env(safe-area-inset-bottom, 0));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.events-submenu-card a {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.more-submenu-card a {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.events-submenu-card a.active,
.events-submenu-card a:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.more-submenu-card a.active,
.more-submenu-card a:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

@media (max-width: 768px) {
  .resident-photo-wrap {
    width: 390px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: center;
  }

  .resident-photo {
    height: 390px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .resident-list-item {
    min-height: 62px;
    border-radius: 10px;
  }

  .calendar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 42px;
  }
}

@media (min-width: 992px) {
  .layout-shell {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - 52px);
  }

  .desktop-sidebar {
    display: block;
    width: 248px;
    flex: 0 0 248px;
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface), var(--surface-soft));
    position: sticky;
    top: 0;
    max-height: calc(100vh - 52px);
    overflow-y: auto;
  }

  .desktop-sidebar-nav {
    display: grid;
    gap: 6px;
    padding: 10px;
  }

  .desktop-nav-group {
    display: grid;
    gap: 6px;
    margin-bottom: 2px;
  }

  .desktop-nav-group-title {
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    font-size: 0.86rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .desktop-nav-group-toggle {
    list-style: none;
    cursor: pointer;
    justify-content: space-between;
  }

  .desktop-nav-group-toggle::-webkit-details-marker {
    display: none;
  }

  .desktop-nav-group-main {
    display: inline-flex;
    align-items: center;
    gap: 10px;
  }

  .desktop-nav-group-chevron {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
  }

  .desktop-nav-group[open] .desktop-nav-group-chevron {
    transform: rotate(180deg);
  }

  .desktop-sidebar-nav a {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-soft);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
  }

  .desktop-nav-group > a {
    margin-left: 10px;
  }

  .desktop-sidebar-nav a:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--surface-hover);
  }

  .desktop-sidebar-nav a.active {
    border-color: var(--accent);
    color: #fff;
    background: var(--accent);
  }

  .page-content {
    flex: 1;
    padding-bottom: 20px;
  }

  .events-feed,
  .post-page-wrap {
    max-width: 720px;
    margin: 0 auto;
  }

  .events-feed .post-card,
  .post-page-wrap .post-card {
    max-width: 640px;
    margin: 0 auto;
  }

  .mobile-footer,
  .events-submenu-sheet,
  .more-submenu-sheet {
    display: none !important;
  }
}
