/* Scratchy base styles. Colours, radius and fonts are set per site in Settings > Theme and Fonts. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0; font-family: var(--font-body, system-ui, sans-serif); color: var(--text, #0f172a);
  background-color: var(--bg, #f1f5f9); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column;
  overflow-x: clip; position: relative; isolation: isolate;
}

/* Theme background image & fading pattern layers */
body.has-bg-image::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image:
    linear-gradient(
      to bottom,
      rgba(var(--bg-rgb, 15, 23, 42), var(--bg-fade, 0.55)),
      rgba(var(--bg-rgb, 15, 23, 42), calc(min(0.96, var(--bg-fade, 0.55) + 0.14)))
    ),
    var(--bg-image-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
body.has-bg-image.bg-style-cover_scroll::before {
  position: absolute;
}
body.has-bg-image.bg-style-fade_top::before {
  position: absolute;
  bottom: auto;
  height: min(75vh, 640px);
  background-image:
    linear-gradient(
      to bottom,
      rgba(var(--bg-rgb, 15, 23, 42), calc(var(--bg-fade, 0.55) * 0.65)) 0%,
      rgba(var(--bg-rgb, 15, 23, 42), var(--bg-fade, 0.55)) 55%,
      var(--bg, #f1f5f9) 100%
    ),
    var(--bg-image-url);
}

body[class*="bg-pattern-"]:not(.bg-pattern-none)::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* 1. Radial Glow + Dot Matrix (inspired by dashboard.php) */
body.bg-pattern-radial_dots::after {
  background-image:
    radial-gradient(circle at 50% 18%, rgba(var(--primary-rgb, 92, 219, 149), 0.24) 0%, transparent 60%),
    radial-gradient(circle at 82% 85%, rgba(var(--accent-rgb, 248, 192, 24), 0.12) 0%, transparent 50%),
    radial-gradient(rgba(var(--primary-rgb, 255, 255, 255), 0.22) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 30px 30px;
}

/* 2. Deep Space Starfield & Cosmic Fade */
body.bg-pattern-starfield::after {
  background-image:
    radial-gradient(circle at 25% 20%, rgba(var(--primary-rgb, 167, 139, 250), 0.24) 0%, transparent 52%),
    radial-gradient(circle at 78% 74%, rgba(var(--accent-rgb, 56, 189, 248), 0.2) 0%, transparent 50%),
    radial-gradient(rgba(255, 255, 255, 0.45) 1px, transparent 1.2px),
    radial-gradient(rgba(var(--accent-rgb, 56, 189, 248), 0.35) 1px, transparent 1.2px);
  background-size: 100% 100%, 100% 100%, 54px 54px, 86px 86px;
  background-position: 0 0, 0 0, 0 0, 27px 43px;
}

/* 3. Tech Blueprint Grid Fade */
body.bg-pattern-cyber_grid::after {
  background-image:
    radial-gradient(circle at 50% 14%, rgba(var(--primary-rgb, 16, 185, 129), 0.24) 0%, transparent 62%),
    linear-gradient(to right, rgba(var(--primary-rgb, 16, 185, 129), 0.11) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(var(--primary-rgb, 16, 185, 129), 0.11) 1px, transparent 1px);
  background-size: 100% 100%, 34px 34px, 34px 34px;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.75) 65%, rgba(0,0,0,0.22) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.75) 65%, rgba(0,0,0,0.22) 100%);
}

/* 4. Science Molecular Lattice Fade */
body.bg-pattern-hex_lab::after {
  background-image:
    radial-gradient(circle at 75% 18%, rgba(var(--primary-rgb, 2, 132, 199), 0.18) 0%, transparent 55%),
    radial-gradient(circle at 18% 78%, rgba(var(--accent-rgb, 20, 184, 166), 0.15) 0%, transparent 50%),
    repeating-linear-gradient(60deg, rgba(var(--primary-rgb, 2, 132, 199), 0.08) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(-60deg, rgba(var(--accent-rgb, 20, 184, 166), 0.08) 0 1px, transparent 1px 28px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
}

/* 5. Neon Dual-Glow & Scanline Fade */
body.bg-pattern-neon_horizon::after {
  background-image:
    radial-gradient(circle at 22% 16%, rgba(var(--primary-rgb, 0, 245, 255), 0.25) 0%, transparent 48%),
    radial-gradient(circle at 80% 78%, rgba(var(--accent-rgb, 255, 42, 133), 0.24) 0%, transparent 52%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 4px);
}

/* 6. Soft Aurora Gradient Fade */
body.bg-pattern-aurora_fade::after {
  background-image:
    radial-gradient(ellipse at 18% 12%, rgba(var(--primary-rgb, 56, 189, 248), 0.2) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 25%, rgba(var(--accent-rgb, 129, 140, 248), 0.16) 0%, transparent 52%),
    radial-gradient(ellipse at 50% 95%, rgba(var(--primary-rgb, 56, 189, 248), 0.12) 0%, transparent 55%);
}

/* 7. Minimal Fading Dots */
body.bg-pattern-subtle_dots::after {
  background-image:
    radial-gradient(circle at 50% 0%, rgba(var(--primary-rgb, 29, 78, 216), 0.12) 0%, transparent 55%),
    radial-gradient(rgba(var(--primary-rgb, 29, 78, 216), 0.16) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.35) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.35) 100%);
}

