:root {
  --ch-primary: #2563eb;
  --ch-primary-dark: #1d4ed8;
  --ch-primary-soft: #eff6ff;
  --ch-ink: #172033;
  --ch-muted: #667085;
  --ch-border: #e4eaf2;
  --ch-surface: #ffffff;
  --ch-canvas: #f6f8fc;
  --ch-success: #15803d;
  --ch-shadow: 0 14px 40px rgba(23, 32, 51, 0.08);
  --ch-radius: 1rem;
  --ch-nav-bg: rgba(255, 255, 255, 0.97);
  --ch-nav-link: #475467;
  --ch-hero-border: #dbe7f8;
  --ch-hero-bg: linear-gradient(120deg, #f8fbff 0%, #eef5ff 55%, #f7faff 100%);
  --ch-table-heading: #f9fafc;
  --ch-table-hover: #fbfcff;
  --ch-table-text: #344054;
  --ch-table-divider: #edf0f5;
  --ch-footer-bg: #fff;
}

[data-bs-theme="dark"] {
  --ch-primary-dark: #a9c9ff;
  --ch-primary-soft: #19365a;
  --ch-ink: #edf4ff;
  --ch-muted: #b7c6d9;
  --ch-border: #34465e;
  --ch-surface: #142136;
  --ch-canvas: #0c1626;
  --ch-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
  --ch-nav-bg: rgba(16, 28, 46, 0.98);
  --ch-nav-link: #d2deed;
  --ch-hero-border: #304967;
  --ch-hero-bg: linear-gradient(120deg, #111f34 0%, #182d49 55%, #102038 100%);
  --ch-table-heading: #1b2d47;
  --ch-table-hover: #1a304a;
  --ch-table-text: #e0e9f5;
  --ch-table-divider: #34465e;
  --ch-footer-bg: #101c2e;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ch-ink);
  background: var(--ch-canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

main { flex: 1; }
.container, .row, .col, .stat-card > div:last-child { min-width: 0; }

a { text-underline-offset: 0.2em; }

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1100;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  color: #fff;
  background: var(--ch-ink);
  transform: translateY(-160%);
  transition: transform 120ms ease;
}

.skip-link:focus { transform: translateY(0); }

.app-navbar {
  min-height: 74px;
  border-bottom: 1px solid var(--ch-border);
  background: var(--ch-nav-bg);
}

.nav-controls { flex: 0 0 auto; }
.theme-toggle {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid var(--ch-border);
  border-radius: 0.65rem;
  padding: 0.5rem 0.75rem;
  color: var(--ch-ink);
  background: var(--ch-surface);
  font-size: 0.84rem;
  font-weight: 700;
}
.theme-toggle:hover { border-color: var(--ch-primary-dark); background: var(--ch-primary-soft); }
.theme-toggle:focus-visible { outline: 3px solid var(--ch-primary-dark); outline-offset: 2px; }
.theme-icon { width: 1.1rem; height: 1.1rem; flex: 0 0 auto; }
.theme-icon-moon, [data-bs-theme="dark"] .theme-icon-sun { display: none; }
[data-bs-theme="dark"] .theme-icon-moon { display: block; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ch-ink);
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: inline-grid;
  width: 2.45rem;
  height: 2.45rem;
  place-items: center;
  border-radius: 0.75rem;
  color: #fff;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.app-navbar .nav-link {
  border-radius: 0.55rem;
  color: var(--ch-nav-link);
  font-weight: 650;
  padding: 0.55rem 0.9rem !important;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus-visible,
.app-navbar .nav-link.active {
  color: var(--ch-primary-dark);
  background: var(--ch-primary-soft);
}

.page-hero,
.compact-hero {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--ch-hero-border);
  background: var(--ch-hero-bg);
}

.page-hero::after,
.compact-hero::after {
  position: absolute;
  top: -7rem;
  right: 2%;
  width: 22rem;
  height: 22rem;
  border: 1px solid rgba(37, 99, 235, 0.1);
  border-radius: 50%;
  content: "";
  box-shadow: 0 0 0 4rem rgba(37, 99, 235, 0.03), 0 0 0 8rem rgba(37, 99, 235, 0.02);
}

.page-hero .container,
.compact-hero .container { position: relative; z-index: 1; }
.page-hero { padding: 4rem 0; }
.compact-hero { padding: 3rem 0; }

.eyebrow,
.section-kicker {
  color: var(--ch-primary-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.display-title {
  max-width: 790px;
  overflow-wrap: anywhere;
  font-size: clamp(1.85rem, 4vw, 2.75rem);
  font-weight: 780;
  letter-spacing: -0.04em;
  line-height: 1.12;
}

.hero-copy { color: var(--ch-muted); font-size: 1.05rem; }
.page-content { padding-top: 2rem; padding-bottom: 4rem; }

.btn {
  border-radius: 0.65rem;
  font-weight: 650;
  padding: 0.62rem 1rem;
}

.btn-primary { border-color: var(--ch-primary); color: #fff; background: var(--ch-primary); }
.btn-primary:hover, .btn-primary:focus { border-color: #1d4ed8; color: #fff; background: #1d4ed8; }
.btn-outline-primary { border-color: #b8cdf6; color: #1d4ed8; }
.btn-outline-primary:hover { border-color: var(--ch-primary); background: var(--ch-primary); }

.action-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.78rem 1.2rem;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.2);
  font-size: 1rem;
}

.action-button svg { width: 1.15rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }

.demo-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  border: 1px solid #bfdbfe;
  border-radius: 0.8rem;
  padding: 0.85rem 1rem;
  color: #1e3a5f;
  background: #eff6ff;
  font-size: 0.9rem;
}

.notice-icon {
  display: inline-grid;
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--ch-primary);
  font-size: 0.72rem;
  font-weight: 800;
}

.stat-card,
.content-card,
.quick-card {
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius);
  background: var(--ch-surface);
  box-shadow: var(--ch-shadow);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
}

.stat-icon {
  display: grid;
  width: 3.75rem;
  height: 3.75rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 1rem;
}

.stat-icon svg { width: 1.65rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.75; }
.stat-icon-blue { color: #2563eb; background: #eff6ff; }
.stat-icon-green { color: #15803d; background: #edf9f0; }
.stat-label { margin-bottom: 0.15rem; color: var(--ch-muted); font-size: 0.9rem; font-weight: 650; }
.stat-value { margin-bottom: 0.25rem; font-size: 2.1rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.stat-link { color: var(--ch-primary-dark); font-size: 0.87rem; font-weight: 700; text-decoration: none; }
.stat-caption { color: var(--ch-muted); font-size: 0.87rem; }

.content-card { min-width: 0; }
.card-heading { padding: 1.35rem 1.5rem; }
.section-title { font-size: 1.3rem; font-weight: 760; letter-spacing: -0.025em; }

.table-responsive { overflow-x: auto; }
#contactsTableWrap { max-height: min(68vh, 42rem); overflow: auto; }
.contact-table { min-width: 760px; --bs-table-bg: transparent; --bs-table-color: var(--ch-table-text); }
#contactsTableWrap .contact-table { min-width: 960px; }
.contact-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom-color: var(--ch-border);
  padding: 0.85rem 1rem;
  color: #667085;
  background: var(--ch-table-heading);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  white-space: nowrap;
}

.contact-table tbody td {
  border-bottom-color: var(--ch-table-divider);
  padding: 1rem;
  color: var(--ch-table-text);
  font-size: 0.9rem;
  vertical-align: middle;
}

.contact-table tbody tr:last-child td { border-bottom: 0; }
.contact-table tbody tr:hover td { background: var(--ch-table-hover); }

.contact-person { display: flex; align-items: center; gap: 0.75rem; min-width: 180px; }
.avatar {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #1d4ed8;
  background: #e8f0ff;
  font-size: 0.72rem;
  font-weight: 800;
}
.person-name { color: var(--ch-ink); font-weight: 720; }
.person-email { display: block; max-width: 250px; overflow: hidden; color: var(--ch-muted); font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.contact-id { color: #667085; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; }

.category-badge {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.28rem 0.62rem;
  font-size: 0.75rem;
  font-weight: 750;
}
.category-family { border-color: #fbcfe8; color: #9d174d; background: #fdf2f8; }
.category-friends { border-color: #bbf7d0; color: #166534; background: #f0fdf4; }
.category-work { border-color: #bfdbfe; color: #1e40af; background: #eff6ff; }
.category-others { border-color: #e5e7eb; color: #4b5563; background: #f9fafb; }

.quick-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.65rem;
  color: #fff;
  border-color: transparent;
  background: linear-gradient(115deg, #1e40af, #2563eb 60%, #3b82f6);
}
.quick-card .section-kicker, .quick-card .text-secondary { color: rgba(255, 255, 255, 0.78) !important; }
.quick-button { flex-shrink: 0; color: #1d4ed8; }

.filter-group { width: 100%; max-width: 640px; min-width: 0; }
.filter-group .form-select { min-width: 180px; }
.search-field { position: relative; flex: 1; min-width: 0; }
.search-field svg { position: absolute; top: 50%; left: 0.85rem; width: 1.05rem; fill: none; stroke: #667085; stroke-linecap: round; stroke-width: 1.8; transform: translateY(-50%); }
.search-field .form-control { padding-left: 2.5rem; }

.form-control, .form-select {
  min-height: 44px;
  border-color: #d0d5dd;
  border-radius: 0.6rem;
  color: var(--ch-ink);
}
.form-control:focus, .form-select:focus { border-color: #6ea0f7; box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.12); }
.form-label { margin-bottom: 0.4rem; color: #344054; font-size: 0.88rem; font-weight: 700; }
.required-mark { color: #dc2626; }
.optional-label { color: #98a2b3; font-size: 0.76rem; font-weight: 500; }

.results-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.reset-link { padding: 0; text-decoration: none; }
.action-group { display: inline-flex; justify-content: flex-end; gap: 0.4rem; white-space: nowrap; }
.table-action { display: inline-flex; align-items: center; gap: 0.3rem; border-radius: 0.5rem; padding: 0.42rem 0.6rem; font-size: 0.78rem; }
.table-action svg { width: 0.9rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }

.empty-state { padding: 3.5rem 1.5rem; text-align: center; }
.empty-state h3 { margin-bottom: 0.4rem; font-size: 1.12rem; font-weight: 750; }
.empty-state p { color: var(--ch-muted); }
.empty-icon {
  display: grid;
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 1rem;
  place-items: center;
  border: 1px dashed #93b4ef;
  border-radius: 50%;
  color: var(--ch-primary);
  background: var(--ch-primary-soft);
  font-size: 1.6rem;
}

.modal-content { max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); border: 0; border-radius: 1rem; box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22); }
#contactModal .modal-content > form { display: flex; min-height: 0; flex-direction: column; }
#contactModal .modal-body { min-height: 0; overflow-y: auto; }
.modal-header, .modal-body, .modal-footer { padding-left: 1.5rem; padding-right: 1.5rem; }
.modal-header { border-bottom-color: var(--ch-border); padding-top: 1.25rem; padding-bottom: 1.1rem; }
.modal-footer { border-top-color: var(--ch-border); flex-wrap: wrap; }
.delete-icon { display: grid; width: 3.5rem; height: 3.5rem; margin-bottom: 1.2rem; place-items: center; border-radius: 50%; color: #b42318; background: #fef3f2; }
.delete-icon svg { width: 1.45rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.toast { border: 0; border-radius: 0.75rem; box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18); }
.toast-success { color: #14532d; background: #f0fdf4; }
.toast-error { color: #991b1b; background: #fef2f2; }

.app-footer {
  border-top: 1px solid var(--ch-border);
  padding: 1.35rem 0;
  color: var(--ch-muted);
  background: var(--ch-footer-bg);
  font-size: 0.82rem;
}

[data-bs-theme="dark"] .skip-link { color: #0c1626; background: #edf4ff; }
[data-bs-theme="dark"] .brand-lockup:hover,
[data-bs-theme="dark"] .brand-lockup:focus { color: var(--ch-ink); }
[data-bs-theme="dark"] .demo-notice { border-color: #41668a; color: #e2edfc; background: #17324e; }
[data-bs-theme="dark"] .btn-outline-primary { border-color: #7aaaf2; color: #b8d4ff; }
[data-bs-theme="dark"] .btn-outline-primary:hover,
[data-bs-theme="dark"] .btn-outline-primary:focus { color: #fff; background: #1d4ed8; }
[data-bs-theme="dark"] .btn-outline-secondary { border-color: #8498b2; color: #edf4ff; }
[data-bs-theme="dark"] .btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn-outline-secondary:focus { color: #fff; background: #34465e; }
[data-bs-theme="dark"] .stat-icon-blue { color: #b8d4ff; background: #1b395f; }
[data-bs-theme="dark"] .stat-icon-green { color: #9ce3b4; background: #1a4938; }
[data-bs-theme="dark"] .contact-table thead th { color: #c4d3e5; }
[data-bs-theme="dark"] .avatar { color: #c8deff; background: #1b3b63; }
[data-bs-theme="dark"] .contact-id { color: #b7c6d9; }
[data-bs-theme="dark"] .category-family { border-color: #874d74; color: #ffd2e9; background: #4b2340; }
[data-bs-theme="dark"] .category-friends { border-color: #44745b; color: #c0f1d0; background: #1d4330; }
[data-bs-theme="dark"] .category-work { border-color: #496ca4; color: #c8ddff; background: #1c375f; }
[data-bs-theme="dark"] .category-others { border-color: #68778d; color: #e4eaf4; background: #344258; }
[data-bs-theme="dark"] .search-field svg { stroke: #b7c6d9; }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select { border-color: #62748b; color: var(--ch-ink); background-color: #101c2e; }
[data-bs-theme="dark"] .form-control::placeholder { color: #a7b8cd; opacity: 1; }
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus { border-color: #a9c9ff; box-shadow: 0 0 0 0.22rem rgba(169, 201, 255, 0.2); }
[data-bs-theme="dark"] .form-label { color: #e0e9f5; }
[data-bs-theme="dark"] .optional-label { color: #adbed2; }
[data-bs-theme="dark"] .required-mark { color: #ff9b9b; }
[data-bs-theme="dark"] .empty-icon { border-color: #7699c8; }
[data-bs-theme="dark"] .modal-content { color: var(--ch-ink); background: var(--ch-surface); }
[data-bs-theme="dark"] .toast-success { color: #d1f6dd; background: #194433; }
[data-bs-theme="dark"] .toast-error { color: #ffe0de; background: #5a292d; }

@media (max-width: 767.98px) {
  .app-navbar .navbar-collapse { padding: 0.8rem 0 0.4rem; }
  .page-hero, .compact-hero { padding: 2.5rem 0; }
  .page-content { padding-top: 1.25rem; padding-bottom: 2.5rem; }
  .page-hero .action-button, .compact-hero .action-button { width: 100%; }
  #contactsTableWrap { max-height: none; overflow-x: auto; overflow-y: visible; }
  .stat-card { align-items: flex-start; }
  .card-heading { padding: 1.1rem; }
  .quick-card { align-items: flex-start; flex-direction: column; }
  .quick-button { width: 100%; }
  .filter-group { max-width: none; }
  .filter-group > div, .filter-group .form-select { width: 100%; min-width: 0; }
  .results-row { align-items: flex-start; flex-direction: column; }
  .modal-header, .modal-body, .modal-footer { padding-left: 1rem; padding-right: 1rem; }
}

@media (max-width: 420px) {
  .brand-lockup { gap: 0.5rem; font-size: 1rem; }
  .brand-mark { width: 2.2rem; height: 2.2rem; }
  .theme-toggle { width: 2.75rem; padding: 0.5rem; }
  .theme-label { display: none; }
  .navbar-toggler { padding: 0.4rem 0.55rem; }
  .stat-card { gap: 0.9rem; padding: 1.15rem; }
  .stat-icon { width: 3.1rem; height: 3.1rem; }
  .display-title { font-size: 1.8rem; }
  .modal-footer > .btn { flex: 1 1 100%; }
}

@media (max-height: 520px) {
  .modal-dialog-centered { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
