/* ==========================================================================
   Roost Targets Dashboard
   Design system: Jost (free Avant Garde Gothic clone), brand colours,
   modular type scale (12/14/16/20/24/32/48/64).
   ========================================================================== */

@font-face {
  font-family: 'Jost';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/jost-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Jost';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/jost-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Brand */
  --bg: #78D7E3;
  --bg-tint: #8DDDE7;
  --red: #9F3838;
  --red-deep: #8E2F2F;
  --red-light: #C76060;
  --dark: #2C3E47;
  --ink: #1F2D33;
  --light: #DCEDF1;
  --gauge-track: #A6E2EB;
  --divider: rgba(255, 255, 255, 0.55);

  --donut-rebecca: #9F3838;
  --donut-mark: #DCEDF1;
  --donut-thabit: #C2A78C;
  --donut-toby: #2D5662;

  /* Type scale */
  --t-xs:  12px;
  --t-sm:  13px;
  --t-md:  16px;
  --t-lg:  20px;
  --t-xl:  24px;
  --t-2xl: 32px;
  --t-3xl: 48px;
  --t-4xl: 56px;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: 'Jost', 'Century Gothic', 'Avant Garde', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   Dashboard grid
   -------------------------------------------------------------------------- */

.dash {
  position: relative;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--s-6) 40px var(--s-6) 40px;
  display: grid;
  grid-template-columns: repeat(4, 1fr) 400px;
  grid-template-rows: 56px auto auto;
  gap: 0;
  background: var(--bg);
}

.dash__head {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.dash__logo {
  height: 44px;
  width: auto;
  display: block;
}

/* --------------------------------------------------------------------------
   Broker cards
   -------------------------------------------------------------------------- */

.brokers {
  grid-column: 1 / 5;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  align-items: start;
}

.broker {
  --col-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 var(--s-2);
  position: relative;
  transition: transform 200ms ease, filter 200ms ease;
}
.broker:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 80px;
  width: 1px;
  background: var(--divider);
}

.broker__name {
  /* Only shown on mobile — hidden on desktop where photos are the identifier */
  display: none;
  font-size: var(--t-lg);
  font-weight: 700;
  color: var(--dark);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: var(--s-1);
  line-height: 1;
}

.broker__pct {
  font-size: var(--t-2xl);
  font-weight: 500;
  color: #fff;
  letter-spacing: -0.5px;
  margin-bottom: var(--s-2);
  line-height: 1;
}

.broker__photo {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 5px solid var(--red);
  background: #ddd center/cover no-repeat;
  margin-bottom: var(--s-3);
  box-shadow:
    0 4px 14px rgba(40, 60, 70, 0.12),
    0 1px 3px rgba(40, 60, 70, 0.08);
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.broker__gauge-wrap {
  width: var(--col-width);
  position: relative;
}
.broker__gauge {
  width: 100%;
  aspect-ratio: 240 / 130;
  position: relative;
}

.broker__volume {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  font-size: var(--t-4xl);
  font-weight: 700;
  color: #fff;
  line-height: 1;
  letter-spacing: -1.5px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.broker__minmax {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: var(--t-xs);
  color: #fff;
  font-weight: 500;
  margin-top: -2px;
  padding: 0 var(--s-1);
  letter-spacing: 0.3px;
}

.broker__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: var(--col-width);
  margin-top: var(--s-5);
  text-align: left;
  border-bottom: 1px solid var(--divider);
  padding-bottom: var(--s-4);
  column-gap: var(--s-2);
}
.stat__label {
  font-size: var(--t-xs);
  color: var(--dark);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: var(--s-1);
}
.stat__value {
  font-size: var(--t-xl);
  color: #fff;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.5px;
}

.broker__bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: var(--col-width);
  margin-top: var(--s-3);
  align-items: start;
  column-gap: var(--s-2);
}
.broker__quarters {
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.q-row {
  font-size: var(--t-md);
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: 0;
}
.q-row__num { display: block; }
.q-row__label {
  display: block;
  font-size: 10px;
  margin-top: 2px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--dark);
  opacity: 0.95;
}

