/* =====================================================================
   Advanced Features Lab - styles
   #509 White-label: --brand, --brand-accent, --brand-ink, --radius and --app-font
   come from the company's branding (set on <html> by layout.html).
   ===================================================================== */
:root {
    --brand: #4f46e5;
    --brand-accent: #06b6d4;
    --brand-ink: #fff;
    --radius: 12px;
    --app-font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --sidebar-w: 268px;
    --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 30%, transparent);
    --surface: #ffffff;
    --page: #f4f5f9;
    --line: #e6e8ef;
    --muted: #6b7280;
    --bs-border-radius: var(--radius);
    --bs-border-radius-lg: calc(var(--radius) + 4px);
    --bs-border-radius-sm: calc(var(--radius) * .6);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: color-mix(in srgb, var(--brand) 80%, #000);
    --bs-body-font-family: var(--app-font);
}
[data-bs-theme="dark"] {
    --surface: #161a23;
    --page: #0e1117;
    --line: #262c39;
    --muted: #9aa3b5;
    --brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
    --bs-link-color: color-mix(in srgb, var(--brand) 60%, #fff);
    --bs-link-hover-color: color-mix(in srgb, var(--brand) 40%, #fff);
    --bs-body-bg: var(--page);
}

body { background: var(--page); font-family: var(--app-font); }
.min-w-0 { min-width: 0; }

/* ---------- Buttons and form controls follow the brand ---------- */
.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-color: var(--brand-ink);
    --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 85%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 85%, #000);
    --bs-btn-hover-color: var(--brand-ink);
    --bs-btn-active-bg: color-mix(in srgb, var(--brand) 75%, #000); --bs-btn-active-border-color: color-mix(in srgb, var(--brand) 75%, #000);
    --bs-btn-active-color: var(--brand-ink);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); --bs-btn-disabled-color: var(--brand-ink);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand-line);
    --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-hover-color: var(--brand-ink);
    --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); --bs-btn-active-color: var(--brand-ink);
}
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: color-mix(in srgb, var(--brand) 55%, #fff); }
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--brand-line); box-shadow: 0 0 0 .2rem var(--brand-soft);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-range::-webkit-slider-thumb { background: var(--brand); }
.form-range::-moz-range-thumb { background: var(--brand); }
.text-brand { color: var(--brand) !important; }
[data-bs-theme="dark"] .text-brand { color: color-mix(in srgb, var(--brand) 55%, #fff) !important; }
.bg-brand-soft { background: var(--brand-soft) !important; }
.btn-icon { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--bs-body-color); }
.btn-icon:hover { background: var(--brand-soft); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; overflow-y: auto; z-index: 1040;
    background: #111827; color: #cbd5e1; border-right: 1px solid transparent;
}
.sidebar-light .sidebar { background: var(--surface); color: var(--bs-body-color); border-right-color: var(--line); }
.sidebar-brand .sidebar { background: color-mix(in srgb, var(--brand) 92%, #000); color: color-mix(in srgb, var(--brand-ink) 85%, transparent); }
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 14px; text-decoration: none; color: inherit; }
.brand-logo {
    width: 40px; height: 40px; border-radius: calc(var(--radius) * .9); display: grid; place-items: center; flex: none;
    background: linear-gradient(135deg, var(--brand), var(--brand-accent)); color: var(--brand-ink); font-size: 1.25rem;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 35%, transparent);
}
.sidebar-brand .brand-logo { background: rgba(255,255,255,.18); color: #fff; box-shadow: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 1.02rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-light .brand-text strong { color: var(--bs-emphasis-color); }
.brand-text small { font-size: .75rem; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-nav { padding: 6px 10px 16px; flex: 1; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; opacity: .55; padding: 16px 10px 6px; font-weight: 600; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 1px 0; border-radius: calc(var(--radius) * .7);
    color: inherit; text-decoration: none; font-size: .9rem; transition: background .15s;
}
.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.nav-item span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item em { font-style: normal; font-size: .68rem; opacity: .5; font-variant-numeric: tabular-nums; }
.nav-item:hover { background: rgba(255,255,255,.07); color: inherit; }
.sidebar-light .nav-item:hover { background: var(--brand-soft); }
.nav-item.active { background: var(--brand); color: var(--brand-ink); }
.nav-item.active i, .nav-item.active em { opacity: 1; }
.sidebar-brand .nav-item.active { background: rgba(255,255,255,.2); color: #fff; }
.sidebar-foot { padding: 12px 18px 18px; font-size: .72rem; opacity: .55; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: 12px;
    padding: 10px 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.tenant-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .92rem; min-width: 0; }
.tenant-chip i { color: var(--brand); }
[data-bs-theme="dark"] .tenant-chip i { color: color-mix(in srgb, var(--brand) 55%, #fff); }
.tenant-chip .badge { font-size: .62rem; font-weight: 600; letter-spacing: .04em; }
.user-btn { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; background: var(--surface); }
.user-menu { width: 330px; max-height: 70vh; overflow-y: auto; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .78rem; font-weight: 700;
    background: linear-gradient(135deg, var(--brand), var(--brand-accent)); color: var(--brand-ink); flex: none;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dropdown-item.active, .dropdown-item:active { background: var(--brand); color: var(--brand-ink); }
.content { padding: 24px; max-width: 1480px; width: 100%; }

/* ---------- Page header ---------- */
.feature-head { margin-bottom: 20px; }
.feature-icon {
    width: 52px; height: 52px; border-radius: calc(var(--radius) + 2px); display: grid; place-items: center; flex: none;
    background: var(--brand-soft); color: var(--brand); font-size: 1.5rem;
}
[data-bs-theme="dark"] .feature-icon { color: color-mix(in srgb, var(--brand) 55%, #fff); }
.feature-no { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--brand); color: var(--brand-ink); }
.page-title { font-size: 1.55rem; font-weight: 700; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: 4px 0 0; max-width: 820px; }
.how-panel { margin-top: 12px; padding: 12px 16px; border-radius: var(--radius); background: var(--brand-soft); border: 1px dashed var(--brand-line); font-size: .9rem; }
.how-panel code { font-size: .8rem; color: inherit; background: var(--surface); padding: 1px 6px; border-radius: 6px; display: inline-block; margin-top: 4px; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; padding: 12px 16px; display: flex; align-items: center; gap: 8px; }
.card-header .bi { color: var(--brand); }
[data-bs-theme="dark"] .card-header .bi { color: color-mix(in srgb, var(--brand) 55%, #fff); }
.card-header small { font-weight: 400; color: var(--muted); }
.stat-card { padding: 16px 18px; }
.stat-card .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .hint { font-size: .8rem; color: var(--muted); }
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { border-bottom-color: var(--line); padding: .6rem .75rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--brand-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem;
    background: var(--brand-soft); color: var(--bs-emphasis-color); border: 1px solid var(--brand-line); text-decoration: none;
}
button.chip { cursor: pointer; }
button.chip:hover, a.chip:hover { background: var(--brand); color: var(--brand-ink); }
.chip-muted { background: var(--bs-tertiary-bg); border-color: var(--line); }
.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: 8px; opacity: .6; }
.code-box {
    font-family: Consolas, "Cascadia Code", monospace; font-size: .82rem; white-space: pre-wrap; word-break: break-word;
    background: #0f172a; color: #e2e8f0; border-radius: var(--radius); padding: 12px 14px; margin: 0;
}
.code-box .kw { color: #93c5fd; }
.code-box .param { color: #fcd34d; }
.meter { height: 8px; background: var(--bs-tertiary-bg); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-accent)); border-radius: 99px; }
.pill-good { background: #dcfce7; color: #166534; }
.pill-bad { background: #fee2e2; color: #991b1b; }
.pill-mid { background: #fef3c7; color: #92400e; }
.pill-info { background: #e0f2fe; color: #075985; }
[data-bs-theme="dark"] .pill-good { background: #14532d; color: #bbf7d0; }
[data-bs-theme="dark"] .pill-bad { background: #7f1d1d; color: #fecaca; }
[data-bs-theme="dark"] .pill-mid { background: #78350f; color: #fde68a; }
[data-bs-theme="dark"] .pill-info { background: #0c4a6e; color: #bae6fd; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }

/* ---------- Dashboard ---------- */
.hero {
    border-radius: calc(var(--radius) + 6px); padding: 26px 28px; color: var(--brand-ink);
    background: radial-gradient(1200px 300px at 100% 0%, color-mix(in srgb, var(--brand-accent) 70%, transparent), transparent 60%),
                linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 70%, #000));
    position: relative; overflow: hidden;
}
.hero h1 { font-weight: 800; font-size: 1.8rem; letter-spacing: -.02em; }
.hero p { opacity: .9; max-width: 720px; }
.hero .bi-hero { position: absolute; right: 24px; bottom: -20px; font-size: 9rem; opacity: .12; }
.feature-tile { display: flex; gap: 14px; padding: 16px; height: 100%; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
.feature-tile:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(16,24,40,.08); border-color: var(--brand-line); color: inherit; }
.feature-tile .feature-icon { width: 44px; height: 44px; font-size: 1.25rem; }
.feature-tile h3 { font-size: 1rem; font-weight: 700; margin: 0 0 2px; }
.feature-tile p { font-size: .85rem; color: var(--muted); margin: 0; }

/* ---------- Chatbot ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 460px; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg-user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; background: var(--bs-tertiary-bg); border-bottom-left-radius: 4px; }
.msg-meta { font-size: .7rem; opacity: .65; margin-top: 4px; white-space: normal; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.chat-input { border-top: 1px solid var(--line); padding: 12px; }

/* ---------- Auto-fill ---------- */
.ai-filled { background: color-mix(in srgb, var(--brand-accent) 12%, var(--bs-body-bg)) !important; border-color: color-mix(in srgb, var(--brand-accent) 60%, transparent) !important; transition: background .4s; }
.conf { font-size: .7rem; font-weight: 600; padding: 1px 6px; border-radius: 99px; margin-left: 6px; }

/* ---------- OCR / faces / documents ---------- */
.img-frame { border: 1px solid var(--line); border-radius: var(--radius); background: repeating-conic-gradient(var(--bs-tertiary-bg) 0% 25%, transparent 0% 50%) 50% / 16px 16px; display: grid; place-items: center; min-height: 160px; overflow: hidden; }
.img-frame img { max-width: 100%; height: auto; display: block; }
.ocr-text { font-family: Consolas, monospace; font-size: .9rem; white-space: pre-wrap; min-height: 120px; }
.glyph-low { background: #fee2e2; color: #991b1b; border-radius: 3px; }
[data-bs-theme="dark"] .glyph-low { background: #7f1d1d; color: #fecaca; }
.face-thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); background: #ddd; image-rendering: auto; }
.face-thumb-lg { width: 128px; height: 128px; }
.cam-box { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.cam-box video, .cam-box canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-guide { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cam-guide::after { content: ""; width: 56%; aspect-ratio: 1; border: 3px dashed rgba(255,255,255,.85); border-radius: 18px; }
.mark { background: color-mix(in srgb, var(--brand-accent) 30%, transparent); border-radius: 3px; padding: 0 2px; }
.doc-src { font-family: Consolas, monospace; font-size: .8rem; white-space: pre-wrap; max-height: 460px; overflow: auto; }

/* ---------- Sentiment ---------- */
.w-pos { background: #bbf7d0; color: #14532d; border-radius: 3px; padding: 0 2px; }
.w-neg { background: #fecaca; color: #7f1d1d; border-radius: 3px; padding: 0 2px; }
.w-mod { text-decoration: underline dotted; text-underline-offset: 3px; }
.gauge { height: 14px; border-radius: 99px; position: relative; background: linear-gradient(90deg, #ef4444, #f59e0b 50%, #22c55e); }
.gauge > i { position: absolute; top: -5px; width: 4px; height: 24px; background: var(--bs-emphasis-color); border-radius: 2px; transform: translateX(-2px); }

/* ---------- Heatmap / matrix ---------- */
.matrix td, .matrix th { text-align: center; font-size: .8rem; }
.cell-on { background: color-mix(in srgb, #22c55e 22%, transparent) !important; }
.cell-off { background: color-mix(in srgb, #ef4444 12%, transparent) !important; }

/* ---------- Geofence map ---------- */
.geo-map { width: 100%; height: auto; display: block; border-radius: var(--radius); background: #e8eef3; cursor: crosshair; user-select: none; }
[data-bs-theme="dark"] .geo-map { background: #1b2430; }
.geo-map .road { stroke: #fff; stroke-linecap: round; fill: none; }
[data-bs-theme="dark"] .geo-map .road { stroke: #2d3a4b; }
.geo-map .river { stroke: #9cc7e6; fill: none; stroke-linecap: round; }
[data-bs-theme="dark"] .geo-map .river { stroke: #24476a; }
.geo-map .park { fill: #cfe8c8; }
[data-bs-theme="dark"] .geo-map .park { fill: #1f3a2a; }
.geo-map .zone { fill-opacity: .18; stroke-width: 2; }
.geo-map .zone-label { font-size: 12px; font-weight: 700; paint-order: stroke; stroke: rgba(255,255,255,.85); stroke-width: 3px; }
[data-bs-theme="dark"] .geo-map .zone-label { stroke: rgba(0,0,0,.7); fill: #fff; }
.geo-map .me { fill: var(--brand); stroke: #fff; stroke-width: 3; }
.geo-map .pulse { fill: var(--brand); opacity: .25; animation: pulse 1.6s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes pulse { 0% { transform: scale(.6); opacity: .45; } 100% { transform: scale(2.2); opacity: 0; } }
.geo-map .trail { stroke: var(--brand); stroke-width: 2; stroke-dasharray: 4 4; fill: none; opacity: .7; }

/* ---------- Branding preview ---------- */
.preview-frame { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; min-height: 300px; background: #f6f7fb; color: #111827; }
.pv-side { width: 150px; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; font-size: .75rem; }
.pv-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 10px; font-size: .82rem; }
.pv-logo span { width: 28px; height: 28px; display: grid; place-items: center; }
.pv-item { padding: 5px 8px; opacity: .8; }
.pv-main { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.pv-hero { padding: 16px; color: #fff; }
.pv-card { background: #fff; padding: 12px; border: 1px solid #e5e7eb; }
.contrast-ok { color: #15803d; } .contrast-bad { color: #b91c1c; }
.swatch { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }

/* ---------- A/B demo ---------- */
.ab-demo { border: 1px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; background: var(--bs-tertiary-bg); }
.ab-demo .cta { font-size: 1.05rem; padding: 10px 26px; border: 0; border-radius: var(--radius); font-weight: 600; color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
    body.nav-open .sidebar { transform: none; }
    .content { padding: 16px; }
    .topbar { padding: 10px 16px; }
    .msg { max-width: 92%; }
}
