/* ========== Design Tokens ========== */
:root {
  --sidebar-bg: #ffffff;
  --sidebar-hover: #f0ede6;
  --sidebar-active: #000000;
  --sidebar-text: #000000;
  --sidebar-text-bright: #000000;
  --sidebar-width: 260px;
  --content-bg: #f6f3ec;
  --card-bg: #ffffff;
  --accent: #000000;
  --accent-hover: #000000;
  --accent-light: #f0ede6;
  --male-bg: #f0ede6;
  --male-border: #d9d3c8;
  --female-bg: #f3efe7;
  --female-border: #d9d3c8;
  --text-primary: #000000;
  --text-secondary: #948e83;
  --text-muted: #948e83;
  --border: #d9d3c8;
  --radius: 12px;
  --radius-sm: 8px;
  --header-height: 69px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --transition: 0.2s ease;
}

/* ========== Reset & Base ========== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 0.9375rem;
  color: var(--text-primary);
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hover);
}

/* ========== Layout Shell ========== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-shell.auth-page {
  background: var(--content-bg);
  justify-content: center;
  align-items: center;
}

.auth-content {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
}

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: 10px 0 22px rgba(0, 0, 0, 0.08);
}

.sidebar-brand {
  height: var(--header-height);
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-icon {
  width: 30px;
  height: 30px;
  background: #000;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-weight: 700;
}

.sidebar-brand-icon svg {
  width: 15px;
  height: 15px;
  color: #fff;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--sidebar-text-bright);
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 12px 6px;
  margin-top: 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  margin-bottom: 2px;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-link .link-icon {
  width: 20px;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.7;
}

.sidebar-link.active .link-icon,
.sidebar-link:hover .link-icon {
  opacity: 1;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}

.sidebar-footer {
  padding: 16px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--content-bg);
  border: 1px solid var(--border);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
}

.sidebar-user-avatar svg {
  width: 18px;
  height: 18px;
  color: #fff;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sidebar-text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-logout {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  text-align: center;
  background: #000;
  border: 1px solid #000;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.sidebar-logout:hover {
  background: #000;
  border-color: #000;
  color: #fff;
}

/* ========== Content Area ========== */
.content-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--header-height);
}

.content-header {
  background: var(--card-bg);
  height: var(--header-height);
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  z-index: 50;
}

.content-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.content-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.content-header .breadcrumb-text {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.content-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content-body {
  flex: 1;
  padding: 28px;
}

/* ========== Cards ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: transparent;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.5;
}

.btn-primary {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-primary:hover {
  background: #000;
  border-color: #000;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.btn-outline-primary {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-outline-primary:hover {
  background: #000;
  color: #fff;
}

.btn-outline-secondary {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-outline-secondary:hover {
  background: #000;
  color: #fff;
}

.btn-outline-danger {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-outline-danger:hover {
  background: #000;
  color: #fff;
}

.btn-outline-success {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-outline-success:hover {
  background: #000;
  color: #fff;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.72rem;
  border-radius: 6px;
}

.btn-block {
  width: 100%;
}

/* ========== Forms ========== */
.form-control,
.form-select {
  width: 100%;
  padding: 9px 14px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 18px;
}

textarea.form-control {
  resize: vertical;
  min-height: 70px;
}

/* ========== Alerts ========== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  border: 1px solid transparent;
  margin-bottom: 16px;
}

.alert-success {
  background: var(--content-bg);
  color: var(--text-primary);
  border-color: var(--border);
}

.alert-danger {
  background: var(--content-bg);
  color: var(--text-primary);
  border-color: var(--border);
}

.alert-warning {
  background: var(--content-bg);
  color: var(--text-primary);
  border-color: var(--border);
}

.alert-info {
  background: var(--content-bg);
  color: var(--text-primary);
  border-color: var(--border);
}

.alert-dismissible {
  position: relative;
  padding-right: 40px;
}

.alert-dismissible .btn-close {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
  padding: 0;
}

.alert-dismissible .btn-close:hover {
  opacity: 1;
}

/* ========== Auth Pages ========== */
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
}

.auth-card h3 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.auth-card .auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 28px;
}

.auth-card .form-group {
  margin-bottom: 20px;
}

.auth-card .btn-primary {
  width: 100%;
  padding: 11px;
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 4px;
}

.auth-card .auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========== Dashboard Grid ========== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.tree-card {
  cursor: pointer;
}

.tree-card h5 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 600;
}

.tree-card .tree-card-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.tree-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tree-card .card-footer {
  border-top: none;
}

/* ========== Form Card (create tree, member form) ========== */
.form-card {
  max-width: 640px;
  margin: 0 auto;
}

.form-card .form-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 24px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.form-card .form-section-title:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.form-card .form-actions {
  margin-top: 24px;
  display: flex;
  gap: 10px;
}

/* ========== Member Detail ========== */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.detail-value {
  color: var(--text-primary);
  font-weight: 500;
}

/* ========== Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}

.badge-male {
  background: var(--male-bg);
  color: var(--text-primary);
}

.badge-female {
  background: var(--female-bg);
  color: var(--text-primary);
}

.badge-gen {
  background: var(--accent-light);
  color: var(--text-primary);
}

/* ========== Member Card (tree nodes) ========== */
.member-node {
  display: inline-block;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  min-width: 110px;
  max-width: 180px;
  position: relative;
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: default;
  text-align: center;
}

.member-node:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.member-node.male {
  background: var(--male-bg);
  border-color: var(--male-border);
}

.member-node.female {
  background: var(--female-bg);
  border-color: var(--female-border);
}

.member-node .member-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.member-node .member-info {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.member-node .spouse-row {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.member-node .spouse-divider {
  display: inline-block;
  width: 1px;
  height: 12px;
  background: var(--border);
  margin: 0 6px;
  vertical-align: middle;
}

.member-node-actions {
  margin-top: 6px;
  display: flex;
  justify-content: center;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.member-node:hover .member-node-actions {
  opacity: 1;
}

/* ========== Tree Container ========== */
.tree-container {
  overflow-x: auto;
  padding: 24px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ========== Search ========== */
.search-row {
  display: flex;
  gap: 10px;
  max-width: 360px;
}

.search-row .btn {
  white-space: nowrap;
  writing-mode: horizontal-tb;
}

.search-results {
  margin-bottom: 16px;
}

.search-results .search-result-link {
  display: inline-block;
  padding: 4px 12px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 0.82rem;
  margin: 4px 4px 4px 0;
  text-decoration: none;
  font-weight: 500;
}

.search-results .search-result-link:hover {
  background: var(--accent);
  color: #fff;
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state h4 {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-weight: 600;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ========== Children Badges ========== */
.children-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.child-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
}

.child-badge.male {
  background: var(--male-bg);
  color: var(--text-primary);
  border: 1px solid var(--male-border);
}

.child-badge.female {
  background: var(--female-bg);
  color: var(--text-primary);
  border: 1px solid var(--female-border);
}

.child-badge:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* ========== Mobile Sidebar Toggle ========== */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-primary);
  padding: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .content-wrapper {
    margin-left: 0;
  }

  .content-header {
    left: 0;
    width: 100%;
  }

  .sidebar-toggle {
    display: block;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* ========== Utility ========== */
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.w-100 { width: 100%; }
.small { font-size: 0.82rem; }
.fw-bold { font-weight: 600; }