.broker__nps {
  text-align: center;
  border-left: 1px solid var(--divider);
  padding-left: var(--s-3);
  align-self: stretch;
}
.broker__nps .stat__label {
  font-size: var(--t-xs);
  color: var(--dark);
  font-weight: 700;
}
.broker__nps .nps-score {
  font-size: 44px;
  color: #fff;
  font-weight: 700;
  line-height: 1;
  margin-top: var(--s-1);
  letter-spacing: -1px;
}

/* --------------------------------------------------------------------------
   Donut chart
   -------------------------------------------------------------------------- */

.donut {
  grid-column: 5;
  grid-row: 2;
  position: relative;
  padding: 0 var(--s-3);
  align-self: start;
}
.donut__svg {
  width: 100%;
  max-width: 400px;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.06));
}

/* --------------------------------------------------------------------------
   Roost Total
   -------------------------------------------------------------------------- */

.totals {
  /* Sit in the same row as the donut/brokers but bottom-anchored so it
     aligns visually with the bottom of the broker cards. */
  grid-column: 5;
  grid-row: 2;
  align-self: end;
  text-align: right;
  padding: 0 var(--s-3) 0 0;
}
.totals__label {
  font-size: var(--t-xl);
  color: var(--dark);
  font-weight: 500;
  line-height: 1.1;
}
.totals__value {
  font-size: var(--t-3xl);
  color: var(--dark);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1.5px;
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Bottom bars
   -------------------------------------------------------------------------- */

.bars {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-top: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.bar { position: relative; }
.bar__title {
  font-size: var(--t-sm);
  color: var(--red);
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  margin-bottom: var(--s-1);
}
.bar__track {
  position: relative;
  width: 100%;
  height: 52px;
  background: var(--light);
  border-radius: 3px;
  overflow: visible;
}
.bar--solid .bar__track {
  background: var(--red);
}
.bar__fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--red);
  border-radius: 3px 0 0 3px;
  transition: width 600ms cubic-bezier(0.4, 0, 0.2, 1);
}
.bar--solid .bar__fill {
  background: var(--red);
  border-radius: 3px;
}
.bar__marker {
  position: absolute;
  top: -22px;
  transform: translateX(-50%);
  font-size: var(--t-sm);
  color: var(--red);
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
}
.bar__marker::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  width: 2px;
  height: 52px;
  background: rgba(255, 255, 255, 0.95);
}
.bar__caption {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: 0 var(--s-4);
  font-size: var(--t-sm);
  color: #fff;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1;
}
.bar__caption .pct {
  font-size: var(--t-xl);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--red);
  line-height: 1;
}
.bar--solid .bar__caption .pct,
.bar--over .bar__caption .pct {
  color: #fff;
}

/* --------------------------------------------------------------------------
   Upload button + dialog
   -------------------------------------------------------------------------- */

.upload-btn {
  position: fixed;
  right: var(--s-4);
  top: var(--s-4);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(159, 56, 56, 0.85);
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: transform 200ms ease, background 200ms ease, opacity 200ms ease;
  z-index: 100;
  opacity: 0.55;
}
.upload-btn:hover,
.upload-btn:focus-visible {
  transform: scale(1.08);
  opacity: 1;
  background: var(--red);
  outline: none;
}
.upload-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7), 0 4px 14px rgba(0, 0, 0, 0.15);
}
.upload-btn svg { width: 20px; height: 20px; }

/* Focus rings (accessibility) */
:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 2px;
}

.dlg {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 540px;
  width: 90%;
  font-family: 'Jost', system-ui, sans-serif;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px); }
