/* Kith 1.4 — Linear / X-Grade Design Token System & Responsive App Shell (Shared Stylesheet) */

:root,
[data-theme="light"] {
  --bg-canvas: #f8f7f4;
  --bg-main: #f8f7f4;
  --bg-surface: #ffffff;
  --bg-elevated: #f1efe9;
  --bg-muted: #e8e5dd;
  --text-main: #141413;
  --text-secondary: #52514e;
  --text-muted: #787671;
  --border-color: #e4e2dd;
  --primary: #c96442;
  --primary-hover: #b55434;
  --primary-dark: #b55434;
  --primary-darker: #7c351d;
  --accent: #d4886a;
  --accent-light: rgba(201, 100, 66, 0.12);

  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 0.75rem;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.05), 0 4px 12px rgba(20, 20, 19, 0.04);
  --shadow-lg: 0 10px 30px rgba(20, 20, 19, 0.12);
  color-scheme: light;
}

[data-theme="dark"],
html.dark {
  --bg-canvas: #0b0d10;
  --bg-main: #0b0d10;
  --bg-surface: #13161b;
  --bg-elevated: #1c2027;
  --bg-muted: #252a34;
  --text-main: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border-color: rgba(255, 255, 255, 0.08);
  --primary: #e07a5f;
  --primary-hover: #ec8c72;
  --primary-dark: #ec8c72;
  --primary-darker: #f3f4f6;
  --accent: #e07a5f;
  --accent-light: rgba(224, 122, 95, 0.15);

  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#app,
.kith-shell,
.kith-main-wrap {
  background-color: var(--bg-canvas) !important;
  color: var(--text-main) !important;
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  color: var(--primary-hover);
}

h1, h2, h3, h4, h5, h6, strong {
  color: var(--text-main);
}

.text-secondary {
  color: var(--text-secondary) !important;
}
.text-muted {
  color: var(--text-muted) !important;
}

/* ---------- Blazor Error UI Toast ---------- */
#blazor-error-ui {
  display: none !important;
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--danger);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-lg);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  align-items: center;
  gap: 0.75rem;
  max-width: 24rem;
}

#blazor-error-ui.show,
#blazor-error-ui[style*="display: block"],
#blazor-error-ui[style*="display:block"] {
  display: flex !important;
}

#blazor-error-ui .reload {
  font-weight: 600;
  color: var(--primary);
  text-decoration: underline;
}

#blazor-error-ui .dismiss {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  font-size: 0.9rem;
}

/* ---------- Surfaces & Cards ---------- */
.card {
  background-color: var(--bg-surface) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.card + .card {
  margin-top: 1rem;
}

.parent-box {
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 0.9rem;
  margin: 0.7rem 0;
  background-color: var(--bg-elevated);
  color: var(--text-main);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  text-decoration: none;
  line-height: 1.25;
}
.btn:hover {
  background-color: var(--bg-muted);
  color: var(--text-main);
  text-decoration: none;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #ffffff !important;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover) !important;
  border-color: var(--primary-hover) !important;
  color: #ffffff !important;
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover:not(:disabled) {
  background-color: var(--bg-elevated);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  background-color: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #ffffff !important;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 0.6rem;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Inputs & Forms ---------- */
.inp,
.input,
.select,
.textarea {
  width: 100%;
  padding: 0.55rem 0.8rem;
  font-size: 0.92rem;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  background-color: var(--bg-elevated) !important;
  color: var(--text-main) !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.inp::placeholder,
.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}
.inp:focus,
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light);
  background-color: var(--bg-surface) !important;
}

label.field,
.lbl,
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0.5rem 0 0.25rem;
}

.error-text { color: var(--danger); font-size: 0.85rem; margin: 0.25rem 0; }
.success-text { color: var(--success); font-size: 0.85rem; }

/* ---------- Pills & Badges ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  transition: all 0.15s ease;
}
.pill:hover {
  border-color: var(--primary);
  color: var(--text-main);
}
.pill.active {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #ffffff !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.6rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background-color: var(--bg-elevated);
  color: var(--text-secondary);
}
.badge-primary {
  background-color: var(--accent-light);
  border-color: transparent;
  color: var(--primary);
}
.badge-pending {
  background-color: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--warning);
}
.badge-restricted {
  background-color: var(--bg-muted);
  color: var(--text-muted);
}
.badge-award {
  background: linear-gradient(135deg, #f6d7a8, #e8b662);
  color: #4a3200;
  border-color: transparent;
}

.nav-badge {
  min-width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background-color: var(--primary);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
}

/* ---------- Navigation Links ---------- */
.navlink {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.navlink:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  text-decoration: none;
}
.navlink.active {
  background-color: var(--accent-light);
  border-color: rgba(201, 100, 66, 0.25);
  color: var(--primary);
}

