:root {
  color-scheme: light;
  --page-bg: #fff;
  --surface-bg: #fff;
  --surface-muted: #f8f9fa;
  --text-color: #212529;
  --muted-color: #6c757d;
  --border-color: #dee2e6;
  --link-color: #0d6efd;
  --shadow-color: rgba(0, 0, 0, .12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #101418;
  --surface-bg: #171d23;
  --surface-muted: #202832;
  --text-color: #edf2f7;
  --muted-color: #a9b4c0;
  --border-color: #33404d;
  --link-color: #8ab4ff;
  --shadow-color: rgba(0, 0, 0, .45);
}

body {
  background: var(--page-bg);
  color: var(--text-color);
}

a {
  color: var(--link-color);
}

.page-wrapper {
  min-height: 80vh;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  background-color: var(--surface-bg);
  border-color: var(--border-color) !important;
}

.card,
.card-header,
.card-footer,
.list-group-item,
.form-control,
.form-select,
.dropdown-menu,
.alert-light {
  background-color: var(--surface-bg);
  border-color: var(--border-color);
  color: var(--text-color);
}

.form-control:focus,
.form-select:focus,
textarea.form-control:focus {
  background-color: var(--surface-bg);
  border-color: var(--link-color);
  color: var(--text-color);
  box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--link-color) 25%, transparent);
}

.form-control::placeholder,
textarea.form-control::placeholder {
  color: var(--muted-color);
  opacity: 1;
}

.bg-white {
  background-color: var(--surface-bg) !important;
}

.bg-light {
  background-color: var(--surface-muted) !important;
}

.text-muted,
.text-body-secondary,
.link-dark,
.nav-link.link-dark {
  color: var(--muted-color) !important;
}

.text-dark,
.site-header a.text-dark,
.mobile-logo-link {
  color: var(--text-color) !important;
}

.form-control:disabled,
.form-select:disabled {
  background-color: var(--surface-muted);
}

.border,
.border-top,
.border-bottom {
  border-color: var(--border-color) !important;
}

.latest-visited-panel {
  padding: 0;
}

.latest-visited-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1rem;
}

.latest-visited-panel-header h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  font-weight: 500;
}

.latest-visited-panel-header span {
  min-width: 1.75rem;
  padding: .15rem .45rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted-color);
  font-size: .8rem;
  text-align: center;
}

.latest-visited-list {
  display: grid;
  gap: .35rem;
}

.latest-visited-user {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 18px;
  align-items: center;
  gap: .65rem;
  padding: .45rem;
  border-radius: 8px;
  color: var(--text-color);
  text-decoration: none;
}

.latest-visited-user:hover {
  background: var(--surface-muted);
  color: var(--link-color);
}

.latest-visited-user img {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
}

.latest-visited-user-body {
  min-width: 0;
}

.latest-visited-user-body strong,
.latest-visited-user-body small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-visited-user-body small {
  color: var(--muted-color);
  font-size: .8rem;
}

.latest-visited-user user-icon {
  color: var(--muted-color);
}

.user-menu-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.user-menu-dropdown summary {
  list-style: none;
}

.user-menu-dropdown summary::-webkit-details-marker {
  display: none;
}

.user-menu-trigger {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid #ced4da;
  overflow: hidden;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  background-color: var(--surface-bg);
  border: 1px solid var(--border-color);
  border-radius: .5rem;
  box-shadow: 0 8px 24px var(--shadow-color);
  padding: .4rem 0;
  z-index: 1050;
}

.user-menu-link {
  display: flex;
  align-items: center;
  color: var(--text-color);
  text-decoration: none;
  padding: .45rem .75rem;
  font-size: .95rem;
}

.user-menu-link:hover {
  background-color: var(--surface-muted);
}

.theme-toggle,
.header-icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-bg);
  color: var(--text-color);
  cursor: pointer;
  text-decoration: none;
}

.header-icon-button:hover {
  color: var(--link-color);
}

.theme-toggle [data-theme-icon-light] {
  display: none;
}

:root[data-theme="dark"] .theme-toggle [data-theme-icon-dark] {
  display: none;
}

:root[data-theme="dark"] .theme-toggle [data-theme-icon-light] {
  display: inline-flex;
}

@media (max-width: 767.98px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  body > footer {
    display: none !important;
  }

  .mobile-logo-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    margin-bottom: 1rem;
    padding: 0 12px;
    background: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
  }

  .mobile-logo-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    text-decoration: none;
  }

  .mobile-header-avatar {
    display: block;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-muted);
  }

  .mobile-theme-toggle {
    position: absolute;
    right: 60px;
  }

  .mobile-logout-button {
    position: absolute;
    right: 106px;
  }

  .mobile-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .mobile-header-auth {
    display: flex;
    align-items: center;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    min-height: calc(64px + env(safe-area-inset-bottom));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .08);
  }

  .mobile-bottom-nav-link {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    color: var(--text-color);
    text-decoration: none;
    font-size: .72rem;
    line-height: 1.1;
    border: 0;
    background: transparent;
  }

  .mobile-bottom-nav-link user-icon {
    font-size: 1.25rem;
    line-height: 1;
  }

  .mobile-bottom-nav-button {
    font: inherit;
  }

  .mobile-bottom-menu {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    z-index: 1050;
    padding: 8px;
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, .18);
  }

  .mobile-bottom-menu-link {
    display: flex;
    align-items: center;
    padding: .65rem .75rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 6px;
  }

  .mobile-bottom-menu-link:hover {
    background: var(--surface-muted);
  }
}
