/*
 * Shared app styles on top of Bootstrap 5.3 (see docs/UI-STACK.md). Everything here reads
 * Bootstrap's CSS variables, so it follows light/dark (data-bs-theme) and the per-tenant brand
 * colour (--bs-primary, set per request by src/app/web/brandTheme.ts). Never hardcode a colour here.
 */

/* Type: IBM Plex Sans for the UI, IBM Plex Mono for codes. */
:root {
  --bs-body-font-family: 'IBM Plex Sans', system-ui, sans-serif;
  --bs-font-monospace: 'IBM Plex Mono', ui-monospace, monospace;
}
table { font-variant-numeric: tabular-nums; }

/* Rounder corners: one scale for every component. */
:root {
  --bs-border-radius: .625rem;
  --bs-border-radius-sm: .45rem;
  --bs-border-radius-lg: .875rem;
  --bs-border-radius-xl: 1.25rem;
  --bs-border-radius-xxl: 1.75rem;
}

/* Elevation: one shadow scale for everything above the page background. */
:root, [data-bs-theme="light"] {
  --asc-shadow-sm: 0 1px 2px rgba(var(--bs-emphasis-color-rgb), .05), 0 2px 6px -2px rgba(var(--bs-emphasis-color-rgb), .10);
  --asc-shadow: 0 1px 2px rgba(var(--bs-emphasis-color-rgb), .05), 0 6px 16px -4px rgba(var(--bs-emphasis-color-rgb), .12);
  --asc-shadow-lg: 0 2px 4px rgba(var(--bs-emphasis-color-rgb), .06), 0 16px 32px -8px rgba(var(--bs-emphasis-color-rgb), .20);
}
[data-bs-theme="dark"] {
  --asc-shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 6px -2px rgba(0, 0, 0, .45);
  --asc-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px -4px rgba(0, 0, 0, .55);
  --asc-shadow-lg: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 32px -8px rgba(0, 0, 0, .7);
}
:root, [data-bs-theme] { --bs-box-shadow-sm: var(--asc-shadow-sm); --bs-box-shadow: var(--asc-shadow); --bs-box-shadow-lg: var(--asc-shadow-lg); }
.card { box-shadow: var(--asc-shadow); }
.dropdown-menu, .ts-dropdown, .popover, .toast, .modal-content, .offcanvas { box-shadow: var(--asc-shadow-lg); }
.btn-primary:not(:disabled), .btn-danger:not(:disabled), .btn-secondary:not(:disabled) { box-shadow: var(--asc-shadow-sm); }

/* Page background: a soft brand-tinted glow. */
body {
  background-color: var(--bs-tertiary-bg);
  background-image:
    radial-gradient(ellipse 900px 360px at 50% -80px, color-mix(in srgb, var(--bs-primary) 14%, transparent), transparent 70%),
    linear-gradient(180deg, transparent 0, color-mix(in srgb, var(--bs-primary) 4%, transparent) 100%);
  background-repeat: no-repeat;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Top bar: brand gradient, text colour chosen for contrast against the (adjusted) brand colour. */
.app-header {
  color: var(--asc-primary-contrast);
  background-image: linear-gradient(120deg, var(--bs-primary) 0%, color-mix(in srgb, var(--bs-primary) 80%, black) 100%);
  box-shadow: var(--asc-shadow);
  position: relative;
  z-index: 10;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: 999px;
  color: inherit; background: rgba(255, 255, 255, .16); box-shadow: none; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .26); }

/* Public reporting flow: narrow column. */
.container-narrow { max-width: 560px; }
.steps { display: flex; gap: 6px; margin: 0 0 1rem; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--bs-border-color); }
.steps span.done { background: var(--bs-primary); }
.accounts { border: 1px dashed var(--bs-border-color); border-radius: var(--bs-border-radius); padding: .75rem; margin-top: .75rem; }
code.big { font-size: 1.75rem; letter-spacing: 2px; color: var(--bs-body-color); background: none; }

/* Inline Lucide icons follow the text colour (see src/app/web/icons.ts). */
.icon { width: 1.15em; height: 1.15em; vertical-align: -.2em; flex-shrink: 0; }
.icon-lg { font-size: 1.6rem; }

/* Tom Select's Bootstrap 5 theme hardcodes #343a40 text: unreadable in dark. Point it at theme variables. */
.ts-wrapper .ts-control, .ts-wrapper .ts-control input, .ts-dropdown { color: var(--bs-body-color); }
.ts-dropdown .active { background-color: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); }
.ts-wrapper.multi .ts-control > div { background: var(--bs-tertiary-bg); color: var(--bs-body-color); border-color: var(--bs-border-color); }

/* Admin console: a dark sidebar (always dark, in both themes) + content column.
 * Desktop: the sidebar is sticky and as tall as the viewport, so it never scrolls away with a long
 *   page; if its menu is taller than the screen it scrolls inside itself.
 * Phone (<768px): it becomes a sticky top bar; the menu opens under it with the menu button. */