/* ---------- Global Sticky Top Bar (.kith-topbar) ---------- */
.kith-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.kith-topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.02em;
  text-decoration: none;
  flex-shrink: 0;
}
.kith-topbar-brand:hover {
  color: var(--primary-hover);
  text-decoration: none;
}

.kith-topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 460px;
  margin: 0 auto;
}

.kith-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ---------- Omnisearch Bar & Popover ---------- */
.kith-omnisearch {
  position: relative;
  width: 100%;
  max-width: 460px;
}

.kith-omnisearch-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.38rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.kith-omnisearch-input-wrap:focus-within {
  background-color: var(--bg-surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.kith-omnisearch-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
}
.kith-omnisearch-input::placeholder {
  color: var(--text-muted);
}

.kith-omnisearch-popover {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 0;
  right: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-lg);
  max-height: 26rem;
  overflow-y: auto;
  z-index: 120;
  padding: 0.5rem;
}

.kith-omnisearch-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem 0.2rem;
}

.kith-omnisearch-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 0.55rem;
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
}
.kith-omnisearch-item:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  text-decoration: none;
}

/* ---------- Responsive Shell Grid (.kith-shell) ---------- */
.kith-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.kith-main {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 1.25rem 1rem 5.5rem;
}

.kith-shell-gate .kith-main-wrap {
  margin-left: 0 !important;
}
.kith-shell-gate .kith-main {
  max-width: 1120px;
  padding-bottom: 2rem;
}

/* Desktop (>= 769px) */
@media (min-width: 769px) {
  .kith-bottomnav {
    display: none !important;
  }
  .kith-sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    width: 240px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 1rem 0.75rem;
    overflow-y: auto;
    z-index: 80;
  }
  .kith-main-wrap {
    margin-left: 240px;
    flex: 1;
  }
  .kith-main {
    padding: 1.5rem 1.5rem 2.5rem;
    max-width: 820px;
  }
}

/* Mobile (<= 768px) */
@media (max-width: 768px) {
  .kith-sidebar {
    display: none !important;
  }
  .kith-main-wrap {
    margin-left: 0 !important;
    flex: 1;
  }
  .kith-bottomnav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    justify-content: space-around;
    background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    padding: 0.4rem 0 calc(0.4rem + env(safe-area-inset-bottom));
  }
  .kith-bottomnav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    position: relative;
    text-decoration: none;
  }
  .kith-bottomnav a.active {
    color: var(--primary);
  }
}

/* ---------- Public Footer (Facebook-style language + legal bar) ---------- */
.kith-public-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  padding: 1.25rem 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.kith-public-footer-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.kith-lang-link {
  background: none;
  border: none;
  padding: 0.15rem 0.35rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0.35rem;
}
.kith-lang-link:hover {
  color: var(--primary);
  text-decoration: underline;
}
.kith-lang-link.active {
  font-weight: 700;
  color: var(--primary);
}

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-panel {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  color: var(--text-main);
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: 0.75rem;
  padding: 0.65rem 0.9rem;
  margin: 0.6rem 0;
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  background-color: var(--bg-elevated);
  color: var(--text-main);
}
.alert-danger {
  background-color: rgba(220, 38, 38, 0.12);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.35);
}
.alert-info {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  border-color: var(--border-color);
}

/* ---------- Pedigree Tree ---------- */
.ped-tree { display: flex; flex-direction: column; align-items: center; gap: 0; }
.ped-tier { display: flex; justify-content: center; gap: 0.6rem; flex-wrap: wrap; }
.ped-card {
  width: 190px;
  text-align: center;
  padding: 0.65rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.85rem;
}
.ped-card.subject { border: 2px solid var(--primary); background-color: var(--bg-elevated); }
.ped-card.pending { border-color: var(--warning); }
.ped-card.restricted { opacity: 0.55; filter: grayscale(0.7); }
.ped-card.unknown { border-style: dashed; color: var(--text-muted); }
.ped-connector { width: 2px; height: 18px; background: var(--border-color); margin: 0 auto; }
.ped-hline { height: 2px; background: var(--border-color); }
.role-label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.3rem; text-align: center; }

/* ---------- Utility Classes ---------- */
.avatar { border-radius: 999px; object-fit: cover; background: var(--bg-muted); flex-shrink: 0; display: inline-block; }
.sharecode {
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  border: 1px dashed var(--border-color);
  border-radius: 0.45rem;
  padding: 0.15rem 0.45rem;
  user-select: all;
  font-size: 0.82rem;
}
.qr-box { background: #ffffff; padding: 0.75rem; border-radius: 0.75rem; display: inline-block; }
.feed-img { max-width: 100%; max-height: 520px; border-radius: 0.75rem; display: block; }
.divider { border: 0; border-top: 1px solid var(--border-color); margin: 1rem 0; }
.grid-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 0.5rem; top: 0.5rem; z-index: 200; background: var(--primary); color: #ffffff; padding: 0.5rem 1rem; border-radius: 0.5rem; }
