/* BBS License Manager — shared styles on top of Bootstrap 5.3 */
:root {
  --app-primary: #1d5fc4;
  --app-primary-rgb: 29, 95, 196;
  --app-accent: #7cb342;
  --app-sidebar: #0b1f3a;
  --app-sidebar-ink: #c5d2e6;
  --app-sidebar-active: #16335c;
  --app-bg: #f3f6fb;
  --app-surface: #ffffff;
  --app-border: #e3e8f0;
  --app-ink: #1f2937;
  --app-muted: #6b7280;
  --app-good: #15803d;
  --app-warn: #b45309;
  --app-critical: #c62828;
  --app-radius: 10px;
  --bs-primary: var(--app-primary);
  --bs-primary-rgb: var(--app-primary-rgb);
  --bs-link-color: var(--app-primary);
  --bs-body-font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-font-size: .9rem;
}
[data-bs-theme="dark"] {
  --app-bg: #0f1623;
  --app-surface: #172131;
  --app-border: #263246;
  --app-ink: #e5e7eb;
  --app-muted: #94a3b8;
  --app-sidebar: #0a1220;
  --app-sidebar-active: #18263d;
  --app-primary: #5b8fe6;
  --app-primary-rgb: 91, 143, 230;
  --app-good: #4ade80;
  --app-warn: #fbbf24;
  --app-critical: #f87171;
  --bs-body-bg: #0f1623;
}

body { background: var(--app-bg); color: var(--app-ink); }
.btn-primary { --bs-btn-bg: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: #174fa3; --bs-btn-hover-border-color: #174fa3; --bs-btn-active-bg: #133f82; }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0b1220; --bs-btn-hover-bg: #7aa6ef; --bs-btn-hover-border-color: #7aa6ef; }
[data-bs-theme="dark"] .btn-light { --bs-btn-bg: var(--app-surface); --bs-btn-color: var(--app-ink); --bs-btn-border-color: var(--app-border); --bs-btn-hover-bg: #22304a; --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: var(--app-border); --bs-btn-disabled-bg: var(--app-surface); --bs-btn-disabled-color: var(--app-muted); }
.btn-outline-primary { --bs-btn-color: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: var(--app-primary); --bs-btn-hover-border-color: var(--app-primary); }
.text-muted, .form-text { color: var(--app-muted) !important; }
.form-label { font-weight: 600; font-size: .8rem; color: var(--app-muted); margin-bottom: .25rem; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--app-sidebar); color: var(--app-sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 1030; transition: width .2s;
}
.sidebar .brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.sidebar .brand img { width: 32px; height: 32px; }
.sidebar .brand small { display: block; font-weight: 400; font-size: .7rem; color: var(--app-sidebar-ink); letter-spacing: 0; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .25rem .6rem 1rem; }
.sidebar .nav-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8fae; padding: 1rem .6rem .35rem; }
.sidebar .nav-link { color: var(--app-sidebar-ink); border-radius: 8px; padding: .5rem .7rem; display: flex; align-items: center; gap: .7rem; font-size: .88rem; }
.sidebar .nav-link i { width: 18px; text-align: center; opacity: .85; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active { background: var(--app-sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--app-accent); }
.sidebar .foot { padding: .8rem 1.1rem; font-size: .7rem; color: #7d8fae; border-top: 1px solid rgba(255,255,255,.06); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--app-surface); border-bottom: 1px solid var(--app-border); display: flex; align-items: center;
  gap: .75rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 1020;
}
.topbar .page-title { font-size: 1.05rem; font-weight: 650; margin: 0; }
.topbar .crumb { font-size: .75rem; color: var(--app-muted); }
.topbar .avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--app-border); }
.content { padding: 1.25rem; flex: 1; }
/* The menu button works on every screen size: slide-in drawer on phones/tablets, collapse-to-full-width on desktop. */
@media (min-width: 992px) {
  .sidebar { transition: margin-left .2s ease; }
  .app.collapsed .sidebar { margin-left: -248px; }
}
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .content { padding: .9rem; }
}
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1025; display: none; }
.backdrop.show { display: block; }

