/* ── Google Fonts loaded in base.html ───────────────────────────────────── */

/* ── Design tokens (override Bootstrap 5 CSS vars) ─────────────────────── */
:root {
  /* Palette */
  --bs-body-bg:            #f5f4f0;
  --bs-body-color:         #18181b;
  --bs-secondary-color:    #68686f;
  --bs-border-color:       #e2e1dd;
  --bs-card-border-color:  #e2e1dd;
  --bs-link-color:         var(--bs-primary);
  --bs-link-color-rgb:     var(--bs-primary-rgb);
  --bs-link-hover-color:   #4338ca;
  --bs-code-color:         #b8236a;

  /* Primary → indigo */
  --bs-primary:            #4f46e5;
  --bs-primary-rgb:        79, 70, 229;

  /* Typography */
  --bs-font-sans-serif:    'Inter', system-ui, -apple-system, sans-serif;
  --bs-font-monospace:     'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
  --bs-body-font-size:     1rem;
  --bs-body-line-height:   1.65;

  /* Custom */
  --nav-bg:     #18181b;
  --accent:     var(--bs-primary);
  --accent-lt:  #818cf8;
  --shadow-sm:  0 1px 2px rgba(0,0,0,.06), 0 1px 4px rgba(0,0,0,.04);
  --shadow:     0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --radius:     .5rem;
}

/* ── Background watermark ───────────────────────────────────────────────── */
.bg-watermark {
  position: fixed;
  top: 50%;
  right: -70px;
  transform: translateY(-50%);
  width: 420px;
  height: 420px;
  color: var(--bs-body-color);
  opacity: .035;
  z-index: 0;
  pointer-events: none;
}
[data-bs-theme="dark"] .bg-watermark { opacity: .05; }

@media (max-width: 991.98px) {
  .bg-watermark { display: none; }
}

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
  background: var(--bs-body-bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--nav-bg) !important;
  border-bottom: 1px solid rgba(255,255,255,.07);
  padding-top: .8rem;
  padding-bottom: .8rem;
}

.navbar-brand {
  font-family: var(--bs-font-monospace);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -.02em;
  color: #fff !important;
}