.dlg__inner { padding: var(--s-6); display: flex; flex-direction: column; gap: var(--s-3); }
.dlg h2 { margin: 0; font-size: var(--t-lg); font-weight: 600; color: var(--ink); }
.dlg p { margin: 0; font-size: var(--t-sm); color: #555; }
.drop {
  border: 2px dashed #c7c7c7;
  border-radius: 8px;
  padding: var(--s-5);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  align-items: center;
  color: #666;
  transition: border-color 200ms ease, background 200ms ease;
}
.drop.is-over { border-color: var(--red); background: #fef5f5; }
.dlg textarea {
  width: 100%;
  font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
  font-size: var(--t-xs);
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: var(--s-2);
  resize: vertical;
  line-height: 1.5;
}
.dlg textarea:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(159, 56, 56, 0.15);
}
.dlg .row { display: flex; flex-direction: column; gap: var(--s-1); font-size: var(--t-sm); }
.dlg .row input {
  padding: var(--s-2);
  border: 1px solid #ccc;
  border-radius: 6px;
  font: inherit;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.dlg .row input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(159, 56, 56, 0.15);
}
.dlg__actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-1);
}
.dlg__msg { min-height: 18px; font-size: var(--t-sm); color: #666; margin: 0; }
.dlg__msg.is-err { color: #b00; }
.dlg__msg.is-ok { color: #1a7f37; }

.btn {
  padding: 10px 16px;
  min-height: 44px;  /* touch target */
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: var(--t-sm);
  transition: background 150ms ease, border-color 150ms ease, transform 100ms ease;
}
.btn:hover { background: #f5f5f5; }
.btn:active { transform: scale(0.98); }
.btn--ghost { background: transparent; }
.btn--ghost:hover { background: rgba(0, 0, 0, 0.04); }
.btn--primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn--primary:hover { background: var(--red-deep); border-color: var(--red-deep); }

/* --------------------------------------------------------------------------
   Responsive — fluid breakpoints
   -------------------------------------------------------------------------- */

/* ▸ Large desktop: fill more of viewport when above 1600px */
@media (min-width: 1600px) {
  .dash { max-width: 1760px; }
}

/* ▸ Laptop (1280-1599): tighten donut column so it fits */
@media (max-width: 1599px) {
  .dash {
    grid-template-columns: repeat(4, 1fr) 300px;
    padding: var(--s-5) var(--s-6) var(--s-7) var(--s-6);
  }
  .broker { --col-width: 220px; }
  .broker__photo { width: 152px; height: 152px; border-width: 4px; }
  .broker__pct { font-size: var(--t-xl); }
  .broker__volume { font-size: var(--t-3xl); letter-spacing: -1px; }
  .stat__value { font-size: var(--t-lg); }
  .broker__nps .nps-score { font-size: 40px; }
  .totals__value { font-size: 40px; }
  .donut__svg { max-width: 280px; }
}

/* ▸ Medium (960-1319): cards full-width, donut + total in a sidebar row below */
@media (max-width: 1319px) {
  .dash {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 52px auto auto auto;
    padding: var(--s-5);
  }
  .brokers {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
  }
  .broker { --col-width: 200px; padding: 0 var(--s-1); }
  .broker__photo { width: 140px; height: 140px; }
  .broker__pct { font-size: var(--t-lg); margin-bottom: var(--s-1); }
  .broker__volume { font-size: var(--t-2xl); }
  .donut {
    grid-column: 1;
    grid-row: 3;
    padding: var(--s-5) 0 0 0;
    display: flex;
    justify-content: center;
  }
  .donut__svg { max-width: 280px; }
  .totals {
    grid-column: 2;
    grid-row: 3;
    text-align: right;
    padding: var(--s-7) 0 0 0;
    align-self: center;
  }
  .totals__value { font-size: var(--t-2xl); }
  .bars { grid-row: 4; }
}

/* ▸ Tablet (640-959): 2x2 broker grid */
@media (max-width: 959px) {
  .dash {
    padding: var(--s-4);
    grid-template-rows: 52px auto auto auto;
  }
  .brokers {
    grid-template-columns: 1fr 1fr;
    gap: var(--s-5) 0;
  }
  .broker { padding: 0 var(--s-3); }
  .broker:nth-child(2n)::after { display: none; }
  .broker__pct { font-size: var(--t-xl); }
  .broker__photo { width: 156px; height: 156px; }
  .broker__volume { font-size: var(--t-2xl); }
  .donut__svg { max-width: 260px; }
}

/* ▸ Phone (≤639px): single-column mobile layout
   - Logo + Roost Total in a compact header
   - Broker cards stack vertically, each one self-contained with name label
   - Donut moves below the cards
   - Bars at the very bottom, marker label inside the row instead of floating
*/
@media (max-width: 639px) {
  .dash {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    padding: var(--s-4) var(--s-4) calc(var(--s-7) + 56px);
    gap: 0;
  }

  /* Header: logo left, Roost Total right */
  .dash__head {
    grid-row: 1;
    justify-content: space-between;
    padding: 0;
    margin-bottom: var(--s-3);
  }
  .dash__logo { height: 32px; }

  /* Roost Total promoted into the header on mobile so it's the first thing seen */
  .totals {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    justify-self: end;
    text-align: right;
    padding: 0 60px 0 0;  /* leave space for upload button */
  }
  .totals__label { font-size: var(--t-sm); margin-bottom: 0; }
  .totals__value { font-size: var(--t-2xl); margin-top: 0; }

  /* Stacked broker cards */
  .brokers {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    gap: var(--s-4);
  }
  .broker {
    --col-width: 100%;
    padding: var(--s-4) var(--s-4);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
  }
  .broker:not(:last-child)::after { display: none; }
  .broker__name {
    display: block;
    text-align: center;
    margin-bottom: var(--s-1);
  }
  .broker__pct { font-size: var(--t-2xl); margin-bottom: var(--s-2); }
  .broker__photo {
    width: 120px;
    height: 120px;
    border-width: 4px;
  }
  .broker__gauge-wrap { width: min(280px, 100%); }
  .broker__volume { font-size: var(--t-2xl); letter-spacing: -0.8px; }
  .broker__stats { width: min(280px, 100%); }
  .broker__bottom { width: min(280px, 100%); }
  .stat__value { font-size: var(--t-lg); }
  .broker__nps .nps-score { font-size: var(--t-2xl); }

  /* Donut below brokers, centred */
  .donut {
    grid-column: 1;
    grid-row: 3;
    padding: var(--s-5) 0 0 0;
    display: flex;
    justify-content: center;
  }
  .donut__svg { max-width: 260px; }

  /* Bars at the bottom with inline captions (no floating marker) */
  .bars {
    grid-column: 1;
    grid-row: 4;
    margin-top: var(--s-5);
    gap: var(--s-4);
  }
  .bar { margin-bottom: 0; }
  .bar__track { height: 44px; }
  .bar__caption {
    position: static;
    transform: none;
    justify-content: space-between;
    padding: var(--s-2) 0 0 0;
    color: var(--ink);
    font-size: var(--t-xs);
    letter-spacing: 1px;
  }
  .bar__caption .pct { color: var(--red); font-size: var(--t-md); }
  .bar--solid .bar__caption {
    /* For the solid red bar (progress), keep caption inside the bar */
    position: absolute;
    inset: 0;
    color: #fff;
    padding: 0 var(--s-4);
    font-size: var(--t-xs);
  }
  .bar--solid .bar__caption .pct { color: #fff; font-size: var(--t-md); }
  .bar__marker {
    /* Marker label shrinks and hugs the top-right of the track */
    top: -18px;
    font-size: 11px;
  }
  .bar__marker::after { height: 44px; }

  /* Upload button bottom-right so it doesn't overlap the Roost Total */
  .upload-btn {
    top: auto;
    bottom: var(--s-4);
    right: var(--s-4);
    width: 48px;
    height: 48px;
  }
  .upload-btn svg { width: 22px; height: 22px; }
}

/* ▸ Tiny (≤419px) — iPhone SE etc. */
@media (max-width: 419px) {
  .dash { padding: var(--s-3) var(--s-3) calc(var(--s-7) + 56px); }
  .dash__logo { height: 28px; }
  .totals__value { font-size: var(--t-xl); }
  .broker { padding: var(--s-3); }
  .broker__photo { width: 104px; height: 104px; border-width: 3px; }
  .broker__pct { font-size: var(--t-xl); }
  .broker__volume { font-size: var(--t-xl); }
  .broker__nps .nps-score { font-size: var(--t-xl); }
  .donut__svg { max-width: 220px; }
}
