/* Layout stylesheet for the dashboard shell (nav, filters sidebar, login
   page). Component-level chart/tile colours stay in theme.py — this file
   is structure/layout only, kept out of the Python callbacks so the two
   can change independently.

   Dash serves everything in this folder automatically, mounted at /assets.
*/

:root {
  --colour-primary: #1d70b8;
  --colour-border: #b1b4b6;
  --colour-danger: #d4351c;
  --colour-nav-bg: #f3f2f1;
  --colour-filters-bg: #f8f8f8;
  /* Both scale with viewport width instead of staying pinned at their
     desktop max on screens well short of a big monitor. Floors keep the nav
     labels/filter controls usable; caps match the previous fixed widths on
     wide screens. Below the 900px off-canvas breakpoint this is moot — that
     mode uses its own fixed widths. */
  --nav-width: clamp(170px, 15vw, 220px);
  --filters-width: clamp(280px, 22vw, 420px);
  --content-max-width: 960px;
  --topbar-height: 56px;
}

* {
  box-sizing: border-box;
}

/* dcc.Input renders <div class="dash-input-container"><input
   class="dash-input-element">; a `style` prop passed from Python only
   reaches the outer container div, not the actual <input>, which otherwise
   falls back to the browser's native ~20-character default width and clips
   longer values regardless of how wide the container is sized. Applies
   everywhere a dcc.Input is used, not just the login page. */
.dash-input-container .dash-input-element {
  width: 100%;
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #0b0c0c;
}

a {
  color: var(--colour-primary);
}

/* ── Shell ────────────────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 2px solid var(--colour-primary);
}

.topbar-title {
  font-weight: 700;
}

.topbar-spacer {
  flex: 1 1 auto;
}

.topbar-logout {
  text-decoration: none;
}

.icon-btn {
  background: none;
  border: 1px solid var(--colour-border);
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1.2;
}

.icon-btn:hover {
  background: var(--colour-nav-bg);
}

.app-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* ── Per-page title + description (inside main content) ─────────────────── */

.page-lead {
  margin: 0.25rem 0 1.25rem;
  color: #505a5f;
}

/* ── Left nav ─────────────────────────────────────────────────────────── */

.left-nav {
  width: var(--nav-width);
  flex-shrink: 0;
  background: var(--colour-nav-bg);
  border-right: 1px solid var(--colour-border);
  padding: 1rem 0.5rem;
  overflow: hidden;
  transition: width 0.2s ease, padding 0.2s ease;
}

.app-shell.nav-toggled .left-nav {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: none;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  text-decoration: none;
  color: #0b0c0c;
  white-space: nowrap;
}

.nav-link:hover {
  background: #dbdad9;
}

/* Separates the nav into Analysis / Settings / Admin groups. */
.nav-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--colour-border);
  margin: 0.5rem 0;
}

/* ── Right filters sidebar ────────────────────────────────────────────── */

.right-filters {
  width: var(--filters-width);
  flex-shrink: 0;
  background: var(--colour-filters-bg);
  border-left: 1px solid var(--colour-border);
  padding: 1rem;
  overflow: auto;
  transition: width 0.2s ease, padding 0.2s ease;
}

.app-shell.filters-toggled .right-filters {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-left: none;
  overflow: hidden;
}

.right-filters-title {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #505a5f;
}

.filters-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Separates data filters from chart-display options (colour-by, trendline)
   in the filters sidebar — a plain rule rather than another labelled
   section, since it's one sidebar with two kinds of control in it. */
.filters-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--colour-border);
  margin: 0;
}

/* Metrics dropdown: the closed control truncates chosen values to a single
   "N selected" line by default — let it wrap and grow instead, with a
   little box around each chosen metric. */
.metric-multi-dropdown .dash-dropdown-trigger {
  height: auto;
  min-height: 2.25rem;
  align-items: flex-start;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
}

.metric-multi-dropdown .dash-dropdown-value {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.metric-multi-dropdown .dash-dropdown-value-item {
  display: inline-block;
  border: 1px solid var(--colour-border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  margin: 0.15rem 0.25rem 0.15rem 0;
  background: #fff;
  font-size: 0.8rem;
}

/* The default single-line display comma-separates items via ::before —
   redundant now that each item is its own boxed chip. */
.metric-multi-dropdown .dash-dropdown-value-item::before {
  content: none;
}

/* ── Main content ─────────────────────────────────────────────────────── */

.main-area {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  /* Shrinks on narrower screens instead of eating a fixed chunk of an
     already-tight width — same clamp() approach as the sidebars above. */
  padding: clamp(0.75rem, 1.4vw, 1.5rem) clamp(0.375rem, 1.1vw, 1rem);
  min-width: 0;
}

.main-area-inner {
  width: 100%;
  max-width: var(--content-max-width);
}

/* ── Login page ───────────────────────────────────────────────────────── */

.login-page {
  display: flex;
  justify-content: center;
  padding: 10vh 1rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 2rem;
}

.login-title {
  margin-bottom: 1.5rem;
}

.login-error {
  color: var(--colour-danger);
  margin-bottom: 0.75rem;
}

.login-input {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
}

.login-password-wrap {
  position: relative;
}

.login-password-wrap .login-input {
  padding-right: 3.5rem;
}

.login-password-toggle {
  position: absolute;
  right: 0.4rem;
  top: 0;
  height: calc(100% - 0.5rem);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--colour-primary);
  line-height: 1;
  padding: 0 0.35rem;
}

.login-button {
  width: 100%;
}

/* ── Responsive: off-canvas sidebars below 900px ─────────────────────── */

@media (max-width: 900px) {
  .app-body {
    position: relative;
  }

  .left-nav,
  .right-filters {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    z-index: 30;
    width: min(80vw, 280px);
    padding: 1rem;
    transition: transform 0.2s ease;
  }

  .left-nav {
    left: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .right-filters {
    right: 0;
    transform: translateX(100%);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .app-shell.nav-toggled .left-nav {
    width: min(80vw, 280px);
    padding: 1rem;
    border-right: 1px solid var(--colour-border);
    transform: translateX(0);
  }

  .app-shell.filters-toggled .right-filters {
    width: min(80vw, 280px);
    padding: 1rem;
    border-left: 1px solid var(--colour-border);
    overflow: auto;
    transform: translateX(0);
  }
}