.brand-cpp    { color: var(--accent-lt); }
.brand-idioms { color: #e4e4e7; font-weight: 400; }

.navbar .nav-link { color: rgba(255,255,255,.65) !important; font-size: .9rem; white-space: nowrap; }
.navbar .nav-link:hover { color: #fff !important; }
.navbar .nav-link.active { color: #fff !important; font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent-lt); }

/* Just above the lg breakpoint (992-1024px) the right-hand button group
   (theme toggle, search, +New idiom, bell, account) is too wide for one
   row — Bootstrap doesn't wrap text within a nav-link/button, it just lets
   individual multi-word labels ("Work Wanted", "+ New idiom") break
   mid-word instead. Keep each label intact and let the whole group wrap
   to a second row instead, which reads as "a full item moved down" rather
   than "a word is cut in half". */
.navbar-collapse > .d-flex { flex-wrap: wrap; row-gap: .5rem; justify-content: flex-end; }
.navbar .btn, .navbar .navbar-username { white-space: nowrap; }

.navbar .form-control {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.14);
  color: #fff;
  font-size: .9rem;
  border-radius: var(--radius);
}
.navbar .form-control::placeholder { color: rgba(255,255,255,.45); }
.navbar .form-control:focus {
  background: rgba(255,255,255,.15);
  border-color: rgba(129,140,248,.5);
  box-shadow: 0 0 0 3px rgba(129,140,248,.2);
  color: #fff;
}

.navbar .btn-outline-light {
  border-radius: var(--radius);
  font-size: .9rem;
  padding: .35rem .85rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: #fff;
}

.card-header {
  background: transparent;
  border-bottom-color: var(--bs-border-color);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--bs-secondary-color);
  padding: .8rem 1.25rem;
}

/* ── Idiom index list ────────────────────────────────────────────────────── */
.list-group {
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.list-group-item {
  background: #fff;
  border-color: var(--bs-border-color);
  transition: background .1s ease;
  padding: 1rem 1.25rem;
}

.list-group-item:first-child {
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

.list-group-item:last-child {
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

.list-group-item-action:hover { background: rgba(79, 70, 229, .07); }

.list-group-item h5 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0;
}

/* Two structures share this list: idiom_card nests a real <a> inside the
   h5 (so the badges alongside it aren't also links); people.html/
   references.html make the whole row the <a> and the h5 is bare inside
   it. Both need the title itself to read as a link. */
.list-group-item h5 a,
.list-group-item-action h5 { color: var(--bs-link-color); }

.list-group-item .text-muted { font-size: .875rem; }

/* ── Announcement banner ─────────────────────────────────────────────────── */
.announcement-banner p:last-child { margin-bottom: 0; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  font-weight: 500;
  font-size: .72rem;
  border-radius: .3rem;
  letter-spacing: .01em;
}

.badge.bg-primary  { background: #dde1fb !important; color: #3730a3 !important; }
.badge.bg-secondary { background: #f0eee8 !important; color: #52525b !important; }
.badge.bg-success  { background: #dcfce7 !important; color: #15803d !important; }
.badge.bg-warning  { background: #fef9c3 !important; color: #854d0e !important; }
.badge.bg-dark     { background: #27272a !important; color: #e4e4e7 !important; }

/* Activity log action labels — plain text-success/text-danger (Bootstrap's
   stock #198754/#dc3545) measure ~4.1:1 against this page's background in
   both themes, borderline-to-failing AA. Scoped to these two classes rather
   than overriding .text-success/.text-danger globally, since those utility
   classes are also used elsewhere (badges, card headers) on backgrounds
   this fix wasn't verified against. */
.activity-created { color: #15803d; }
.activity-deleted { color: #b91c1c; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  --bs-btn-bg:             var(--bs-primary);
  --bs-btn-border-color:   var(--bs-primary);
  --bs-btn-hover-bg:       #4338ca;
  --bs-btn-hover-border-color: #4338ca;
  --bs-btn-active-bg:      #3730a3;
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

.btn-outline-secondary { border-color: var(--bs-border-color); color: #52525b; }
.btn-outline-secondary:hover { background: #f0eee8; color: var(--bs-body-color); border-color: #c4c2bc; }

/* Bootstrap's stock .btn-outline-primary is compiled with its own default
   blue (#0d6efd), not this site's --bs-primary indigo — 4.5:1 light /
   3.97:1 dark, both borderline-to-failing AA against this site's actual
   backgrounds. .btn-primary needed the same kind of explicit override
   above for the same reason (a root --bs-primary redefinition doesn't
   propagate into Bootstrap's per-component --bs-btn-* variables). */
.btn-outline-primary { border-color: var(--bs-primary); color: var(--bs-primary); }
.btn-outline-primary:hover { background: var(--bs-primary); color: #fff; border-color: var(--bs-primary); }
[data-bs-theme="dark"] .btn-outline-primary { border-color: #818cf8; color: #818cf8; }
[data-bs-theme="dark"] .btn-outline-primary:hover { background: #818cf8; color: #0f172a; border-color: #818cf8; }

/* <summary> toggles for inline rename/edit forms (dashboard.html,
   categories.html) — plain text-muted with list-style:none gave no visual
   signal they expand into a form. Suppress the native marker (list-style
   alone doesn't fully hide it in every browser) and draw our own chevron
   that flips when open, in the link color instead of muted gray. */
summary.disclosure-toggle { cursor: pointer; list-style: none; color: var(--bs-primary); }
summary.disclosure-toggle::-webkit-details-marker { display: none; }
summary.disclosure-toggle::before { content: "▸ "; display: inline-block; }
summary.disclosure-toggle:hover { text-decoration: underline; }
details[open] > summary.disclosure-toggle::before { content: "▾ "; }
[data-bs-theme="dark"] summary.disclosure-toggle { color: #818cf8; }

/* Bootstrap's stock btn-outline-warning (#ffc107 on white) is ~1.5:1 —
   effectively invisible. Same amber already used for .badge.bg-warning. */
.btn-outline-warning { border-color: #854d0e; color: #854d0e; }
.btn-outline-warning:hover { background: #854d0e; color: #fff; border-color: #854d0e; }

/* Subtle filled variant — replaces hardcoded style="background-color:#e9ecef" */
.btn-tinted { background-color: #e9ecef; }
[data-bs-theme="dark"] .btn-tinted { background-color: #1e293b; }

/* ── Section labels (idiom page) ─────────────────────────────────────────── */
.section-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--bs-secondary-color);
  margin-bottom: .6rem;
}

/* ── Prose (long-form text) ──────────────────────────────────────────────── */
.prose {
  line-height: 1.8;
  color: #3f3f46;
  max-width: 70ch;
}

.prose > :last-child { margin-bottom: 0; }

/* Guide pages — full-width prose (overrides the 70ch idiom default) */
.guide-prose { max-width: none; }
.guide-prose table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.guide-prose th, .guide-prose td { padding: .4rem .75rem; border: 1px solid #dee2e6; }
.guide-prose th { background: #f8f9fa; font-weight: 600; }
.guide-prose h2 { margin-top: 2rem; }
.guide-prose hr { margin: 2rem 0; }

[data-bs-theme="dark"] .guide-prose th { background: #162032; border-color: #334155; }
[data-bs-theme="dark"] .guide-prose td { border-color: #334155; }

/* ── Comment body (rendered HTML from mistune) ───────────────────────────── */
.comment-body {
  line-height: 1.7;
  color: #3f3f46;
}
.comment-body > :last-child { margin-bottom: 0; }
.comment-body blockquote {
  background: #f8f9fa;
  border-left: 4px solid #adb5bd;
  border-radius: 0 .25rem .25rem 0;
  padding: .5rem .75rem;
  margin: .25rem 0 .75rem;
  color: #495057;
  font-style: italic;
}
.comment-body blockquote > :last-child { margin-bottom: 0; }

/* ── Code blocks (public view) ───────────────────────────────────────────── */
pre { margin: 0; }

pre code.hljs {
  font-family: var(--bs-font-monospace);
  font-size: .84rem;
  line-height: 1.6;
  border-radius: 0;
  padding: 1.1rem 1.25rem;
}

.code-card pre:last-child code.hljs {
  border-bottom-left-radius: calc(var(--radius) - 1px);
  border-bottom-right-radius: calc(var(--radius) - 1px);
}

/* ── CodeMirror (admin editor) ───────────────────────────────────────────── */
.CodeMirror {
  height: auto;
  min-height: 180px;
  font-family: var(--bs-font-monospace);
  font-size: .85rem;
  line-height: 1.55;
  border-radius: var(--radius);
  border: 1px solid var(--bs-border-color);
}

/* ── Tables (admin) ──────────────────────────────────────────────────────── */
.table {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--bs-border-color);
}

.table thead th {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--bs-secondary-color);
  background: #faf9f6;
  border-bottom-width: 1px;
}

.table tbody tr:hover td { background: #faf9f6; }
/* Bootstrap's stock light-mode table-secondary (#e2e3e5) sits only ~1.1:1
   from this same page's own row-hover tone (#faf9f6 blended with the
   generic 7.5% black hover overlay) — a hovered ordinary row and a
   *resting* deleted row were nearly indistinguishable. Give it its own
   clearly darker shade, same reasoning as the dark-mode variant colors. */
.table-secondary { --bs-table-bg: #c5c6c9; --bs-table-hover-bg: #b6b7ba; --bs-table-color: #33373b; --bs-table-hover-color: #33373b; }
/* Same .text-muted-doesn't-adapt issue as the dark-mode fix above, and the
   same reason a plain `color: inherit` alone doesn't work: Bootstrap marks
   .text-muted's color !important, so overriding it needs !important too. */
.table-secondary .text-muted { color: inherit !important; }

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb { font-size: .85rem; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--bs-secondary-color); }

/* ── Category checklist ─────────────────────────────────────────────────── */
.category-checklist .form-check { padding-top: .2rem; padding-bottom: .2rem; }

/* ── OAuth buttons ───────────────────────────────────────────────────────── */
.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .55rem 1rem;
  font-size: .9rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--bs-border-color);
  text-decoration: none;
  transition: filter .15s;
}
.btn-oauth:hover { filter: brightness(.95); }

.btn-oauth-google { background: #fff; color: #3c4043; border-color: #dadce0; }
.btn-oauth-github { background: #24292e; color: #fff; border-color: #24292e; }

.oauth-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Auth divider ────────────────────────────────────────────────────────── */
.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--bs-secondary-color);
  font-size: .8rem;
}
.auth-divider::before,
.auth-divider::after { content: ''; flex: 1; border-top: 1px solid var(--bs-border-color); }

/* ── Navbar username ─────────────────────────────────────────────────────── */
.navbar-username {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .875rem;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer { background: var(--bs-body-bg); }

/* ── Dark mode ───────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
  --bs-body-bg:           #0f172a;
  --bs-body-color:        #e2e8f0;
  --bs-secondary-color:   #94a3b8;
  --bs-border-color:      #334155;
  --bs-card-border-color: #334155;
  --bs-link-color:        #818cf8;
  --bs-link-color-rgb:    129, 140, 248;
  --bs-link-hover-color:  #a5b4fc;
  --bs-code-color:        #e685b5;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 2px 8px rgba(0,0,0,.5);
}

[data-bs-theme="dark"] .card { background: #1e293b; }
[data-bs-theme="dark"] .list-group-item { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .list-group-item-action:hover { background: #283548; }
[data-bs-theme="dark"] .list-group-item h5 a,
[data-bs-theme="dark"] .list-group-item-action h5 { color: var(--bs-link-color); }

[data-bs-theme="dark"] .prose        { color: #cbd5e1; }
[data-bs-theme="dark"] .prose p,
[data-bs-theme="dark"] .prose li,
[data-bs-theme="dark"] .prose td    { color: #cbd5e1; }
[data-bs-theme="dark"] .comment-body { color: #cbd5e1; }
[data-bs-theme="dark"] .comment-body blockquote {
  background: #162032; border-color: #475569; color: #94a3b8;
}

[data-bs-theme="dark"] .table          { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .table thead th { background: #162032 !important; border-color: #334155; }
[data-bs-theme="dark"] .table tbody tr:hover td { background: #253347; }
[data-bs-theme="dark"] .table-light, [data-bs-theme="dark"] .table-light th { background: #162032 !important; }
[data-bs-theme="dark"] .table td, [data-bs-theme="dark"] .table th { border-color: #334155; color: #e2e8f0; }
/* Bootstrap's table-variant classes set --bs-table-bg/--bs-table-color, which
   each cell reads individually (background-color: var(--bs-table-bg)) — a
   plain background-color override on .table-success itself doesn't reach the
   <td>, only overriding these same custom properties does. */
[data-bs-theme="dark"] .table-success   { --bs-table-bg: #14532d; --bs-table-color: #bbf7d0; --bs-table-border-color: #1e6b3a; }
[data-bs-theme="dark"] .table-warning   { --bs-table-bg: #78350f; --bs-table-color: #fde68a; --bs-table-border-color: #92400e; }
[data-bs-theme="dark"] .table-secondary { --bs-table-bg: #3f3f46; --bs-table-color: #d4d4d8; --bs-table-border-color: #52525b; }
/* .text-muted's fixed --bs-secondary-color doesn't adapt to sit on top of
   these variant backgrounds — fall back to the cell's own (already correct)
   color instead of the generic muted gray. */
[data-bs-theme="dark"] .table-success .text-muted,
[data-bs-theme="dark"] .table-warning .text-muted,
[data-bs-theme="dark"] .table-secondary .text-muted { color: inherit !important; opacity: .8; }
/* Bootstrap 5.3's actual table-hover paint isn't background-color at all —
   it's `box-shadow: inset 0 0 0 9999px var(--bs-table-hover-bg)` on
   `tr:hover > *`, a separate custom property from --bs-table-bg above.
   Light mode already ships a sensible --bs-table-hover-bg per variant
   (Bootstrap's own default, e.g. #e2e3e5 for table-secondary) — leave that
   alone. Dark mode has no such default for these custom colors, so hovering
   fell back to the page's plain hover tint, wiping out the variant entirely.
   Give dark mode its own hover shade — a step lighter than the base, not
   identical to it, so hovering still reads as "this row responded" instead
   of feeling inert next to every other (still-interactive) row. */
[data-bs-theme="dark"] .table-success   { --bs-table-hover-bg: #1c6b3a; --bs-table-hover-color: #bbf7d0; }
[data-bs-theme="dark"] .table-warning   { --bs-table-hover-bg: #8a4014; --bs-table-hover-color: #fde68a; }
[data-bs-theme="dark"] .table-secondary { --bs-table-hover-bg: #4b4b54; --bs-table-hover-color: #d4d4d8; }

[data-bs-theme="dark"] .badge.bg-primary   { background: #312e81 !important; color: #c7d2fe !important; }
[data-bs-theme="dark"] .badge.bg-secondary { background: #3f3f46 !important; color: #d4d4d8 !important; }
[data-bs-theme="dark"] .badge.bg-success   { background: #14532d !important; color: #bbf7d0 !important; }
[data-bs-theme="dark"] .badge.bg-warning   { background: #78350f !important; color: #fde68a !important; }

[data-bs-theme="dark"] .activity-created { color: #bbf7d0; }
[data-bs-theme="dark"] .activity-deleted { color: #fca5a5; }

[data-bs-theme="dark"] .btn-outline-secondary { border-color: #475569; color: #94a3b8; }
[data-bs-theme="dark"] .btn-outline-secondary:hover { background: #334155; color: #e2e8f0; border-color: #64748b; }
[data-bs-theme="dark"] .btn-outline-warning { border-color: #fde68a; color: #fde68a; }
[data-bs-theme="dark"] .btn-outline-warning:hover { background: #fde68a; color: #1a1d22; border-color: #fde68a; }

[data-bs-theme="dark"] .btn-oauth-google { background: #1e293b; color: #e2e8f0; border-color: #334155; }

/* ── Diff page ───────────────────────────────────────────────────────────── */
.diff-add     { background: #d4edda; color: #155724; }
.diff-remove  { background: #f8d7da; color: #721c24; }
.diff-header  { background: #e9ecef; color: #5c646b; font-style: italic; }
.diff-line    { font-family: var(--bs-font-monospace); font-size: .82rem;
                white-space: pre-wrap; word-break: break-all;
                padding: .1rem .5rem; display: block; }
.diff-line::before            { display: inline-block; width: 1.2rem; }
.diff-add    .diff-line::before  { content: "+ "; }
.diff-remove .diff-line::before  { content: "− "; }
.diff-header .diff-line::before  { content: "  "; }
.diff-context .diff-line::before { content: "  "; }

.diff-example-add    { background: #d4edda; font-size: .82rem; }
.diff-example-remove { background: #f8d7da; font-size: .82rem; }

/* Character-level highlight within a changed line/value, GitHub-PR style */
.diff-char-remove, .diff-char-add { border-radius: 2px; padding: 0 1px; color: inherit; }
.diff-char-remove { background: #f1948a; text-decoration: line-through; }
.diff-char-add    { background: #7dcea0; text-decoration: underline; }

[data-bs-theme="dark"] .diff-add     { background: #14532d; color: #bbf7d0; }
[data-bs-theme="dark"] .diff-remove  { background: #7f1d1d; color: #fecaca; }
[data-bs-theme="dark"] .diff-header  { background: #1e293b; color: #94a3b8; }
[data-bs-theme="dark"] .diff-context { background: transparent; }
[data-bs-theme="dark"] .diff-example-add    { background: #14532d; }
[data-bs-theme="dark"] .diff-example-remove { background: #7f1d1d; }
[data-bs-theme="dark"] .diff-char-remove    { background: #b91c1c; }
[data-bs-theme="dark"] .diff-char-add       { background: #15803d; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 5rem 1rem;
  color: var(--bs-secondary-color);
}

.empty-state h2 { font-size: 1.25rem; font-weight: 500; margin-bottom: .5rem; }
.empty-state p  { font-size: .95rem; margin-bottom: 1.5rem; }
