:root {
  --white: #ffffff;
  --gray-100: #f5f5f7;
  --gray-200: #e8e8ed;
  --gray-300: #d2d2d7;
  --gray-400: #86868b;
  --gray-500: #6e6e73;
  --gray-600: #424245;
  --gray-700: #2d2d2f;
  --gray-800: #1d1d1f;
  --black: #000000;
  --card-bg: rgba(18, 18, 20, 0.76);
  --card-border: rgba(255, 255, 255, 0.08);
  --accent: #30d158;
  --accent-2: #0a84ff;
  --warn: #ff9f0a;
  --danger: #ff453a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  min-height: 100%;
  background: #050506;
  overscroll-behavior-y: none;
}
body {
  font-family: -apple-system, 'Inter', 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background:
    radial-gradient(circle at 15% 20%, rgba(10, 132, 255, 0.18), transparent 25%),
    radial-gradient(circle at 85% 10%, rgba(48, 209, 88, 0.12), transparent 22%),
    linear-gradient(180deg, #050506 0%, #000000 100%);
  color: var(--white);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: none;
  touch-action: pan-x pan-y;
}
body::before {
  content: '';
  position: fixed;
  inset: -180px 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 20%, rgba(10, 132, 255, 0.18), transparent 25%),
    radial-gradient(circle at 85% 10%, rgba(48, 209, 88, 0.12), transparent 22%),
    linear-gradient(180deg, #050506 0%, #000000 100%);
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: radial-gradient(circle at 50% 18%, black, transparent 72%);
}
body::selection { background: rgba(255, 255, 255, 0.22); }

.ambient { position: fixed; border-radius: 999px; filter: blur(90px); pointer-events: none; opacity: 0.5; z-index: 0; }
.ambient-one { width: 320px; height: 320px; background: rgba(10, 132, 255, 0.18); top: 6%; left: -6%; }
.ambient-two { width: 280px; height: 280px; background: rgba(48, 209, 88, 0.14); right: -4%; bottom: 8%; }

.topbar {
  width: min(1200px, calc(100% - 40px));
  margin: max(20px, env(safe-area-inset-top)) auto 0;
  padding: 14px 18px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.55);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 18px;
  z-index: 20;
}

.logo-wrap { display: flex; align-items: center; gap: 14px; color: var(--white); text-decoration: none; }
.logo-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: -0.03em;
  background: linear-gradient(135deg, rgba(255,255,255,0.14), rgba(255,255,255,0.04));
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}
.logo-mark.logo-image {
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  padding: 0;
}
.logo-mark.logo-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.logo-title { font-size: 1rem; font-weight: 700; letter-spacing: -0.03em; }
.logo-sub { font-size: 0.75rem; color: var(--gray-500); }

.top-actions { display: flex; align-items: center; gap: 14px; }
.top-link {
  color: var(--gray-300);
  text-decoration: none;
  font-size: 0.86rem;
  padding: 8px 11px;
  border-radius: 12px;
}
.top-link:hover { color: var(--white); background: rgba(255,255,255,0.06); }

.lang-switch { display: flex; gap: 6px; }
.lang {
  font-family: 'JetBrains Mono', monospace;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  color: var(--gray-400);
  font-size: 0.72rem; text-decoration: none;
}
.lang.active { color: var(--white); background: rgba(255,255,255,0.1); }

.admin-nav { display: flex; flex-wrap: wrap; gap: 4px; }
.admin-nav a {
  padding: 8px 12px; border-radius: 12px;
  color: var(--gray-300); text-decoration: none;
  font-size: 0.85rem;
}
.admin-nav a:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.admin-nav a.danger { color: #ffb7b2; }

.hero-pill, .section-pill, .meta-chip, .helper-text, .mono, .section-note {
  font-family: 'JetBrains Mono', monospace;
}

.page-shell {
  width: min(1200px, calc(100% - 40px));
  margin: 30px auto 60px;
  display: grid;
  grid-template-columns: 1.06fr 0.94fr;
  gap: 20px;
  align-items: start;
  position: relative;
  z-index: 1;
}

.page-shell-single {
  width: min(1200px, calc(100% - 40px));
  margin: 30px auto 60px;
  position: relative;
  z-index: 1;
}

.single-card { display: grid; gap: 20px; }
.single-card.narrow { max-width: 640px; margin: 0 auto; }

.hero-card, .list-card {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.055), rgba(255,255,255,0.018)),
    var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 26px;
  backdrop-filter: blur(34px);
  -webkit-backdrop-filter: blur(34px);
  box-shadow: 0 24px 90px rgba(0,0,0,0.34), inset 0 1px 0 rgba(255,255,255,0.08);
  position: relative;
  overflow: hidden;
}
.hero-card { padding: 36px; }
.list-card { padding: 30px; }
.list-card.full { grid-column: 1 / -1; }

