/* ==========================================================================
   KB Theme — Modern Enterprise UI
   Location: /public/assets/css/kb-theme.css
   ========================================================================== */

/* ===== CSS Reset (trimmed) ===== */
*,
*::before,
*::after { box-sizing: border-box; }
html, body { height: 100%; }
body, h1, h2, h3, h4, h5, h6, p, figure { margin: 0; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }

/* ===== Design Tokens ===== */
:root{
  /* Palette — Dark Luxe */
  --bg: #0b0d10;              /* page background */
  --panel: #101319;           /* cards/panels */
  --panel-2: #0e1117;         /* alt panels */
  --elev: 0 2px 24px rgba(0,0,0,.35), 0 1px 1px rgba(0,0,0,.2);
  --border: #1f2630;          /* subtle borders */
  --muted: #96a0b5;           /* subdued text */
  --text: #e7e9ef;            /* primary text */
  --text-inv: #0b0d10;

  /* Accent: refined electric blue w/ gold for highlights */
  --accent: #5cabff;
  --accent-2: #a0c8ff;
  --gold: #f6c560;

  /* States */
  --ok: #3ddc97;
  --warn: #ffd166;
  --err: #ff6b6b;

  /* Typography scale */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --fs-xxs: 11px;
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --fs-3xl: 36px;

  /* Radii & spacing */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;

  /* Focus ring */
  --ring: 0 0 0 3px rgba(92,171,255,.25);
}