/* ---------- Cards & tiles ---------- */
.card { border: 1px solid var(--app-border); border-radius: var(--app-radius); background: var(--app-surface); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--app-border); font-weight: 600; padding: .85rem 1rem; }
.tile { display: block; text-decoration: none; color: inherit; padding: 1rem; height: 100%; transition: border-color .15s, transform .15s; cursor: pointer; }
.tile:hover { border-color: rgba(var(--app-primary-rgb), .5); transform: translateY(-1px); }
.tile .label { font-size: .75rem; color: var(--app-muted); font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.tile .value { font-size: 1.75rem; font-weight: 700; line-height: 1.15; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.tile .hint { font-size: .72rem; color: var(--app-muted); }
.tile .icon { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: rgba(var(--app-primary-rgb), .1); color: var(--app-primary); }
.tile.warn .icon { background: rgba(180,83,9,.12); color: var(--app-warn); }
.tile.critical .icon { background: rgba(198,40,40,.12); color: var(--app-critical); }

/* ---------- Status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.pill { flex-shrink: 0; }
.min-w-0 { min-width: 0; }
.nowrap { white-space: nowrap; }
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.good { color: var(--app-good); background: rgba(21,128,61,.1); }
.pill.warn { color: var(--app-warn); background: rgba(180,83,9,.12); }
.pill.critical { color: var(--app-critical); background: rgba(198,40,40,.1); }
.pill.neutral { color: var(--app-muted); background: rgba(107,114,128,.12); }
.pill.info { color: var(--app-primary); background: rgba(var(--app-primary-rgb), .1); }

/* ---------- Data grid ---------- */
.grid-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--app-border); }
.grid-toolbar .search { max-width: 280px; }
.grid-wrap { overflow: auto; }
.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .85rem; }
.grid th { position: sticky; top: 0; background: var(--app-surface); z-index: 1; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--app-muted); font-weight: 650; padding: .6rem .75rem; border-bottom: 1px solid var(--app-border); white-space: nowrap; user-select: none; }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { color: var(--app-ink); }
.grid th .sort { opacity: .35; margin-left: .25rem; }
.grid th.sorted .sort { opacity: 1; color: var(--app-primary); }
.grid td { padding: .55rem .75rem; border-bottom: 1px solid var(--app-border); vertical-align: middle; }
.grid tbody tr.dg-row:hover td { background: rgba(var(--app-primary-rgb), .04); }
.grid tr.filters th { padding: .35rem .5rem; text-transform: none; letter-spacing: 0; top: 33px; }
.grid tr.filters input, .grid tr.filters select { font-size: .78rem; padding: .2rem .4rem; min-width: 70px; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .center { text-align: center; }
.grid .expander { width: 34px; }
.grid .expander button { border: 0; background: none; color: var(--app-muted); padding: 0 .25rem; transition: transform .15s; }
.grid tr.open .expander button { transform: rotate(90deg); color: var(--app-primary); }
.grid tr.detail > td { background: var(--app-bg); padding: .75rem 1rem .9rem 2.5rem; }
.grid .actions { white-space: nowrap; text-align: right; }
.grid .actions .btn { padding: .15rem .45rem; font-size: .8rem; }
.grid-foot { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: space-between; align-items: center; padding: .6rem 1rem; font-size: .8rem; color: var(--app-muted); }
.grid-empty { text-align: center; color: var(--app-muted); padding: 2.5rem 1rem !important; }
.subgrid { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 8px; overflow: hidden; }
.subgrid .grid th { top: 0; }

/* ---------- Icon buttons ---------- */
.btn-icon { width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--app-muted); background: transparent; border: 1px solid transparent; }
.btn-icon:hover { background: rgba(var(--app-primary-rgb), .08); color: var(--app-primary); }
.btn-icon.danger:hover { background: rgba(198,40,40,.1); color: var(--app-critical); }