.hero-card::before, .list-card::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(circle at top right, rgba(10,132,255,0.16), transparent 32%),
    radial-gradient(circle at bottom left, rgba(48,209,88,0.08), transparent 30%);
  pointer-events: none;
}
.hero-card > *, .list-card > * { position: relative; z-index: 1; }

.hero-pill, .section-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--gray-300);
  font-size: 0.76rem;
  margin-bottom: 18px;
}

.hero-card h1, .list-card h2 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.05em;
  margin-bottom: 16px;
}
.list-card h2 { font-size: 1.55rem; margin-bottom: 0; }
.hero-copy { color: var(--gray-300); line-height: 1.6; margin: -4px 0 22px; max-width: 620px; }
.kb-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 24px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(10,132,255,0.1);
  border: 1px solid rgba(10,132,255,0.2);
  color: #cfe6ff;
}
.kb-alert strong,
.kb-alert a {
  overflow-wrap: anywhere;
  line-height: 1.25;
}
.kb-alert a { color: var(--white); font-weight: 800; text-decoration: none; }

.cta-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 8px 0 28px; }

.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  border-radius: 14px;
  padding: 14px 22px;
  font-weight: 700; font-size: 0.92rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--white), var(--gray-200));
  color: var(--black);
  box-shadow: 0 10px 34px rgba(255,255,255,0.08);
}
.btn-primary:hover { transform: translateY(-1px); opacity: 0.95; }
.btn-ghost {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--white);
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-ghost.danger { color: #ffb7b2; border-color: rgba(255,69,58,0.25); }

.link-form { margin-top: 12px; }
.link-form label { display: block; color: var(--gray-300); font-size: 0.9rem; margin-bottom: 12px; }

.input-row { display: grid; grid-template-columns: 1fr 170px; gap: 12px; }

input, select, textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--white);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--white);
  box-shadow: 0 0 0 1000px #17191f inset;
  transition: background-color 9999s ease-out;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: rgba(10, 132, 255, 0.6);
  background: rgba(255,255,255,0.06);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2386868b' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  color-scheme: dark;
}
select option {
  background: #16181e;
  color: var(--white);
}
select option:checked,
select option:hover {
  background: #2f5bd3;
  color: var(--white);
}

.input-row button {
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--white), var(--gray-200));
  color: var(--black);
  border-radius: 14px;
  padding: 14px 20px;
  font-weight: 700;
  font-family: inherit;
}

.form { display: grid; gap: 14px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field { display: grid; gap: 8px; }
.form-field label { color: var(--gray-300); font-size: 0.85rem; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; }
.ai-draft-form { margin-top: 14px; flex-wrap: wrap; }

.kb-search {
  display: grid;
  grid-template-columns: 1fr 180px 220px 130px;
  gap: 12px;
  margin-top: 22px;
}
.kb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.kb-card, .kb-suggest-item {
  display: grid;
  gap: 10px;
  padding: 18px;
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(255,255,255,0.06), rgba(255,255,255,0.025));
  border: 1px solid rgba(255,255,255,0.07);
  color: var(--white);
  text-decoration: none;
}
.kb-card:hover, .kb-suggest-item:hover {
  background:
    linear-gradient(145deg, rgba(10,132,255,0.12), rgba(255,255,255,0.04));
  transform: translateY(-2px);
  border-color: rgba(10,132,255,0.28);
}
.kb-card, .kb-suggest-item { transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease; }
.kb-card h3 { font-size: 1.05rem; line-height: 1.25; }
.kb-card p, .kb-suggest-item span { color: var(--gray-400); line-height: 1.55; font-size: 0.9rem; }
.kb-content {
  display: grid;
  gap: 14px;
  margin-top: 24px;
  color: var(--gray-200);
  line-height: 1.75;
  font-size: 1rem;
}
.kb-feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.kb-feedback input { display: none; }
.kb-suggestions {
  display: grid;
  gap: 10px;
  margin: 4px 0 8px;
}
.kb-suggestions:empty { display: none; }