/* ===== Base ===== */
html { background: var(--bg); }
body {
  min-height: 100%;
  color: var(--text);
  background: radial-gradient(1200px 800px at 80% -10%, rgba(92,171,255,.07), transparent 55%) no-repeat,
              radial-gradient(1000px 700px at -10% 0%, rgba(246,197,96,.05), transparent 45%) no-repeat,
              var(--bg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* ===== Layout ===== */
.kb-header{ position:sticky; top:0; z-index:10; backdrop-filter:saturate(120%) blur(8px); border-bottom:1px solid var(--border); }

.kb-header__inner {
  max-width: 1120px; margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
}

.kb-brand {
  font-weight: 800; letter-spacing: .3px;
  font-size: var(--fs-lg);
  display: inline-flex; align-items: center; gap: 10px;
}
.kb-brand__emblem {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(180deg, var(--accent), #2f79ff);
  box-shadow: 0 6px 20px rgba(92,171,255,.35), inset 0 0 12px rgba(255,255,255,.25);
}

.kb-nav { color: var(--muted); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.kb-nav a { color: var(--accent-2); text-decoration: none; }
.kb-nav a:hover { color: var(--accent); }

.kb-container { max-width: 1120px; width: 100%; margin: 0 auto; padding: var(--space-5) var(--space-4); flex: 1; }
.kb-footer { color: var(--muted); text-align: center; padding: var(--space-6) var(--space-4); border-top: 1px solid var(--border); }

/* ===== Cards & Panels ===== */
.kb-card { background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  box-shadow: var(--elev);
}
.kb-card--compact { padding: var(--space-4); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px; border: 1px solid transparent;
  background: #222833; color: #e8ecf7; font-weight: 700; cursor: pointer;
  transition: transform .05s ease, border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn--primary {
  background: linear-gradient(180deg, var(--accent), #2f79ff);
  color: var(--text-inv);
  box-shadow: 0 10px 30px rgba(92,171,255,.25);
}
.btn--primary:hover { filter: brightness(1.08); }
.btn--secondary{ background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn--ghost {
  background: transparent; border-color: #2a3445; color: var(--muted);
}
.btn--danger {
  background: linear-gradient(180deg, #ff7b7b, #e45858);
  color: var(--text-inv);
}

/* ===== Inputs & Forms ===== */
.form {
  display: grid; gap: var(--space-4);
}
.form__row {
  display: grid; gap: var(--space-2);
}
.label { color: var(--muted); font-size: var(--fs-sm); }
.input, .select, .textarea {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
.textarea { min-height: 240px; resize: vertical; }

/* Inline help / validation */
.help { color: var(--muted); font-size: var(--fs-xs); }
.form__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ===== Search “Hero” ===== */
.kb-hero { margin-bottom: var(--space-5); }
.kb-hero__title { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: .2px; margin-bottom: var(--space-2); }
.kb-hero__sub { color: var(--muted); font-size: var(--fs-lg); }

.kb-search { margin-top: var(--space-4); display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.kb-search__input {
  flex: 1 1 auto; border: none; background: transparent; color: var(--text); padding: 10px 12px; font-size: var(--fs-lg);
  outline: none;
}
.kb-search__btn { white-space: nowrap; }

/* ===== Results ===== */
.results { display: grid; gap: 12px; }
.result { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.result h3 { margin: 0 0 6px 0; font-size: 19px; letter-spacing: .2px; }
.result h3 a { color: var(--text); text-decoration: none; }
.result h3 a:hover { color: var(--accent); }
.meta { color: var(--muted); font-size: var(--fs-xs); }
.tags { display:flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip{display:inline-block;padding:4px 10px;border-radius:999px;background:var(--panel-2);border:1px solid var(--border);color:var(--text);font-size:12px;}
.chip--gold { color:#1b1205; background: linear-gradient(180deg, #ffe29a, #f6c560); border: none; }

/* ===== Notices / Alerts ===== */
.notice { color: var(--accent-2); }
.alert { padding: 12px 14px; border-radius: 12px; border: 1px solid; }
.alert--ok { background: rgba(61,220,151,.08); border-color: rgba(61,220,151,.4); color: #a3f1cc; }
.alert--warn { background: rgba(255,209,102,.08); border-color: rgba(255,209,102,.4); color: #ffe29a; }
.alert--err { background: rgba(255,107,107,.08); border-color: rgba(255,107,107,.4); color: #ffc9c9; }

/* ===== Article / Entry ===== */
.kb-article { display: grid; gap: var(--space-4); }
.kb-article h1 { font-size: var(--fs-2xl); font-weight: 800; }
.prose {
  color: #e9edf6;
  line-height: 1.75;
}
.prose :is(h2,h3,h4){ margin-top: 1.25em; margin-bottom: .6em; letter-spacing: .2px; }
.prose h2 { font-size: 22px; }
.prose h3 { font-size: 18px; }
.prose p, .prose ul, .prose ol { margin: .7em 0; }
.prose a { color: var(--accent-2); }
.prose a:hover { color: var(--accent); }
.prose code { background: var(--panel-2); color: #e8f0ff; padding: 2px 6px; border-radius: 8px; border: 1px solid var(--border); }
.prose pre { background:#0e1421; padding: 14px; border-radius: 12px; overflow:auto; border: 1px solid #222a3a; }
.prose img { border-radius: 12px; border: 1px solid #222a34; }

/* ===== Editor / Uploader ===== */
.imglist { display:flex; flex-wrap:wrap; gap: 10px; }
.imgitem {
  background: #0f151f; border: 1px dashed #324055; border-radius: 10px; padding: 8px;
  transition: border-color .2s ease, transform .05s ease;
}
.imgitem:hover { border-color: var(--accent); transform: translateY(-1px); }

.kb-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Utilities ===== */
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
.center { text-align: center; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.w-100 { width: 100%; }

mark { background: #ffd54d; color: #1a1a1a; padding: 0 .2em; border-radius: 4px; }

/* ===== Links ===== */
a { color: var(--accent-2); }
a:hover { color: var(--accent); }

/* ===== Responsive ===== */
@media (max-width: 720px) {
  .kb-header__inner { padding: var(--space-3); }
  .kb-container { padding: var(--space-4) var(--space-3); }
  .kb-card { padding: var(--space-4); }
  .kb-hero__title { font-size: 28px; }
}

/* ===== Focus-visible Polyfill Friendly ===== */
:focus-visible { outline: none; box-shadow: var(--ring); }

/* ===== Nice subtle scrollbars ===== */
* { scrollbar-width: thin; scrollbar-color: #2a3445 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #2a3445; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ==== Entry image sizing & overlay (2025-09-03) ==== */
.kb-article .entry-body img { max-width: 320px; height: auto; cursor: zoom-in; border-radius: 8px; }
.kb-article .entry-body { white-space: pre-wrap; word-wrap: break-word; }
.img-overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 1000; background: rgba(0,0,0,0.8); padding: 24px; }
.img-overlay.is-open { display: flex; }
.img-overlay__img { max-width: 100%; max-height: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.img-overlay__close { position: fixed; top: 12px; right: 16px; background: rgba(255,255,255,.9); border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.tag-list { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-block; background: #eef2ff; color: #2a3445; padding: 4px 8px; border-radius: 999px; font-size: 13px; text-decoration: none; }
.tag:hover { background: #dfe6ff; }

/* === Editor guardrails (non-invasive) === */
#entryForm .form__row{ margin-bottom: 14px; }
#entryForm .label{ display:block; font-weight:600; margin-bottom: 6px; }
#entryForm .input, #entryForm .textarea{ width:100%; box-sizing:border-box; }

.form_actions .btn{ margin-right: 10px; }

.imglist{ display:flex; flex-wrap:wrap; gap: 12px; }
.imgitem .btn.img-del{ display:inline-flex; }

/* Ensure danger button is prominent */
.btn--danger{ background: linear-gradient(180deg, #ff7b7b, #e45858); color: var(--text-inv); }
.btn--danger:hover{ filter: brightness(1.06); }
/* ===== Editor resilience (append-only) ===== */
.kb-card input[type="text"],
.kb-card input[type="email"],
.kb-card input[type="password"],
.kb-card input[type="search"],
.kb-card input[type="url"],
.kb-card input[type="number"],
.kb-card input[type="file"],
.kb-card textarea,
.kb-card select {
  width: 100%;
  background: #0d1016;
  color: var(--text);
  border: 1px solid #262e3a;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.kb-card input::placeholder,
.kb-card textarea::placeholder { color: #70809b; }
.kb-card input:focus,
.kb-card textarea:focus,
.kb-card select:focus { border-color: var(--accent); box-shadow: var(--ring); }

.textarea, .kb-card textarea { min-height: 240px; resize: vertical; }

/* Ensure image delete button is visible on thumbs */
.imgitem .btn.img-del { display: inline-flex; }

/* ===== Editor resilience (append-only) ===== */
.kb-card input[type="text"],
.kb-card input[type="email"],
.kb-card input[type="password"],
.kb-card input[type="search"],
.kb-card input[type="url"],
.kb-card input[type="number"],
.kb-card input[type="file"],
.kb-card textarea,
.kb-card select {
  width: 100%;
  background: #0d1016;
  color: var(--text);
  border: 1px solid #262e3a;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.kb-card input::placeholder,
.kb-card textarea::placeholder { color: #70809b; }
.kb-card input:focus,
.kb-card textarea:focus,
.kb-card select:focus { border-color: var(--accent); box-shadow: var(--ring); }
.imgitem .btn.img-del { display: inline-flex; }


/* === Tag bar enhancements === */
.kb-tagbar{ display:flex; flex-wrap:wrap; gap:.5rem 1rem; justify-content:center; }
.kb-tagbar .chip--quick{ transition: box-shadow .15s ease, transform .15s ease; }
.kb-tagbar .chip--quick:hover,
.kb-tagbar .chip--quick:focus{ 
  box-shadow: 0 0 0 3px rgba(100,150,255,.15), 0 0 14px rgba(100,150,255,.25);
  transform: translateY(-1px);
}



/* === Tag bar hover & centering for current markup === */
.kb-quick-tags{ display:flex; flex-wrap:wrap; gap:.5rem 1rem; justify-content:center; }
.kb-quick-tags .chip--quick{ transition: box-shadow .15s ease, transform .15s ease; }
.kb-quick-tags .chip--quick:hover,
.kb-quick-tags .chip--quick:focus{
  box-shadow: 0 0 0 3px rgba(100,150,255,.15), 0 0 14px rgba(100,150,255,.25);
  transform: translateY(-1px);
}



/* ==== 2025-09-06 Mobile alignment + legacy safety patch ==== */

/* Stop sideways scroll/drift on iOS */
html, body { overflow-x: hidden; }

/* Preserve author newlines even if body is plain text */
.entry-body { white-space: pre-wrap; word-wrap: break-word; }

/* Make inline images obviously tappable for zoom */
.entry-body img { cursor: zoom-in; }

/* Result cards: never exceed container; long tokens wrap safely */
.results { grid-template-columns: minmax(0, 1fr); }  /* clamp track to container */
.result { min-width: 0; max-width: 100%; }
.result h3, .result .meta, .result .mt-2 {
  overflow-wrap: anywhere;  /* modern wrap for long words/URLs */
  word-break: break-word;   /* fallback */
}

/* === Code blocks + copy button ========================================= */
.entry-body {
  overflow-wrap: anywhere;   /* break long words/urls on mobile */
  word-break: break-word;
}

.entry-body img {
  max-width: 100%;
  height: auto;
}

.entry-body pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 14px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #cfe3ff;
  overflow: auto;           /* allow horizontal scroll INSIDE the block */
  max-width: 100%;
}

.entry-body pre code {
  white-space: pre;         /* keep code lines intact */
  display: block;
}

/* Wrap each <pre> in a positioned box so we can float a copy button */
.codebox { position: relative; }

.codebox .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: #eaf2ff;
  font-size: 12px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, color .15s ease;
}

.codebox .copy-btn:hover {
  background: rgba(255,255,255,.12);
  transform: translateY(-1px);
}

.codebox .copy-btn.copied {
  background: #33c24d;
  border-color: #33c24d;
  color: #001a07;
}

/* === Block code overrides (ensure pre > code isn't styled like inline code) === */
.kb-entry pre code,
.entry-body pre code {
  background: transparent !important;
  padding: 0 !important;
  border: 0 !important;
  box-shadow: none !important;
  white-space: pre;   /* keep line breaks and spaces */
  display: block;
}

/* Optional: a bit of top room so the copy button never overlaps first line */
.kb-entry pre,
.entry-body pre {
  padding-top: 36px;        /* only if you want extra room for the button */
}


/* Generic form controls */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
textarea,
select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); }



/* === Universal controls (override legacy) === */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
}
input::placeholder, textarea::placeholder { color: var(--muted) !important; }



/* file input override */
input[type="file"]{
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
}
