/* ==== CAT DEV PLATFORM — MONO DARK SYSTEM ==== */

/* ---------- 1. DESIGN TOKENS (MONOCHROME & BLUE ACCENTS) ---------- */
:root {
  /* Mono Dark Palette */
  --bg-body: #0a0a0a;
  --bg-surface: #121212;
  --bg-surface-elevated: #1a1a1a;
  --bg-subtle: #1f1f1f;

  --border-subtle: #262626;
  --border-strong: #333333;

  --text-main: #ededed;
  --text-muted: #888888;
  --text-inverse: #000000;

  /* Blue Accents: Phân tách rõ ràng giữa Hover và Active */
  --blue-hover: #38bdf8;   /* Xanh sky sáng dịu khi hover */
  --blue-active: #0070f3;  /* Xanh electric chuẩn nét khi active */

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --shell-max: 1240px;
  --topbar-h: 64px;

  /* Triệt tiêu bo góc theo yêu cầu phẳng sắc nét */
  --radius-none: 0px;

  --transition-fast: 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- 2. RESET & BASE ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
  background-color: var(--bg-body);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  border-radius: var(--radius-none);
}

/* ---------- 3. CONTAINER ---------- */
.shell-container {
  width: 100%;
  max-width: var(--shell-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: 24px;
  padding-right: 24px;
}

/* ---------- 4. TOPBAR (HEADER) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-shrink: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-logo-img {
  display: block;
  object-fit: contain;
}

.brand-name {
  white-space: nowrap;
}

/* ---------- MENU CHÍNH ---------- */
#menu,
.nav-menu {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--topbar-h);
}

#menu > a,
#menu > .has-sub > a,
.nav-menu > a,
.nav-menu > .has-sub > a {
  display: inline-flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  transition: color var(--transition-fast);
  white-space: nowrap;
  position: relative;
}

/* Hover: Xanh sáng dịu */
#menu > a:hover,
#menu > .has-sub > a:hover,
.nav-menu > a:hover,
.nav-menu > .has-sub > a:hover {
  color: var(--blue-hover) !important;
}

/* Active: Xanh electric */
#menu > a.active,
#menu > .has-sub > a.active,
.nav-menu > a.active,
.nav-menu > .has-sub > a.active {
  color: var(--blue-active) !important;
  font-weight: 600;
}

/* Vạch line tinh tế dưới chân menu khi active */
#menu > a.active::after,
#menu > .has-sub > a.active::after,
.nav-menu > a.active::after,
.nav-menu > .has-sub > a.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 14px;
  right: 14px;
  height: 2px;
  background-color: var(--blue-active);
}

/* ---------- SUBMENU DROPDOWN (FIX HOVER RỚT & BỎ BO GÓC) ---------- */
.has-sub {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.submenu {
  display: block;
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-none);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.7);
  padding: 4px 0;
  list-style: none;
  z-index: 120;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}

/* Cầu nối vô hình chống rớt chuột giữa menu cha và menu con */
.submenu::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: transparent;
}

/* Kích hoạt mượt mà khi hover hoặc focus */
.has-sub:hover .submenu,
.has-sub:focus-within .submenu {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.submenu li {
  margin: 0;
}

.submenu a {
  display: block;
  padding: 10px 18px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-radius: var(--radius-none);
  transition: color var(--transition-fast), background var(--transition-fast);
}

/* Submenu Hover: Nền đen xám nhạt, chữ xanh sky */
.submenu a:hover {
  color: var(--blue-hover);
  background: var(--bg-surface-elevated);
}

/* Submenu Active: Chữ xanh electric */
.submenu a.active {
  color: var(--blue-active);
  font-weight: 600;
  background: var(--bg-subtle);
}

/* Cụm Giữa: Search Slot */
.header-center {
  flex: 1;
  max-width: 380px;
  display: flex;
  justify-content: center;
}

.search-slot {
  width: 100%;
}

.search-slot:empty {
  display: none;
}

/* Cụm Phải: Auth Actions */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- 4.1 AUTH AREA (header right) ---------- */
.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-area:empty {
  display: none;
}

/* Not logged in: 2 buttons */
.auth-guest {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-guest a {
  text-decoration: none;
}

/* Logged in: avatar + username + dropdown */
.auth-user {
  position: relative;
}

.auth-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.auth-user-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
}

.auth-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
}

.auth-avatar-placeholder {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue-active);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}

.auth-username {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-main);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Dropdown */
.auth-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 6px 0;
  z-index: 220;
  list-style: none;
  margin: 0;
}

.auth-user.open .auth-dropdown {
  display: block;
}

.auth-dropdown a,
.auth-dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  font-size: 13.5px;
  color: var(--text-muted);
  text-decoration: none;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.auth-dropdown a:hover,
.auth-dropdown button:hover {
  color: var(--blue-hover);
  background: var(--bg-surface-elevated);
}

.auth-dropdown .auth-dropdown-sep {
  height: 1px;
  background: var(--border-subtle);
  margin: 6px 0;
}

.auth-dropdown-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}

/* Mobile: ẩn username, giữ avatar */
@media (max-width: 880px) {
  .auth-username {
    display: none;
  }

  .auth-user-btn {
    padding: 4px;
  }
}