.helper-text { margin-top: 2px; color: var(--gray-500); font-size: 0.72rem; }
.paste-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: #b2f7c1;
  font-size: 0.8rem;
}
.paste-preview:empty { display: none; }
.paste-preview img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
}

.message {
  margin: 0 auto 18px;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 0.92rem;
  width: min(1200px, calc(100% - 40px));
}
.message.success { background: rgba(48, 209, 88, 0.12); border: 1px solid rgba(48, 209, 88, 0.18); color: #b2f7c1; }
.message.error   { background: rgba(255, 69, 58, 0.12); border: 1px solid rgba(255, 69, 58, 0.18); color: #ffb7b2; }

.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.section-note { color: var(--gray-500); font-size: 0.72rem; padding-top: 10px; }

.empty-state {
  padding: 22px; border-radius: 20px;
  border: 1px dashed rgba(255,255,255,0.12);
  color: var(--gray-400);
  background: rgba(255,255,255,0.02);
  text-align: center;
}

.link-list { display: grid; gap: 14px; }
.link-item {
  padding: 18px; border-radius: 20px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.short-link {
  display: inline-block; text-decoration: none; color: var(--white);
  font-weight: 700; letter-spacing: -0.02em;
  margin-bottom: 8px; word-break: break-all;
}
.short-link:hover { color: #9fd2ff; }
.target-link { color: var(--gray-400); line-height: 1.6; font-size: 0.92rem; word-break: break-word; }
.link-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.meta-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 999px;
  font-size: 0.72rem; color: var(--gray-300);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  text-decoration: none;
}
.mono { letter-spacing: -0.02em; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td {
  text-align: left; padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.88rem;
}
.tbl th { color: var(--gray-400); font-weight: 500; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; }
.tbl tbody tr { cursor: pointer; transition: background 0.15s ease; }
.tbl tbody tr:hover { background: rgba(255,255,255,0.03); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }

/* Dashboard stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-top: 10px; }
.stat-card {
  padding: 20px; border-radius: 18px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.stat-val { font-size: 2rem; font-weight: 700; letter-spacing: -0.04em; }
.stat-lbl { font-size: 0.76rem; color: var(--gray-400); margin-top: 4px; font-family: 'JetBrains Mono', monospace; }

/* Filter bar */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(6, 1fr) auto auto;
  gap: 10px;
  margin-bottom: 22px;
  align-items: center;
}
.filter-bar input, .filter-bar select { padding: 10px 12px; font-size: 0.85rem; }
.filter-bar button, .filter-bar a { padding: 10px 16px; font-size: 0.85rem; }

/* Thread */
.thread { display: grid; gap: 14px; margin: 24px 0; }
.msg {
  padding: 16px 18px; border-radius: 18px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.msg-admin { background: rgba(10, 132, 255, 0.08); border-color: rgba(10,132,255,0.2); }
.msg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.msg-head strong { font-size: 0.9rem; }
.msg-head .mono { font-size: 0.72rem; color: var(--gray-500); }
.msg-body { color: var(--gray-200); line-height: 1.6; font-size: 0.94rem; word-break: break-word; }
.msg .meta-chip { margin-top: 10px; }

/* Install page */
.install-wrap { max-width: 680px; margin: 40px auto; padding: 40px 20px; position: relative; z-index: 1; }

@media (max-width: 980px) {
  .page-shell { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .kb-search, .kb-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar, .page-shell, .page-shell-single, .message {
    width: min(100% - 24px, 1200px);
  }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .admin-nav { width: 100%; }
  .hero-card, .list-card { padding: 22px; border-radius: 24px; }
  .input-row { grid-template-columns: 1fr; }
  .input-row button { width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
  .kb-alert { align-items: flex-start; flex-direction: column; }
  .tbl { font-size: 0.8rem; }
  .tbl th, .tbl td { padding: 10px 8px; }
}
