:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #e2e8f0;
  --line-hover: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #eff6ff;
  --accent: #f59e0b;
  --danger: #ef4444;
  --ok: #10b981;
  --side-bg: #ffffff;
  --side-line: #e2e8f0;

  /* Layout */
  --sidebar-w: 260px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--side-bg);
  border-right: 1px solid var(--side-line);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}

/* Main Content Wrapper */
.main-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Global Topbar */
.global-topbar {
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

/* Top Search */
.top-search {
  width: 240px;
  background: #f1f5f9;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  transition: all .2s;
}

.top-search:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  width: 300px;
}

.breadcrumb {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

.breadcrumb strong {
  color: var(--text);
  font-weight: 600;
}

/* Mobile Topbar overrides */
.mobile-only {
  display: none;
}

.menu-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  z-index: 41;
  /* keep button clickable */
}

/* Sidebar Brand */
.brand {
  margin: 0;
  font-size: 20px;
  color: var(--text);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  word-break: keep-all;
  line-height: 1.2;
}

.brand-sub {
  margin: 6px 0 16px;
  color: var(--muted);
  font-size: 13px;
}

/* Removed side search to top nav */

/* Category & Tools Navigation */
.side-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .8px;
  text-transform: uppercase;
  font-weight: 700;
}

.tool-group {
  margin-bottom: 20px;
}

.tool-link {
  display: block;
  text-decoration: none;
  color: #334155;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  margin-bottom: 4px;
  transition: all .15s ease;
}

.tool-link:hover {
  background: #f8fafc;
  color: var(--brand);
}

.tool-link.active {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: #bfdbfe;
  font-weight: 600;
}

.tool-placeholder {
  display: block;
  color: #94a3b8;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  background: #f8fafc;
}

/* Main Content Header Title within .main */
.header-title-wrapper {
  margin-bottom: 24px;
}

.header-title-wrapper h1 {
  margin: 0;
  font-size: 28px;
  color: var(--text);
  letter-spacing: -0.5px;
}

.header-title-wrapper p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.sponsor-trigger,
.contact-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.sponsor-trigger {
  color: #ef4444;
  border: 1px solid #fecaca;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.1);
}

.sponsor-trigger:hover {
  background: #fef2f2;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

.contact-trigger {
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.contact-trigger:hover {
  background: #f8fafc;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Modal/Popover */
.sponsor-popover,
.contact-popover {
  position: absolute;
  top: 60px;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  display: none;
  z-index: 50;
  text-align: center;
  width: 320px;
}

.sponsor-popover.active,
.contact-popover.active {
  display: block;
  animation: fadeInDown 0.2s ease-out;
}

.sponsor-popover h3,
.contact-popover h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 16px;
}

.sponsor-popover p,
.contact-popover p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.sponsor-qrs {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.qr-box img {
  width: 110px;
  height: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
}

.qr-box span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* General Layout Main Content */
.main {
  padding: 24px 32px;
  max-width: 100%;
}

@media (max-width: 1050px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.05);
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: flex;
  }

  .global-topbar {
    padding: 0 16px;
    gap: 10px;
  }

  .top-search {
    width: 140px;
  }

  .top-search:focus {
    width: 180px;
  }

  .main {
    padding: 16px;
  }

  .sponsor-trigger span.text,
  .contact-trigger span.text {
    display: none;
  }

  .topbar-right {
    gap: 8px;
  }

  .contact-trigger,
  .sponsor-trigger {
    padding: 8px 12px;
    min-width: 44px;
    justify-content: center;
  }

  .sponsor-popover,
  .contact-popover {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 40px);
    max-width: 340px;
    right: auto;
  }

  .sponsor-popover.active,
  .contact-popover.active {
    animation: popIn 0.2s ease-out;
  }

  /* Overlay */
  .overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 90;
    display: none;
    backdrop-filter: blur(2px);
  }

  .overlay.active {
    display: block;
  }
}

@media (max-width: 760px) {
  .global-topbar {
    padding: 0 10px;
    gap: 8px;
  }

  .topbar-left {
    gap: 10px;
  }

  .brand {
    font-size: 16px;
  }

  .topbar-right {
    gap: 6px;
  }

  .top-search {
    width: min(36vw, 140px);
    padding: 8px 10px;
  }

  .top-search:focus {
    width: min(42vw, 160px);
  }

  .contact-trigger,
  .sponsor-trigger {
    padding: 8px 10px;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}
