﻿/* Shared layout, navigation, search and theme styles. */
:root {
  --topbar-height: 58px;
  --floating-control-top: 66px;
  --blog-layout-width: 1320px;
  --blog-bg: #fff;
  --blog-surface: #fff;
  --blog-surface-soft: #f8fafc;
  --blog-footer-bg: #fafafa;
  --blog-heading: #111827;
  --blog-text: #2c3e50;
  --blog-muted: #6b7280;
  --blog-border: #e5e7eb;
  --blog-accent: #3bbf87;
  --blog-accent-strong: #16875b;
  --blog-sidebar: #f8fafc;
  --blog-active: #e2f6ee;
  --blog-shadow: rgba(15, 23, 42, 0.08);
  --blog-code-bg: #f3f4f6;
  --blog-quote-bg: #f8fafc;
  --blog-overlay: rgba(15, 23, 42, 0.28);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --blog-bg: #111827;
  --blog-surface: #172033;
  --blog-surface-soft: #1f2937;
  --blog-footer-bg: #101827;
  --blog-heading: #f8fafc;
  --blog-text: #e5e7eb;
  --blog-muted: #aeb8c8;
  --blog-border: #334155;
  --blog-accent: #48d597;
  --blog-accent-strong: #2faf75;
  --blog-sidebar: #151e2f;
  --blog-active: rgba(72, 213, 151, 0.14);
  --blog-shadow: rgba(0, 0, 0, 0.28);
  --blog-code-bg: #0f172a;
  --blog-quote-bg: #182235;
  --blog-overlay: rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --blog-bg: #111827;
    --blog-surface: #172033;
    --blog-surface-soft: #1f2937;
    --blog-footer-bg: #101827;
    --blog-heading: #f8fafc;
    --blog-text: #e5e7eb;
    --blog-muted: #aeb8c8;
    --blog-border: #334155;
    --blog-accent: #48d597;
    --blog-accent-strong: #2faf75;
    --blog-sidebar: #151e2f;
    --blog-active: rgba(72, 213, 151, 0.14);
    --blog-shadow: rgba(0, 0, 0, 0.28);
    --blog-code-bg: #0f172a;
    --blog-quote-bg: #182235;
    --blog-overlay: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100vw;
}

body {
  max-width: 100vw;
  margin: 0;
  color: var(--blog-text);
  background: var(--blog-bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.topbar {
  min-height: 58px;
  background: var(--blog-surface) !important;
  border-color: var(--blog-border) !important;
  box-shadow: 0 2px 10px var(--blog-shadow);
}

.topbar .container-fluid {
  position: relative;
  width: min(100%, var(--blog-layout-width));
  margin: 0 auto;
  padding-right: 24px;
  padding-left: 24px;
}

.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--blog-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.brand-logo {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 1.35em;
  height: 1.35em;
  overflow: hidden;
  border-radius: 7px;
}

.brand-logo-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-logo-fallback {
  display: grid;
  position: relative;
  width: 100%;
  height: 100%;
  place-items: center;
  background: linear-gradient(135deg, #16a34a, #0ea5e9 58%, #f59e0b);
  color: #fff;
  line-height: 1;
}

.brand-logo-fallback::before,
.brand-logo-fallback::after {
  content: "";
  position: absolute;
  border-radius: 4px;
}

.brand-logo-fallback::before {
  width: 58%;
  height: 58%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.brand-logo-fallback::after {
  right: 18%;
  top: 18%;
  width: 26%;
  height: 26%;
  background: rgba(255, 255, 255, 0.92);
}

.brand-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-link {
  color: var(--blog-muted);
}

.nav-link:hover,
.nav-link.active {
  color: var(--blog-accent);
}

.blog-nav-dropdown {
  position: relative;
}

.blog-nav-menu {
  min-width: 210px;
  padding: 10px 0;
  border: 1px solid var(--blog-border);
  border-radius: 8px;
  background: var(--blog-surface);
  box-shadow: 0 14px 34px var(--blog-shadow);
}

.blog-nav-heading {
  padding: 10px 18px 6px;
  color: var(--blog-muted);
  font-size: 0.78rem;
}

.blog-nav-divider {
  margin: 8px 0;
  border-color: var(--blog-border);
}

.blog-nav-link {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 18px;
  color: var(--blog-text);
}

.blog-nav-link:hover,
.blog-nav-link:focus {
  color: var(--blog-accent-strong);
  background: var(--blog-active);
}

.blog-nav-external {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.nav-external-icon {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  fill: currentColor;
  opacity: 0.62;
}

.navbar-toggler {
  border-color: var(--blog-border);
}

:root[data-theme="dark"] .navbar-toggler-icon {
  filter: invert(1);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .navbar-toggler-icon {
    filter: invert(1);
  }
}

@media (min-width: 992px) {
  .blog-nav-dropdown:hover > .blog-nav-menu {
    display: block;
  }

  .blog-nav-dropdown:hover > .blog-nav-trigger {
    color: var(--blog-accent);
  }
}

@media (max-width: 991.98px) {
  .topbar .blog-nav-menu {
    position: static;
    width: 100%;
    margin: 4px 0 8px;
    border-radius: 8px;
    box-shadow: none;
  }
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
}

.search-switcher {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
}

.blog-search-toggle {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--blog-muted);
}

.blog-search-toggle:hover,
.blog-search-toggle.active {
  color: var(--blog-accent-strong);
  border-color: var(--blog-border);
  background: var(--blog-surface-soft);
}

.blog-search-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.blog-search-backdrop {
  position: fixed;
  inset: var(--topbar-height) 0 0;
  z-index: 1030;
  background: transparent;
}

.blog-search-panel {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  right: max(16px, calc((100vw - var(--blog-layout-width)) / 2 + 24px));
  z-index: 1040;
  width: min(460px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - var(--topbar-height) - 28px));
  overflow: hidden;
  border: 1px solid var(--blog-border);
  border-radius: 8px;
  background: var(--blog-surface);
  box-shadow: 0 20px 44px var(--blog-shadow);
}

.blog-search-panel[hidden],
.blog-search-backdrop[hidden] {
  display: none;
}

.blog-search-form {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--blog-border);
}

.blog-search-form svg {
  width: 18px;
  height: 18px;
  fill: var(--blog-muted);
}

.blog-search-form input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--blog-text);
  font: inherit;
}