/* ---------- Overlays ---------- */
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--app-accent); z-index: 2000; transition: width .3s, opacity .3s; opacity: 0; }
.loading-bar.on { width: 70%; opacity: 1; }
.toast-host { position: fixed; right: 1rem; bottom: 1rem; z-index: 2100; display: flex; flex-direction: column; gap: .5rem; }
.app-toast { min-width: 260px; max-width: 420px; background: var(--app-surface); border: 1px solid var(--app-border); border-left: 4px solid var(--app-primary); border-radius: 8px; padding: .7rem .9rem; box-shadow: 0 10px 30px rgba(0,0,0,.12); font-size: .85rem; white-space: pre-line; }
.app-toast.good { border-left-color: var(--app-good); }
.app-toast.critical { border-left-color: var(--app-critical); }
.app-toast.warn { border-left-color: var(--app-warn); }
.offcanvas.detail-panel { width: min(760px, 100vw) !important; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .75rem; font-size: .86rem; }
.kv dt { color: var(--app-muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- Chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--app-muted); font-size: 11px; }
.chart .grid-line { stroke: var(--app-border); stroke-width: 1; }
.chart .bar { fill: var(--app-primary); }
.chart .bar.overdue { fill: var(--app-critical); }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .value-label { fill: var(--app-ink); font-size: 11px; font-weight: 600; }
.chart-tip { position: absolute; pointer-events: none; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 6px; padding: .35rem .55rem; font-size: .78rem; box-shadow: 0 6px 18px rgba(0,0,0,.12); white-space: nowrap; transform: translate(-50%, -110%); display: none; }

/* ---------- Conversation (tickets / enquiries) ---------- */
.timeline { display: flex; flex-direction: column; gap: .85rem; }
.msg { display: flex; gap: .7rem; }
.msg .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--app-border); }
.msg .bubble { flex: 1; background: var(--app-bg); border: 1px solid var(--app-border); border-radius: 10px; padding: .6rem .8rem; }
.msg .meta { font-size: .75rem; color: var(--app-muted); display: flex; gap: .5rem; align-items: center; }
.msg .body { white-space: pre-wrap; margin-top: .25rem; }
.attach-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; border: 1px solid var(--app-border); border-radius: 6px; padding: .2rem .5rem; margin: .35rem .35rem 0 0; text-decoration: none; background: var(--app-surface); }
.attach-chip img { width: 46px; height: 46px; object-fit: cover; border-radius: 4px; }
.dropzone { border: 1.5px dashed var(--app-border); border-radius: 8px; padding: .6rem; text-align: center; font-size: .8rem; color: var(--app-muted); cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--app-primary); color: var(--app-primary); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .hero { background: linear-gradient(150deg, #0b1f3a 0%, #133a72 60%, #1d5fc4 100%); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth .hero h1 { font-weight: 700; font-size: 2rem; max-width: 26ch; }
.auth .hero ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .7rem; color: #c9d7ee; }
.auth .hero li i { color: var(--app-accent); width: 22px; }
.auth .panel { display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--app-surface); }
.auth .panel form, .auth .panel .box { width: 100%; max-width: 380px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth .hero { display: none; } }

/* ---------- Page preloader: covers the page content (not the menu) until its data has arrived ---------- */
#page:has(> .preloader) { position: relative; min-height: calc(100vh - 110px); }
.preloader {
  position: absolute; inset: -1.25rem; z-index: 20; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 22vh; background: var(--app-bg); opacity: 1; transition: opacity .25s ease; border-radius: 0;
}
.preloader.hiding { opacity: 0; pointer-events: none; }
.preloader[hidden] { display: none; }
.preloader-box { text-align: center; }
.preloader-mark { position: relative; width: 88px; height: 88px; margin: 0 auto; display: flex; align-items: center; justify-content: center; }
.preloader-mark .spinner-border { position: absolute; inset: 0; width: 88px; height: 88px; border-width: 3px; }
.preloader-mark img { animation: preloader-pulse 1.4s ease-in-out infinite; }
@keyframes preloader-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.88); opacity: .75; } }
@media (prefers-reduced-motion: reduce) { .preloader-mark img { animation: none; } .preloader-mark .spinner-border { animation-duration: 1.6s; } }
@media (max-width: 991.98px) { .preloader { inset: -.9rem; } }
.permission-table td, .permission-table th { text-align: center; }
.permission-table td:first-child, .permission-table th:first-child { text-align: left; }
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.required::after { content: " *"; color: var(--app-critical); }
.denied { text-align: center; padding: 4rem 1rem; color: var(--app-muted); }
