/* Castells web — design system */

:root {
  --ink:        #1c2228;
  --ink-muted:  #5a636d;
  --accent:     #8f3d3a;
  --accent-hi:  #a84a46;
  --accent-soft:#f3ebe9;
  --bg:         #f6f5f2;
  --surface:    #ffffff;
  --border:     #e6e2dc;
  --border-soft:#efede8;
  --shadow-sm:  0 1px 2px rgba(28, 34, 40, 0.05);
  --shadow-md:  0 8px 28px rgba(28, 34, 40, 0.08);
  --shadow-lg:  0 20px 48px rgba(28, 34, 40, 0.12);
  --radius:     10px;
  --radius-lg:  14px;
  --font-display: 'Raleway', system-ui, sans-serif;
  --font-sans:    'Roboto', system-ui, sans-serif;
  --tracking-caps: 0.12em;
  --header-h:   64px;
}

/* ---- Base ---- */
body {
  font-family: var(--font-sans);
  font-weight: 400;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6,
.section-title,
.site-brand,
.card-header,
.page-title,
.home-card-title {
  font-family: var(--font-display);
  color: var(--ink);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hi);
}

/* ---- Header ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}

.site-header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-brand-logo {
  display: block;
  height: 1.15em;
  width: auto;
  flex-shrink: 0;
}
.site-brand:hover {
  color: var(--accent);
}

.site-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.site-nav-link {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink-muted);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.site-nav-link:hover {
  color: var(--ink);
  background: var(--accent-soft);
}
.site-nav-link.is-active {
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-soft);
}

.nav-toggle {
  display: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

@media (max-width: 767px) {
  .nav-toggle { display: flex; }
  .site-nav {
    display: none;
    position: absolute;
    top: var(--header-h);
    right: 0;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    margin-left: 0;
  }
  .site-nav.is-open { display: flex; }
  .site-nav-link {
    padding: 0.65rem 0.85rem;
  }
}

/* ---- Main & footer ---- */
.site-content {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.page-main {
  flex: 1;
  max-width: 1320px;
  padding: 2rem 1.5rem 3rem;
}

.page-home .site-header {
  background: transparent;
  backdrop-filter: none;
  border-bottom: none;
  position: absolute;
  width: 100%;
}
.page-home .site-brand,
.page-home .site-nav-link {
  color: rgba(255, 255, 255, 0.92);
}
.page-home .site-nav-link:hover,
.page-home .site-nav-link.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.page-home .nav-toggle span {
  background: #fff;
}

.site-footer {
  flex-shrink: 0;
  padding: 0;
}

/* Tagline strip; slightly lighter dark band */
.site-footer-partners {
  padding: 0.75rem 1.5rem;
  background: linear-gradient(180deg, #3a424c 0%, #323a44 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.site-footer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}

.site-footer-tagline {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
  flex: 1 1 auto;
  min-width: min(100%, 14rem);
  max-width: 36rem;
}

/* ---- Page chrome ---- */
.page-header {
  margin-bottom: 1.75rem;
}
.page-title {
  font-size: 1.65rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}
.page-lead {
  font-size: 0.95rem;
  color: var(--ink-muted);
  margin: 0;
  max-width: 42rem;
}

/* ---- Hero (landing) ---- */
.hero {
  position: relative;
  min-height: 52vh;
  background-size: cover;
  background-position: center 35%;
  display: flex;
  align-items: flex-end;
  margin-top: calc(-1 * var(--header-h));
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    165deg,
    rgba(20, 24, 28, 0.35) 0%,
    rgba(20, 24, 28, 0.55) 45%,
    rgba(20, 24, 28, 0.88) 100%
  );
}

.hero-inner {
  position: relative;
  z-index: 1;
  padding: 5rem 1.5rem 2.25rem;
  color: #fff;
  max-width: 1320px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* Bottom row: CTA buttons */
.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.75rem 1.5rem;
  width: 100%;
}

.hero-eyebrow {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  opacity: 0.85;
  margin-bottom: 0.75rem;
}

.hero-title {
  font-size: clamp(2.1rem, 5vw, 3rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  color: #fff;
  max-width: 100%;
}

.hero-title-row {
  display: inline-flex;
  align-items: center;
  gap: clamp(0.5rem, 1.5vw, 0.85rem);
}

.hero-title-logo {
  display: block;
  height: 0.95em;
  width: auto;
  flex-shrink: 0;
}

/* One line on typical desktop / tablet landscape (narrow phones may still wrap) */
@media (min-width: 768px) {
  .hero-title-row {
    white-space: nowrap;
  }
}

.hero-lead {
  font-size: 1.05rem;
  font-weight: 300;
  line-height: 1.6;
  opacity: 0.9;
  max-width: 36rem;
  margin-bottom: 1.5rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn-hero {
  padding: 0.65rem 1.35rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.btn-hero:hover { transform: translateY(-1px); }

.btn-hero-primary {
  background: #fff;
  color: var(--ink);
  border-color: #fff;
}
.btn-hero-primary:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
}

.btn-hero-ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
}
.btn-hero-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: #fff;
}

/* ---- Home page bands (full-width section backgrounds) ---- */
.home-band {
  width: 100%;
  padding: 3.5rem 0 4rem;
}

.home-band-analysis {
  background: var(--bg);
}

.home-band-model {
  background: #ebe8e3;
}

.home-band .container-xl {
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.section-header {
  margin-bottom: 2rem;
  max-width: 32rem;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  margin-bottom: 0.5rem;
}

.section-subtitle {
  font-size: 0.95rem;
  color: var(--ink-muted);
  margin: 0;
}

.home-grid {
  display: grid;
  /* auto-fit (not auto-fill): collapse empty tracks so 3 or 4 cards share row width evenly */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 1.25rem;
}

.home-card {
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.5rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}
.home-card:hover {
  color: var(--ink);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.home-card-label {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.home-card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.home-card-text {
  font-size: 0.88rem;
  color: var(--ink-muted);
  line-height: 1.5;
  flex: 1;
  margin-bottom: 1rem;
}

.home-card-link {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
}

.home-card-muted .home-card-label {
  color: var(--ink-muted);
}

/* ---- Home: model section (text + image) ---- */
.home-model-layout {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 40%);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
}

.home-model-copy .section-title {
  margin-bottom: 1rem;
}

.home-model-text {
  margin: 0;
  max-width: 36rem;
  font-size: 1.05rem;
  line-height: 1.8;
  font-weight: 300;
  color: var(--ink);
}

.home-model-figure {
  margin: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.home-model-figure img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center center;
}

@media (max-width: 900px) {
  .home-model-layout {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .home-model-figure {
    max-width: 32rem;
  }

  .home-model-text {
    max-width: none;
  }
}

/* ---- Cards (app pages) ---- */
.card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}

.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  border-radius: var(--radius) var(--radius) 0 0 !important;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding: 0.85rem 1.15rem;
}

/* Castells page: chart tabs inside card body (avoids Bootstrap card-header-tabs overflow) */
.castells-chart-card .card-body {
  overflow: hidden;
}

.castells-chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.75rem 1rem 0;
  margin: 0;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}

.castells-chart-tabs .nav-item {
  margin: 0;
}

.castells-chart-tabs .nav-link {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 0.5rem 1rem;
  margin: 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.castells-chart-tabs .nav-link:hover {
  color: var(--ink);
  background: #fff;
  border-color: var(--border);
}

.castells-chart-tabs .nav-link.active {
  color: var(--accent);
  font-weight: 500;
  background: var(--surface);
  border-color: var(--border-soft);
  border-bottom-color: var(--surface);
  position: relative;
  z-index: 1;
  margin-bottom: -1px;
  padding-bottom: calc(0.5rem + 1px);
}

.castells-chart-panes {
  padding: 0.25rem;
  background: var(--surface);
}

.filter-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.filter-card .card-header > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.colla-switcher .form-select {
  min-width: min(320px, 100%);
}

.colla-header .colla-switcher {
  flex-shrink: 0;
}

/* ---- Buttons ---- */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
}

.btn-outline-primary {
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline-primary:hover {
  background: var(--accent-soft);
  color: var(--accent-hi);
  border-color: var(--accent);
}

/* ---- Tables ---- */
.table-responsive {
  max-height: 440px;
  overflow-y: auto;
}
.table-responsive thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  white-space: nowrap;
  border-bottom-width: 1px;
}

.table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}
.table th,
.table td {
  vertical-align: middle;
  border-color: var(--border-soft);
}

.table-sm td,
.table-sm th {
  padding: 0.32rem 0.65rem;
  font-size: 0.82rem;
}

.table-sm th {
  white-space: nowrap;
  font-weight: 500;
  color: var(--ink-muted);
  font-size: 0.78rem;
  text-transform: none;
}
.table-sm th br {
  display: block;
  content: '';
}

.table thead th[style*="cursor"] { user-select: none; }
.sort-ind { font-size: 0.7rem; opacity: 0.5; }

.table-striped tbody tr:nth-of-type(odd) td {
  background-color: rgba(28, 34, 40, 0.02);
}

/* ---- Charts ---- */
.js-plotly-plot {
  min-height: 200px;
}

/* ---- Stat cards (colla) ---- */
.stat-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.stat-card .fw-bold {
  font-family: var(--font-sans);
  font-weight: 300;
  font-size: 2rem;
  line-height: 1.1;
  color: var(--ink);
}
.stat-card .label {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
}

/* ---- Colla page header ---- */
.colla-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.colla-header .page-title {
  margin: 0;
  flex: 1;
  min-width: 200px;
}

/* ---- Forms ---- */
.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(143, 61, 58, 0.15);
}

.form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

/* ---- Utility ---- */
.text-muted { color: var(--ink-muted) !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }

.alert-danger {
  background: #faf0ef;
  border-color: #e8d4d3;
  color: #6b3330;
}