.blog-search-form input::-webkit-search-cancel-button {
  display: none;
}

.blog-search-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--blog-border);
  border-radius: 8px;
  background: var(--blog-surface-soft);
  color: var(--blog-muted);
  font-size: 1.25rem;
  line-height: 1;
}

.blog-search-close:hover {
  color: var(--blog-accent-strong);
}

.blog-search-results {
  max-height: min(560px, calc(100vh - var(--topbar-height) - 112px));
  overflow: auto;
  padding: 8px;
}

.blog-search-panel.is-loading .blog-search-results {
  opacity: 0.75;
}

.blog-search-hint {
  margin: 0;
  padding: 18px 12px;
  color: var(--blog-muted);
  text-align: center;
}

.blog-search-result {
  padding: 12px;
  border-radius: 8px;
}

.blog-search-result:hover {
  background: var(--blog-surface-soft);
}

.blog-search-result-title {
  display: block;
  color: var(--blog-heading);
  font-weight: 700;
  line-height: 1.35;
  text-decoration: none;
}

.blog-search-result-title:hover {
  color: var(--blog-accent-strong);
}

.blog-search-result p {
  display: -webkit-box;
  margin: 6px 0 8px;
  overflow: hidden;
  color: var(--blog-muted);
  line-height: 1.6;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.blog-search-result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--blog-muted);
  font-size: 0.84rem;
}

.blog-search-result-meta a {
  color: var(--blog-accent-strong);
  text-decoration: none;
}

.theme-toggle-switch {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

.theme-toggle-track {
  position: relative;
  display: block;
  width: 50px;
  height: 26px;
  border: 1px solid var(--blog-border);
  border-radius: 999px;
  background: var(--blog-surface-soft);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  color: var(--blog-muted);
  background: var(--blog-surface);
  box-shadow: 0 1px 4px var(--blog-shadow);
  transition: transform 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle-switch:hover .theme-toggle-track {
  border-color: var(--blog-accent);
}

.theme-toggle-switch[data-theme-state="light"] .theme-toggle-thumb {
  color: #d97706;
  transform: translateX(12px);
}

.theme-toggle-switch[data-theme-state="dark"] .theme-toggle-thumb {
  color: #4f46e5;
  transform: translateX(24px);
}

.theme-toggle-state {
  display: none;
}

.theme-toggle-switch[data-theme-state="system"] .theme-toggle-auto,
.theme-toggle-switch[data-theme-state="light"] .theme-toggle-light,
.theme-toggle-switch[data-theme-state="dark"] .theme-toggle-dark {
  display: block;
}

.theme-toggle-state svg,
.theme-toggle-thumb svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.theme-toggle-auto {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: lowercase;
}

@media (max-width: 991.98px) {
  .search-switcher {
    margin: 8px 0 0;
  }

  .theme-switcher {
    margin: 8px 0 0;
  }
}


.blog-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  padding: 18px;
  color: var(--blog-muted);
  border-top: 1px solid var(--blog-border);
  background: var(--blog-footer-bg);
}

.back-top-button {
  position: fixed;
  right: 0;
  bottom: 32px;
  z-index: 50;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--blog-accent-strong);
  border-radius: 8px;
  background: var(--blog-accent-strong);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.back-top-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-top-button:hover {
  background: var(--blog-accent);
}

.back-top-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}


@media (max-width: 820px) {
  :root {
    --topbar-height: 58px;
    --floating-control-top: 72px;
  }

  .topbar .container-fluid {
    flex-wrap: nowrap;
    min-width: 0;
    padding-right: 12px;
    padding-left: 12px;
  }

  .navbar-brand {
    max-width: calc(100vw - 92px);
  }

  .navbar-toggler {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .topbar .navbar-collapse {
    position: absolute;
    top: 100%;
    right: 8px;
    left: 8px;
    z-index: 80;
    padding: 8px 12px 12px;
    border: 1px solid var(--blog-border);
    border-radius: 8px;
    background: var(--blog-surface);
    box-shadow: 0 12px 28px var(--blog-shadow);
  }

  .back-top-button {
    right: 12px;
    bottom: 24px;
  }
}