/* ---------- 5. BUTTONS (MONO SHARP) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  border-radius: var(--radius-none);
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}

.btn-sm {
  padding: 7px 16px;
  font-size: 13px;
  letter-spacing: 0.2px;
}

.btn-ghost {
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  color: #fff;
  border-color: var(--border-subtle);
  background: var(--bg-surface);
}

.btn-primary {
  background: var(--text-main);
  color: var(--text-inverse);
  font-weight: 600;
  border: 1px solid var(--text-main);
}

.btn-primary:hover {
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.2);
}

.menu-toggle {
  display: none;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}

.hamburger-box {
  width: 18px;
  height: 12px;
  position: relative;
  display: block;
  flex-shrink: 0;
}

.hamburger-inner,
.hamburger-inner::before,
.hamburger-inner::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background-color: var(--text-main);
  transition: transform var(--transition-fast);
}

/* 3 dòng: top | middle | bottom — centered trong box 12px */
.hamburger-inner { top: 5px; }
.hamburger-inner::before { top: -5px; }
.hamburger-inner::after { top: 5px; }

/* ---------- 6. NỘI DUNG CHÍNH (#main & CÁC TRANG CON) ---------- */
#main,
.main-content {
  flex: 1;
  width: 100%;
  max-width: var(--shell-max);
  margin-left: auto;
  margin-right: auto;
  padding: 52px 24px 80px 24px;
}

#main h1, .main-content h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.25;
  margin-bottom: 16px;
  color: #fff;
}

#main h2, .main-content h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-top: 40px;
  margin-bottom: 14px;
  color: #fff;
}

#main h3, .main-content h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 10px;
  color: #fff;
}

#main p, .main-content p {
  margin-bottom: 16px;
  color: var(--text-muted);
  line-height: 1.7;
}

#main strong, .main-content strong {
  color: #fff;
  font-weight: 600;
}

/* Link nội dung trang con */
#main a, .main-content a {
  color: var(--text-main);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

#main a:hover, .main-content a:hover {
  color: var(--blue-hover);
}

#main hr, .main-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 36px 0;
}

#main section, .main-content section {
  margin-bottom: 36px;
}

#main ul, #main ol,
.main-content ul, .main-content ol {
  padding-left: 24px;
  margin-bottom: 24px;
  color: var(--text-muted);
}

#main li, .main-content li {
  margin-bottom: 8px;
  line-height: 1.6;
}

#main code, .main-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 2px 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-none);
  color: #ededed;
}

/* ---------- 7. STATE HELPERS & SLOTS ---------- */
.loading,
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  color: var(--text-muted);
  font-style: italic;
}

.error {
  padding: 16px 20px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius-none);
  color: #fca5a5;
}

.plugin-slot {
  margin-top: 24px;
  padding: 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-none);
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.plugin-slot:not(:empty) {
  padding: 0;
  border: none;
  text-align: left;
}

/* ---------- 8. FOOTER ---------- */
.footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 24px 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
}

/* Footer menu — inline ngang, góc phải */
.footer-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.footer-menu a {
  font-size: 12.5px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
  position: relative;
}

.footer-menu a:hover {
  color: var(--blue-hover);
}

.footer-menu a.active {
  color: var(--blue-active);
  font-weight: 500;
}

/* Dấu phân cách giữa các item (trừ item cuối) */
.footer-menu a + a::before,
.footer-menu .has-sub + .has-sub::before,
.footer-menu a + .has-sub::before,
.footer-menu .has-sub + a::before {
  content: "·";
  color: var(--border-strong);
  margin-right: 8px;
  font-weight: 700;
}

/* Footer menu không có dropdown — nếu item có children, hiện inline */
.footer-menu .has-sub {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.footer-menu .submenu {
  display: inline-flex;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 8px;
}

/* Mobile: menu xuống dòng, căn giữa */
@media (max-width: 640px) {
  .footer-inner {
    justify-content: center;
    text-align: center;
  }

  .footer-menu {
    justify-content: center;
  }
}

/* ---------- 9. BACK-TO-TOP ---------- */
#back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-none);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-strong);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  z-index: 150;
  transition: all var(--transition-fast);
}

#back-to-top.visible { display: flex; }
#back-to-top:hover {
  background: var(--bg-subtle);
  border-color: var(--blue-hover);
  color: var(--blue-hover);
}
#back-to-top svg { width: 16px; height: 16px; }

/* ---------- 10. RESPONSIVE ---------- */
@media (max-width: 880px) {
  .header-center {
    order: 3;
    max-width: 100%;
    width: 100%;
  }

  .menu-toggle {
    display: flex;
  }

  #menu,
  .nav-menu {
    display: none;
    position: absolute;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-strong);
    flex-direction: column;
    align-items: stretch;
    height: auto;
    padding: 12px;
    gap: 4px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
  }

  #menu.open,
  .nav-menu.open {
    display: flex;
  }

  #menu > a,
  #menu > .has-sub > a,
  .nav-menu > a,
  .nav-menu > .has-sub > a {
    width: 100%;
    height: 40px;
    padding: 0 14px;
  }

  #menu > a.active::after,
  #menu > .has-sub > a.active::after,
  .nav-menu > a.active::after,
  .nav-menu > .has-sub > a.active::after {
    display: none;
  }

  .submenu {
    position: static;
    display: block;
    visibility: visible;
    opacity: 1;
    transform: none;
    box-shadow: none;
    background: transparent;
    border: none;
    padding-left: 16px;
  }

  .submenu::before {
    display: none;
  }
}