/* Subtle Neon / Sci-Fi Card Glow */
body.theme-glow .card,
body.theme-glow .stat {
  border-color: rgba(var(--primary-rgb, 0, 245, 255), 0.38);
  box-shadow: 0 0 18px rgba(var(--primary-rgb, 0, 245, 255), 0.1), 0 4px 16px rgba(0,0,0,0.35);
}
body.theme-glow .stat-link:hover,
body.theme-glow .stat-active {
  box-shadow: 0 0 22px rgba(var(--primary-rgb, 0, 245, 255), 0.28), 0 6px 18px rgba(0,0,0,0.4);
}
body.theme-glow .site-header {
  border-bottom-color: rgba(var(--primary-rgb, 0, 245, 255), 0.35);
  box-shadow: 0 2px 16px rgba(var(--primary-rgb, 0, 245, 255), 0.12);
}
body.theme-glow .btn-primary {
  box-shadow: 0 0 14px rgba(var(--primary-rgb, 0, 245, 255), 0.35);
}
body.has-bg-image .card,
body.has-bg-image .stat,
body.has-bg-image .site-header {
  background: rgba(var(--surface-rgb, 255, 255, 255), 0.92);
  backdrop-filter: blur(8px);
}
main { flex: 1; padding-bottom: 3rem; min-width: 0; }
h1, h2, h3 { font-family: var(--font-heading, system-ui, sans-serif); line-height: 1.2; margin: .4em 0 .5em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
a { color: var(--primary, #1d4ed8); }
img { max-width: 100%; height: auto; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code { background: rgba(127,127,127,.14); padding: .05em .35em; border-radius: 4px; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: var(--radius, 10px); overflow-x: auto; max-width: 100%; }
.wrap { word-break: break-all; }
.container { width: min(1180px, 100% - 2rem); margin: 0 auto; min-width: 0; }
.narrow { max-width: 620px; margin-left: auto; margin-right: auto; }
.muted { color: var(--muted, #64748b); }
.small { font-size: .875rem; }
.inline { display: inline-block; margin: 0 .25rem .25rem 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.bad-text { color: #dc2626; }

/* Header & Navigation */
.site-header {
  background: var(--surface, #fff); border-bottom: 1px solid rgba(127,127,127,.22);
  position: sticky; top: 0; z-index: 30;
}
.bar { display: flex; align-items: center; gap: 1rem; padding: .65rem 0; position: relative; }
.bar-public { justify-content: space-between; gap: 1rem; flex-wrap: nowrap; }
.public-login-nav { display: flex; align-items: center; flex-shrink: 0; margin-left: auto; }
.admin-login-link {
  display: inline-flex; align-items: center; text-decoration: none; font-weight: 600; font-size: .9rem;
  color: var(--primary, #1d4ed8); padding: .38rem .75rem; border-radius: var(--radius, 10px);
  border: 1px solid rgba(127,127,127,.3); background: rgba(127,127,127,.06);
  transition: background .15s ease, border-color .15s ease;
}
.admin-login-link:hover { background: var(--primary, #1d4ed8); color: #fff; border-color: var(--primary, #1d4ed8); }
.brand {
  display: flex; align-items: center; gap: .6rem; font-weight: 700; text-decoration: none;
  color: inherit; font-family: var(--font-heading, inherit); font-size: 1.1rem; min-width: 0;
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { height: 36px; width: auto; border-radius: 6px; flex-shrink: 0; }
.nav-toggle {
  display: none; align-items: center; gap: .4rem; margin-left: auto;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: .45rem .8rem; border-radius: var(--radius, 10px);
  border: 1px solid rgba(127,127,127,.35); background: var(--surface, #fff); color: var(--text, #0f172a);
  cursor: pointer; min-height: 40px;
}
.nav-toggle-icon { font-size: 1.1rem; line-height: 1; }
.nav-drawer { display: flex; align-items: center; gap: .75rem; flex: 1; min-width: 0; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.nav a {
  text-decoration: none; color: inherit; padding: .42rem .65rem;
  border-radius: var(--radius, 10px); font-size: .93rem; white-space: nowrap;
}
.nav a:hover { background: rgba(127,127,127,.14); }
.nav a.active { background: var(--primary, #1d4ed8); color: #fff; }
.nav-logout { margin: 0; flex-shrink: 0; }
.icon { display: inline-block; min-width: 1.2em; text-align: center; }
.site-footer { border-top: 1px solid rgba(127,127,127,.22); padding: 1rem 0; font-size: .875rem; }

/* Cards & Grids */
.card {
  background: var(--surface, #fff); border: 1px solid rgba(127,127,127,.22);
  border-radius: var(--radius, 10px); padding: 1.1rem 1.25rem; margin: 1rem 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 1rem; }
.grid-2 > *, .form-grid > *, .stat-grid > *, .cards > * { min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 1rem; }
.app-card { display: flex; flex-direction: column; gap: .35rem; text-decoration: none; color: inherit; margin: 0; }

/* Dashboard Stat Cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin: 1rem 0; }
.stat {
  background: var(--surface, #fff); border: 1px solid rgba(127,127,127,.22);
  border-radius: var(--radius, 10px); padding: .9rem 1rem;
}
.stat-link {
  display: block; text-decoration: none; color: inherit;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.stat-link:hover, .stat-link:focus-visible {
  transform: translateY(-2px); border-color: var(--primary, #1d4ed8);
  box-shadow: 0 4px 12px rgba(0,0,0,.08); outline: none;
}
.stat-active {
  border-color: var(--primary, #1d4ed8);
  box-shadow: 0 0 0 2px var(--primary, #1d4ed8);
}
.stat-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.stat-arrow { color: var(--muted, #64748b); font-size: 1.15rem; font-weight: 700; line-height: 1; }
.stat-active .stat-arrow, .stat-link:hover .stat-arrow { color: var(--primary, #1d4ed8); }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--primary, #1d4ed8); font-family: var(--font-heading, inherit); }
.stat-label { font-weight: 600; }
.dashboard-detail { border-left: 4px solid var(--primary, #1d4ed8); }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.detail-head h2 { margin: 0; }
.detail-head .actions { margin-top: 0; }

/* Headings & Actions */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.page-head p { margin: .25rem 0; }
.breadcrumb { font-size: .875rem; }
.actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; margin-top: .5rem; }
.actions-cell { white-space: nowrap; }
.actions-cell .inline { margin-bottom: 0; }
.status-select-sm { width: auto; padding: .28rem .45rem; font-size: .85rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-size: .95rem; padding: .5rem .9rem;
  border-radius: var(--radius, 10px); border: 1px solid rgba(127,127,127,.35);
  background: var(--surface, #fff); color: var(--text, #0f172a);
  text-decoration: none; cursor: pointer; line-height: 1.2;
}
.btn:hover { filter: brightness(.95); }
.btn-primary { background: var(--primary, #1d4ed8); color: #fff; border-color: transparent; }
.btn-danger { background: #dc2626; color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { font-size: .85rem; padding: .32rem .62rem; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid rgba(127,127,127,.22); vertical-align: top; }
.table th { font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted, #64748b); }
.table.compact th, .table.compact td { padding: .3rem .4rem; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--primary, #1d4ed8); text-decoration: underline; }
.row-pending { background: rgba(245, 158, 11, .1); }

/* Badges, Flashes, Notices */
.badge {
  display: inline-block; font-size: .78rem; padding: .12rem .5rem; border-radius: 999px;
  background: rgba(127,127,127,.15); color: var(--badge, inherit); border: 1px solid var(--badge, transparent);
  font-weight: 600; white-space: nowrap;
}
.badge-ok { background: #dcfce7; color: #166534; border-color: transparent; }
.badge-warn { background: #fef3c7; color: #92400e; border-color: transparent; }
.flash { padding: .7rem 1rem; border-radius: var(--radius, 10px); margin: 1rem 0 .5rem; border: 1px solid; }
.flash ul { margin: 0; padding-left: 1.2rem; }
.flash-success { background: #ecfdf5; border-color: #86efac; color: #14532d; }
.flash-error { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
.notice { background: #eff6ff; border: 1px solid #93c5fd; border-radius: var(--radius, 10px); padding: .8rem 1rem; margin: .75rem 0; }

/* Filter Pills & Forms */
.filter-pills { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .85rem; }
.pill {
  display: inline-flex; align-items: center; text-decoration: none; font-size: .84rem; font-weight: 500;
  padding: .3rem .68rem; border-radius: 999px;
  border: 1px solid rgba(127,127,127,.3); color: inherit; background: rgba(127,127,127,.06);
}
.pill:hover { border-color: var(--primary, #1d4ed8); color: var(--primary, #1d4ed8); }
.pill.active { background: var(--primary, #1d4ed8); border-color: var(--primary, #1d4ed8); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters label { flex: 1 1 150px; min-width: 0; }
.filter-bar { padding: .75rem; margin-bottom: .9rem; border-radius: var(--radius, 10px); background: rgba(127,127,127,.06); border: 1px solid rgba(127,127,127,.18); }
form.form-grid, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: .85rem 1rem; align-items: start; }
.form-grid .span-2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .92rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; padding: .48rem .62rem;
  border: 1px solid rgba(127,127,127,.4); border-radius: calc(var(--radius, 10px) * .6);
  background-color: var(--surface, #fff); color: var(--text, #0f172a); width: 100%; max-width: 100%;
}
select option, select optgroup {
  background-color: var(--surface, #fff);
  color: var(--text, #0f172a);
}
input[type=checkbox], input[type=radio] { width: auto; flex-shrink: 0; }
input[type=color] { padding: .15rem; height: 2.4rem; }
textarea { resize: vertical; }
input.narrow-input { width: 4.5rem; }
fieldset { border: 1px solid rgba(127,127,127,.25); border-radius: var(--radius, 10px); padding: .75rem 1rem; grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
fieldset .check { flex-direction: row; align-items: center; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.filters .actions { margin-top: 0; }

/* Theme Packs Gallery */
.theme-pack-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 1rem; margin-top: .75rem;
}
.theme-pack-card {
  display: flex; flex-direction: column; gap: .65rem;
  border: 1px solid rgba(127,127,127,.25); border-radius: var(--radius, 10px);
  padding: .85rem; background: var(--surface, #fff);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.theme-pack-card.is-active {
  border-color: var(--primary, #1d4ed8);
  box-shadow: 0 0 0 2px var(--primary, #1d4ed8);
}
.theme-pack-preview {
  padding: .55rem; border: 1px solid rgba(127,127,127,.2);
  display: flex; flex-direction: column; gap: .45rem;
}
.tp-bar {
  display: flex; align-items: center; gap: .3rem; padding: .35rem .45rem; border-radius: 5px;
  border: 1px solid rgba(127,127,127,.15);
}
.tp-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.tp-pill { width: 32px; height: 8px; border-radius: 999px; margin-left: auto; display: inline-block; }
.tp-surface { padding: .45rem .5rem; display: flex; flex-direction: column; gap: .3rem; border: 1px solid rgba(127,127,127,.12); }
.tp-line { height: 7px; border-radius: 999px; width: 78%; opacity: .85; display: block; }
.tp-line.short { width: 48%; opacity: .65; }
.theme-pack-info { flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.theme-pack-info p { margin: 0; }
.theme-pack-title { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.theme-swatches { display: flex; gap: .3rem; margin-top: .2rem; }
.swatch {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid rgba(127,127,127,.35); display: inline-block;
}
.theme-pack-form { display: flex; flex-direction: column; gap: .5rem; margin-top: auto; }
.theme-pack-form .btn { width: 100%; }

/* Built-in Background Scene Thumbnails */
.bg-thumb-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: .65rem;
}
.bg-thumb-item {
  display: flex; flex-direction: column; gap: .3rem; align-items: center; text-align: center;
  padding: .4rem; border-radius: var(--radius, 10px);
  border: 2px solid rgba(127,127,127,.25); background: var(--surface, #fff); color: inherit;
  font: inherit; cursor: pointer; transition: border-color .15s ease, transform .15s ease;
}
.bg-thumb-item:hover { border-color: var(--primary, #1d4ed8); transform: translateY(-1px); }
.bg-thumb-item.is-selected { border-color: var(--primary, #1d4ed8); box-shadow: 0 0 0 2px rgba(var(--primary-rgb, 29, 78, 216), 0.35); }
.bg-thumb-item img { width: 100%; height: 64px; object-fit: cover; border-radius: calc(var(--radius, 10px) * .5); display: block; }
input[type=range] { padding: .2rem 0; border: 0; background: transparent; accent-color: var(--primary, #1d4ed8); }

/* Details, Lists, Timelines */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .5rem 0; }
.kv dt { color: var(--muted, #64748b); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.plain { list-style: none; padding: 0; margin: .4rem 0; }
.plain li { padding: .35rem 0; border-bottom: 1px dashed rgba(127,127,127,.25); }
.prose { white-space: normal; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.timeline li { border-left: 3px solid var(--primary, #1d4ed8); padding: .45rem .75rem; background: rgba(127,127,127,.07); border-radius: 0 var(--radius, 10px) var(--radius, 10px) 0; }
.timeline li.outbound { border-color: #94a3b8; }
.timeline li.internal { border-color: #f59e0b; }
.timeline .when { font-size: .9rem; margin-bottom: .2rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; }
.chips li { background: rgba(127,127,127,.14); padding: .22rem .65rem; border-radius: 999px; font-size: .9rem; }
.checks { list-style: none; padding: 0; margin: 0; columns: 2; }
.checks li { padding: .15rem 0; }
.checks .ok::before { content: "✓ "; color: #16a34a; }
.checks .bad::before { content: "✗ "; color: #dc2626; }
.pager { display: flex; gap: .3rem; margin: .75rem 0; flex-wrap: wrap; }
.pager a { padding: .3rem .65rem; border: 1px solid rgba(127,127,127,.3); border-radius: var(--radius, 10px); text-decoration: none; }
.pager a.active { background: var(--primary, #1d4ed8); color: #fff; }

/* Settings Tabs (Desktop tabs, Mobile dropdown) */
.tabs-mobile-wrap { display: none; margin: 1rem 0; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin: 1rem 0; border-bottom: 1px solid rgba(127,127,127,.25); padding-bottom: .45rem; }
.tabs a { text-decoration: none; padding: .4rem .7rem; border-radius: var(--radius, 10px); color: inherit; font-size: .92rem; }
.tabs a:hover { background: rgba(127,127,127,.12); }
.tabs a.active { background: var(--primary, #1d4ed8); color: #fff; }

/* Images, Hero, Share */
.image-row { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; border-bottom: 1px dashed rgba(127,127,127,.25); padding-bottom: .75rem; }
.image-row input[type=file] { width: auto; max-width: 100%; }
.preview img { max-height: 90px; max-width: 220px; border-radius: 6px; border: 1px solid rgba(127,127,127,.25); margin: .3rem 0; background: #fff; }
.sample { border-top: 1px dashed rgba(127,127,127,.3); padding: .5rem 0; }
.hero {
  position: relative; border-radius: var(--radius, 10px); overflow: hidden; margin-top: 1rem;
  background: linear-gradient(135deg, var(--primary, #1d4ed8), var(--accent, #f59e0b));
  background-size: cover; background-position: center; color: #fff;
}
.hero h1, .hero .lead { color: #fff; }
.hero-inner { display: flex; gap: 1.25rem; align-items: center; padding: 2.25rem 1.5rem; flex-wrap: wrap; }
.hero a { color: #fff; }
.lead { font-size: 1.15rem; margin: .2rem 0 .5rem; }
.avatar { width: 128px; height: 128px; object-fit: cover; border-radius: 50%; border: 4px solid rgba(255,255,255,.85); background: #fff; flex-shrink: 0; }
.small-avatar { width: 72px; height: 72px; border-width: 2px; }
.share-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; }
.share-who { display: flex; gap: 1rem; align-items: center; min-width: 0; }
.share-who h1 { margin: 0; font-size: 1.5rem; }
.viewer iframe { width: 100%; height: 78vh; min-height: 460px; border: 1px solid rgba(127,127,127,.25); border-radius: var(--radius, 10px); background: #fff; }
.pdf-viewer { display: flex; flex-direction: column; gap: .75rem; }
.pdf-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .5rem .7rem; border-radius: calc(var(--radius, 10px) * .75);
  background: rgba(127,127,127,.09); border: 1px solid rgba(127,127,127,.2);
}
.pdf-toolbar-group { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.pdf-zoom-label { min-width: 3.1rem; text-align: center; font-weight: 600; }
.pdf-status { padding: 2rem 1rem; text-align: center; }
.pdf-pages {
  display: block;
  height: 78vh;
  min-height: 520px;
  max-height: 920px;
  overflow-y: scroll;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  border-radius: calc(var(--radius, 10px) * .75);
  background: rgba(127,127,127,.14);
  border: 1px solid rgba(127,127,127,.24);
}
.pdf-pages::-webkit-scrollbar { width: 14px; height: 14px; }
.pdf-pages::-webkit-scrollbar-track { background: rgba(127,127,127,.22); border-radius: 8px; }
.pdf-pages::-webkit-scrollbar-thumb {
  background: var(--primary, #1d4ed8);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
  min-height: 44px;
}
.pdf-pages::-webkit-scrollbar-thumb:hover { filter: brightness(1.1); }
.pdf-pages::-webkit-scrollbar-corner { background: transparent; }
.pdf-pages[hidden] { display: none; }
.pdf-page-wrap {
  display: block;
  width: fit-content;
  margin: 0 auto 1rem auto;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  line-height: 0;
}
.pdf-page-wrap:last-child { margin-bottom: 0; }
.pdf-page-canvas { display: block; max-width: none; }
.pdf-fallback { padding: 1.25rem; text-align: center; border: 1px dashed rgba(127,127,127,.35); border-radius: calc(var(--radius, 10px) * .75); }
.pdf-fallback .actions { justify-content: center; }
.pdf-noscript-object { display: block; width: 100%; min-height: 540px; border: 1px solid rgba(127,127,127,.25); border-radius: var(--radius, 10px); background: #fff; }

/* "Message Me Now" Contact Form */
.message-me-card h2 { margin-top: 0; }
.channel-picker { gap: .6rem; }
.channel-option { position: relative; flex-direction: row; align-items: center; cursor: pointer; margin: 0; }
.channel-option input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.channel-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .48rem .95rem; border-radius: 999px; font-weight: 600; font-size: .92rem;
  border: 2px solid rgba(127,127,127,.32); background: rgba(127,127,127,.07);
  transition: border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}
.channel-pill::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: currentColor; opacity: .75;
}
.channel-whatsapp::before { background: #22c55e; opacity: 1; }
.channel-telegram::before { background: #38bdf8; opacity: 1; }
.channel-sms::before { background: #f59e0b; opacity: 1; }
.channel-option:hover .channel-pill { border-color: var(--primary, #1d4ed8); }
.channel-option input[type=radio]:focus-visible + .channel-pill {
  outline: 2px solid var(--primary, #1d4ed8); outline-offset: 2px;
}
.channel-option input[type=radio]:checked + .channel-pill {
  border-color: var(--primary, #1d4ed8);
  background: rgba(var(--primary-rgb, 29, 78, 216), .16);
  box-shadow: 0 0 0 1px var(--primary, #1d4ed8);
}
.message-launch-box p { margin: 0 0 .45rem; }

/* Admin Analytics */
.analytics-controls { padding: .85rem 1.1rem; }
.analytics-control-row { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: flex-start; justify-content: space-between; }
.analytics-control-row .filter-pills { margin-bottom: 0; }
.control-title { margin-bottom: .35rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: .75rem; }
.stat-right { display: inline-flex; align-items: center; gap: .35rem; flex-shrink: 0; }
.trend-badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; white-space: nowrap;
}
.trend-up { background: rgba(34, 197, 94, .18); color: #15803d; }
.trend-down { background: rgba(239, 68, 68, .18); color: #b91c1c; }
.trend-flat { background: rgba(127, 127, 127, .16); color: var(--muted, #64748b); }
body.theme-dark .trend-up { color: #86efac; }
body.theme-dark .trend-down { color: #fca5a5; }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: .5rem; }
.analytics-svg { width: 100%; min-width: 460px; height: auto; max-height: 250px; display: block; }
.chart-grid { stroke: rgba(127, 127, 127, .24); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-axis { fill: var(--muted, #64748b); font-size: 11px; font-family: var(--font-body, system-ui, sans-serif); }
.chart-val { fill: var(--text, #0f172a); font-size: 11px; font-weight: 600; font-family: var(--font-body, system-ui, sans-serif); }
.chart-bar-link { cursor: pointer; text-decoration: none; }
.chart-slot-hit { fill: transparent; transition: fill .15s ease; }
.chart-bar-link:hover .chart-slot-hit,
.chart-bar-link:focus-visible .chart-slot-hit { fill: rgba(var(--primary-rgb, 29, 78, 216), .12); }
.chart-bar-link.is-selected .chart-slot-hit { fill: rgba(var(--primary-rgb, 29, 78, 216), .2); stroke: var(--primary, #1d4ed8); stroke-width: 1; }
.chart-bar { opacity: .9; transition: opacity .15s ease, filter .15s ease; }
.chart-bar-link:hover .chart-bar,
.chart-bar-link.is-selected .chart-bar { opacity: 1; filter: brightness(1.12); }
.chart-trendline { opacity: .85; pointer-events: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; margin: .2rem 0 .4rem; color: var(--muted, #64748b); }
.chart-legend span { display: inline-flex; align-items: center; gap: .38rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.meter {
  width: 100%; height: 7px; border-radius: 999px; background: rgba(127, 127, 127, .18);
  overflow: hidden; margin-top: .3rem;
}
.meter > span { display: block; height: 100%; border-radius: 999px; min-width: 0; transition: width .2s ease; }
.metric-cell { display: flex; align-items: baseline; gap: .35rem; flex-wrap: wrap; }
.funnel-list { display: flex; flex-direction: column; gap: .5rem; margin: .5rem 0 1rem; }
.funnel-meta { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.funnel-link {
  display: block; text-decoration: none; color: inherit;
  padding: .45rem .6rem; border-radius: calc(var(--radius, 10px) * .7);
  border: 1px solid transparent; transition: background .15s ease, border-color .15s ease;
}
.funnel-link:hover, .funnel-link:focus-visible {
  background: rgba(var(--primary-rgb, 29, 78, 216), .1);
  border-color: rgba(var(--primary-rgb, 29, 78, 216), .35);
  outline: none;
}
.funnel-link.is-selected {
  background: rgba(var(--primary-rgb, 29, 78, 216), .16);
  border-color: var(--primary, #1d4ed8);
}
.interactive-row { transition: background .15s ease; }
.interactive-row:hover { background: rgba(var(--primary-rgb, 29, 78, 216), .08); }
.interactive-row.row-selected { background: rgba(var(--primary-rgb, 29, 78, 216), .16); }

/* Enhanced Status Highlighting (Jobs & Analytics) */
.badge-status {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
  padding: .2rem .62rem; border-radius: 999px;
  color: var(--status-color, inherit);
  background: rgba(var(--status-rgb, 100, 116, 139), .16);
  border: 1.5px solid rgba(var(--status-rgb, 100, 116, 139), .7);
  box-shadow: 0 0 0 1px rgba(var(--status-rgb, 100, 116, 139), .12);
}
.badge-status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: var(--status-color, currentColor);
  box-shadow: 0 0 6px rgba(var(--status-rgb, 100, 116, 139), .85);
}
body.theme-dark .badge-status {
  background: rgba(var(--status-rgb, 100, 116, 139), .24);
  color: #f8fafc;
  border-color: var(--status-color, #94a3b8);
}
.status-filter-pills { margin: .5rem 0 .85rem; }
.status-pill { gap: .4rem; border-color: rgba(var(--status-rgb, 127, 127, 127), .45); }
.status-pill .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--status-color, #64748b); flex-shrink: 0;
}
.status-pill:hover {
  border-color: var(--status-color, var(--primary, #1d4ed8));
  background: rgba(var(--status-rgb, 100, 116, 139), .16);
  color: inherit;
}
.status-pill.active {
  background: var(--status-color, var(--primary, #1d4ed8));
  border-color: var(--status-color, var(--primary, #1d4ed8));
  color: #fff;
}
.status-pill.active .status-dot { background: #fff; }
.job-status-row {
  background: rgba(var(--status-rgb, 100, 116, 139), .08);
  transition: background .15s ease, opacity .15s ease;
}
.job-status-row:hover { background: rgba(var(--status-rgb, 100, 116, 139), .16); }
.job-status-row > td:first-child { box-shadow: inset 4px 0 0 var(--status-color, transparent); padding-left: .8rem; }
.job-status-row .status-select-sm {
  border-left: 3px solid var(--status-color, rgba(127, 127, 127, .4));
  background-color: var(--surface, #fff);
  background-image: linear-gradient(rgba(var(--status-rgb, 100, 116, 139), .16), rgba(var(--status-rgb, 100, 116, 139), .16));
  color: var(--text, #0f172a);
  font-weight: 600;
}
.job-status-row .status-select-sm option {
  background-color: var(--surface, #fff);
  color: var(--text, #0f172a);
  font-weight: 500;
}
.job-status-skipped { opacity: .72; }
.job-status-closed { opacity: .64; }
.job-status-skipped:hover, .job-status-closed:hover { opacity: 1; }
.job-detail-card { border-left: 4px solid var(--status-color, var(--primary, #1d4ed8)); }
.danger-card { border-left: 4px solid #dc2626; }
.image-row .muted { font-size: .85rem; }

/* Dark Theme Adaptations (respects each dark theme pack's CSS variables) */
body.theme-light { color-scheme: light; }
body.theme-dark { color-scheme: dark; }
body.theme-dark .card,
body.theme-dark .stat,
body.theme-dark .site-header,
body.theme-dark .theme-pack-card {
  border-color: rgba(255,255,255,.14);
  box-shadow: 0 2px 6px rgba(0,0,0,.28);
}
body.theme-dark .btn { border-color: rgba(255,255,255,.22); }
body.theme-dark .btn-primary { color: #0b1120; font-weight: 600; }
body.theme-dark .nav a.active,
body.theme-dark .tabs a.active,
body.theme-dark .pill.active,
body.theme-dark .pager a.active { color: #0b1120; font-weight: 600; }
body.theme-dark .admin-login-link:hover { color: #0b1120; }
body.theme-dark .notice { background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .35); color: var(--text, #e2e8f0); }
body.theme-dark .flash-success { background: rgba(22, 163, 74, .18); border-color: rgba(74, 222, 128, .4); color: #bbf7d0; }
body.theme-dark .flash-error { background: rgba(220, 38, 38, .2); border-color: rgba(248, 113, 113, .45); color: #fecaca; }
body.theme-dark .badge-ok { background: rgba(34, 197, 94, .2); color: #86efac; }
body.theme-dark .badge-warn { background: rgba(245, 158, 11, .22); color: #fde68a; }
body.theme-dark .bad-text { color: #f87171; }
body.theme-dark .row-pending { background: rgba(245, 158, 11, .14); }

@media (prefers-color-scheme: dark) {
  body.theme-auto {
    --bg: #0b1120;
    --surface: #131c31;
    --text: #e2e8f0;
    --muted: #94a3b8;
  }
  body.theme-auto .notice { background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .35); color: var(--text); }
  body.theme-auto .flash-success { background: rgba(22, 163, 74, .18); border-color: rgba(74, 222, 128, .4); color: #bbf7d0; }
  body.theme-auto .flash-error { background: rgba(220, 38, 38, .2); border-color: rgba(248, 113, 113, .45); color: #fecaca; }
}

/* Tablet & Mobile Navigation Dropdown (<= 820px) */
@media (max-width: 820px) {
  .bar-admin { flex-wrap: nowrap; justify-content: space-between; }
  .nav-toggle { display: inline-flex; }
  .nav-drawer {
    display: none;
    position: absolute;
    top: calc(100% + 1px);
    left: -1rem;
    right: -1rem;
    flex-direction: column;
    align-items: stretch;
    gap: .35rem;
    padding: .75rem 1rem 1rem;
    background: var(--surface, #fff);
    border-bottom: 1px solid rgba(127,127,127,.28);
    box-shadow: 0 12px 28px rgba(0,0,0,.16);
    z-index: 40;
  }
  .nav-drawer.is-open { display: flex; }
  .nav-drawer .nav { flex-direction: column; gap: .25rem; }
  .nav-drawer .nav a {
    display: flex; align-items: center; gap: .55rem;
    padding: .68rem .85rem; font-size: 1rem; min-height: 44px;
  }
  .nav-drawer .nav-logout {
    display: block; width: 100%; margin: .35rem 0 0;
    padding-top: .6rem; border-top: 1px solid rgba(127,127,127,.22);
  }
  .nav-drawer .nav-logout .btn { width: 100%; min-height: 42px; }

  .tabs { display: none; }
  .tabs-mobile-wrap { display: block; }
}

/* Mobile Layout & Responsive Stacked Tables (<= 680px) */
@media (max-width: 680px) {
  .container { width: calc(100% - 1.25rem); }
  .nav-drawer { left: -.625rem; right: -.625rem; }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.15rem; }
  .card { padding: .95rem 1rem; margin: .75rem 0; }
  .grid-2 { grid-template-columns: 1fr; gap: .75rem; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .stat { padding: .75rem .8rem; }
  .stat-value { font-size: 1.4rem; }
  .stat-label { font-size: .9rem; }
  .checks { columns: 1; }
  .page-head { gap: .6rem; }
  .page-head .actions { width: 100%; }
  .hero-inner { padding: 1.5rem 1.1rem; gap: .9rem; }
  .avatar { width: 88px; height: 88px; border-width: 3px; }
  .small-avatar { width: 58px; height: 58px; }
  .share-head { flex-direction: column; align-items: flex-start; }
  .share-head .actions { width: 100%; }
  .share-head .actions .btn { flex: 1 1 auto; }
  .viewer iframe { height: 65vh; min-height: 380px; }
  .pdf-pages { height: 68vh; min-height: 380px; padding: .6rem; }
  .image-row { flex-direction: column; align-items: flex-start; }
  .image-row input[type=file] { width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label { flex: 1 1 auto; width: 100%; }
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }

  /* Card-like stacked tables so mobile users avoid horizontal scrolling */
  .table-responsive thead { display: none; }
  .table-responsive,
  .table-responsive tbody,
  .table-responsive tr,
  .table-responsive td { display: block; width: 100%; }
  .table-responsive tr {
    border: 1px solid rgba(127,127,127,.24);
    border-radius: var(--radius, 10px);
    padding: .55rem .75rem;
    margin-bottom: .65rem;
    background: rgba(127,127,127,.03);
  }
  .table-responsive tr.job-status-row {
    border-left: 4px solid var(--status-color, rgba(127,127,127,.4));
    background: rgba(var(--status-rgb, 100, 116, 139), .1);
  }
  .table-responsive tr.job-status-row > td:first-child { box-shadow: none; padding-left: 0; }
  .table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    padding: .32rem 0;
    border-bottom: 1px dashed rgba(127,127,127,.18);
    text-align: right;
    word-break: break-word;
  }
  .table-responsive td:last-child { border-bottom: 0; padding-bottom: .1rem; }
  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted, #64748b);
    text-align: left;
    flex: 0 0 auto;
    max-width: 42%;
  }
  .table-responsive td.actions-cell {
    white-space: normal;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .35rem;
  }
  .table-responsive td.actions-cell::before { width: 100%; margin-bottom: .15rem; }
}

@media (max-width: 440px) {
  .kv { grid-template-columns: 1fr; gap: .15rem; }
  .kv dd { margin-bottom: .45rem; }
  .bar-public { gap: .6rem; }
  .admin-login-link { font-size: .85rem; padding: .32rem .6rem; }
}

@media print {
  .site-header, .nav, .nav-toggle, .nav-drawer, .actions, .btn, .site-footer, .filters, .filter-pills { display: none !important; }
  .card { box-shadow: none; border: 0; }
}