:root { --asc-chrome: #0F1E26; }
body.admin { display: flex; }
.admin-side {
  width: 220px; flex-shrink: 0; display: flex; flex-direction: column; color: #fff;
  background: linear-gradient(195deg, color-mix(in srgb, var(--bs-primary) 40%, var(--asc-chrome)) 0%, var(--asc-chrome) 75%);
  box-shadow: var(--asc-shadow); z-index: 20;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
}
.admin-side .admin-bar { padding: 1.25rem 1.25rem 1.25rem; margin-bottom: .75rem; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.admin-side .admin-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.admin-side .admin-brand { font-weight: 700; display: flex; align-items: center; gap: .6rem; min-width: 0; }
.admin-side .admin-brand-text { min-width: 0; overflow-wrap: anywhere; line-height: 1.2; }
/* The logo is a JPEG with a white ground, so it gets a light rounded backing on the dark sidebar. */
.admin-side .admin-logo { flex-shrink: 0; display: inline-flex; padding: 2px; border-radius: .4rem; background: #fff; }
.admin-side .admin-logo img { width: 28px; height: 28px; object-fit: contain; display: block; }
.admin-side .admin-collapse { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: var(--bs-border-radius); color: inherit; background: rgba(255, 255, 255, .1); cursor: pointer; }
.admin-side .admin-collapse:hover { background: rgba(255, 255, 255, .2); }
.admin-side .admin-collapse-open { display: none; }
.admin-side .admin-toggle { display: none; }
.admin-side .admin-menu { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: 1.25rem; }
.admin-side .admin-section { padding: 1rem 1.25rem .4rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: rgba(255, 255, 255, .5); }
.admin-side .admin-link { display: flex; align-items: center; gap: .6rem; padding: .6rem 1.25rem; color: rgba(255, 255, 255, .8); text-decoration: none; font-size: .9rem; }
.admin-side .admin-link:hover, .admin-side .admin-link.active { background: rgba(255, 255, 255, .1); color: #fff; }
.admin-side .admin-foot { margin-top: auto; padding: .9rem 1.25rem 0; border-top: 1px solid rgba(255, 255, 255, .15); }
.admin-side .admin-user { font-size: .85rem; font-weight: 600; }
.admin-side .admin-role { font-size: .72rem; color: rgba(255, 255, 255, .6); }
.admin-side .admin-logout { background: none; border: 0; padding: .5rem 0; color: rgba(255, 255, 255, .75); font-size: .8rem; font-weight: 600; cursor: pointer; }
.admin-side .admin-logout:hover { color: #fff; }
.admin-main { flex: 1; min-width: 0; padding: 1.75rem 2rem; max-width: 1100px; }
body.admin-login .admin-main { max-width: none; width: 100%; }

@media (min-width: 768px) {
  .nav-collapsed .admin-side { width: 64px; }
  .nav-collapsed .admin-side .admin-label,
  .nav-collapsed .admin-side .admin-brand-text,
  .nav-collapsed .admin-side .admin-user,
  .nav-collapsed .admin-side .admin-role { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav-collapsed .admin-side .admin-bar { flex-direction: column; padding: 1rem .5rem; gap: .75rem; }
  .nav-collapsed .admin-side .admin-collapse-close { display: none; }
  .nav-collapsed .admin-side .admin-collapse-open { display: inline-flex; }
  .nav-collapsed .admin-side .admin-link { justify-content: center; padding: .65rem 0; }
  .nav-collapsed .admin-side .admin-section { height: 0; padding: 0; margin: .5rem .9rem; border-top: 1px solid rgba(255, 255, 255, .15); overflow: hidden; font-size: 0; }
  .nav-collapsed .admin-side .admin-foot { padding: .75rem 0 0; }
  .nav-collapsed .admin-side .admin-foot > .d-flex { flex-direction: column; align-items: center; gap: .5rem; }
  .nav-collapsed .admin-side .admin-logout { padding: .4rem; }
}

@media (max-width: 767.98px) {
  body.admin { flex-direction: column; }
  .admin-side .admin-collapse { display: none; }
  .admin-side { width: 100%; height: auto; max-height: 100vh; max-height: 100dvh; align-self: stretch; }
  .admin-side .admin-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1rem; margin-bottom: 0; border-bottom: 0; }
  .admin-side .admin-brand { min-width: 0; }
  .admin-side .admin-brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .admin-side .admin-toggle { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 2.4rem; height: 2.4rem; padding: 0; border: 0; border-radius: var(--bs-border-radius); color: inherit; background: rgba(255, 255, 255, .12); cursor: pointer; font-size: 1.25rem; }
  .admin-side .admin-toggle:hover { background: rgba(255, 255, 255, .2); }
  .admin-side .admin-toggle-close { display: none; }
  .admin-side.is-open .admin-toggle-open { display: none; }
  .admin-side.is-open .admin-toggle-close { display: inline; }
  .admin-side .admin-menu { display: none; border-top: 1px solid rgba(255, 255, 255, .15); padding-top: .5rem; }
  .admin-side.is-open .admin-menu { display: flex; }
  .admin-main { padding: 1.25rem 1rem; }
}

/* Dashboard stat tiles: theme-aware tinted icon squares (no hardcoded pastels). */
.stat-icon { width: 2.5rem; height: 2.5rem; border-radius: var(--bs-border-radius); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }

/* Chart.js needs a sized, positioned parent to be responsive. */
.chart-box { position: relative; height: 260px; }
.chart-box-lg { position: relative; height: 340px; }

/* Location picker dialog (templates/partials/location-picker.eta). */
.loc-dialog {
  width: min(720px, 94vw); padding: 0; border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg);
  background: var(--bs-body-bg); color: var(--bs-body-color); box-shadow: var(--asc-shadow-lg);
}
.loc-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.loc-map { height: 380px; border-radius: var(--bs-border-radius); border: 1px solid var(--bs-border-color); }
[data-bs-theme="dark"] .loc-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
[data-bs-theme="dark"] .loc-map.leaflet-container { background: #1b1f23; }
