/* =========================================================================
   AgroSolutions — Stakeholder Dashboard
   Light, mobile-first design with a green (#16a34a) accent.
   ========================================================================= */

:root {
  --color-bg: #f6f8f7;
  --color-surface: #ffffff;
  --color-border: #e5e9e7;
  --color-text: #0f172a;
  --color-text-muted: #5b6b65;
  --color-text-subtle: #8a9994;

  --color-accent: #16a34a;
  --color-accent-soft: #dcfce7;
  --color-accent-strong: #15803d;

  --color-up: #16a34a;
  --color-down: #dc2626;
  --color-down-soft: #fee2e2;
  --color-neutral: #64748b;
  --color-neutral-soft: #e2e8f0;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04),
    0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06),
    0 2px 4px rgba(15, 23, 42, 0.04);

  --header-height: 60px;
  --modebar-height: 76px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

p {
  margin: 0;
  color: var(--color-text-muted);
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--color-border);
}

.app-header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-header__logos {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.brand-logo {
  display: block;
  border-radius: 6px;
}

.brand-logo--header {
  width: 28px;
  height: 28px;
}

.app-header__brand h1 {
  font-size: 19px;
  font-weight: 800;
}

.app-header__subtitle {
  color: var(--color-text-subtle);
  font-size: 14px;
  font-weight: 500;
  border-left: 1px solid var(--color-border);
  padding-left: 10px;
}

@media (max-width: 540px) {
  .app-header__subtitle {
    display: none;
  }
}

/* ---------- Mode bar (sticky, centered, big) ---------- */

.mode-bar {
  position: sticky;
  top: var(--header-height);
  z-index: 19;
  background: rgba(246, 248, 247, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 16px;
  display: flex;
  justify-content: center;
}

.mode-toggle {
  display: inline-flex;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px;
  gap: 4px;
  box-shadow: var(--shadow-md);
}

.mode-toggle__btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  padding: 11px 26px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.mode-toggle__btn:hover {
  color: var(--color-text);
}

.mode-toggle__btn.is-active {
  background: var(--color-accent);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(22, 163, 74, 0.35);
}

.mode-toggle__btn img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: block;
}

@media (max-width: 540px) {
  .mode-toggle__btn {
    padding: 9px 14px;
    font-size: 14px;
    gap: 7px;
  }
  .mode-toggle__btn img {
    width: 20px;
    height: 20px;
  }
}

/* ---------- Segmented control (small, used inside chart cards) ---------- */

.segmented {
  display: inline-flex;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}

.segmented__btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.segmented__btn:hover {
  color: var(--color-text);
}

.segmented__btn.is-active {
  background: var(--color-surface);
  color: var(--color-accent-strong);
  box-shadow: var(--shadow-sm);
}

.segmented--small .segmented__btn {
  padding: 5px 12px;
  font-size: 13px;
}

/* ---------- Container & sections ---------- */

.container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section__header h2 {
  font-size: 18px;
  margin-bottom: 2px;
}

.section__header p {
  font-size: 12.5px;
  line-height: 1.45;
  max-width: 920px;
}

/* Three columns on desktop: total KPI | evolution KPI | chart (wider).
   The .kpi-col wrapper uses display:contents so its KPI children become
   direct grid items and align side-by-side with the chart. */
.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2.2fr);
  gap: 12px;
  align-items: stretch;
}

.section-grid > .kpi-card,
.section-grid > .chart-card {
  height: 180px;
}

.kpi-col {
  display: contents;
}

@media (max-width: 1100px) {
  .section-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .section-grid .chart-card {
    grid-column: 1 / -1;
    height: auto;
  }
  .section-grid .chart-card__body {
    flex: 0 0 auto;
    height: 220px;
  }
}

@media (max-width: 640px) {
  .section-grid {
    grid-template-columns: 1fr;
  }
  .section-grid .chart-card {
    grid-column: auto;
    height: auto;
  }
  .section-grid .chart-card__body {
    flex: 0 0 auto;
    height: 220px;
  }
  .section-grid > .kpi-card {
    height: auto;
  }
}

/* ---------- KPI cards ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.kpi-card__header h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.kpi-card__header p {
  font-size: 12px;
  color: var(--color-text-subtle);
  line-height: 1.35;
}

.kpi-card__value {
  position: relative;
  min-height: 36px;
  display: flex;
  align-items: center;
  margin-top: auto;
}

.kpi-card__number {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.kpi-card__delta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.kpi-card.is-loading .kpi-card__number {
  visibility: hidden;
}

.kpi-card .skeleton {
  display: none;
}

.kpi-card.is-loading .skeleton {
  display: block;
  position: absolute;
  inset: 6px 40% 6px 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--color-neutral-soft) 0%,
    #f1f5f9 50%,
    var(--color-neutral-soft) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.kpi-card__delta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-card__delta-label {
  font-size: 12px;
  color: var(--color-text-subtle);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
}

.badge--up {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

.badge--down {
  background: var(--color-down-soft);
  color: var(--color-down);
}

.badge--neutral {
  background: var(--color-neutral-soft);
  color: var(--color-neutral);
}

.badge__arrow {
  font-weight: 700;
}

/* ---------- Chart cards ---------- */

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chart-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-card__header h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.chart-card__header p {
  font-size: 12px;
  color: var(--color-text-subtle);
}

.chart-card__body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.chart-card__body canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* ---------- Spinner ---------- */

.chart-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  z-index: 1;
}
.chart-spinner[hidden] {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--color-neutral-soft);
  border-top-color: var(--color-accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Error banner ---------- */

.error-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-down-soft);
  color: var(--color-down);
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
}
.error-banner[hidden] {
  display: none;
}

.error-banner__icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-down);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.error-banner__text {
  flex: 1;
}

.error-banner__close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--color-down);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

/* ---------- Footer ---------- */

.app-footer {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-subtle);
  padding: 16px 0 0;
}

/* ---------- Mobile tweaks ---------- */

@media (max-width: 640px) {
  .container {
    padding: 14px 14px 32px;
    gap: 18px;
  }

  .kpi-card {
    padding: 14px 16px;
  }

  .kpi-card__number {
    font-size: 28px;
  }

  .chart-card {
    padding: 14px 14px;
  }

  .chart-card__header {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-card__body {
    min-height: 260px;
  }

  .segmented--small {
    align-self: flex-start;
  }

  .app-header__brand h1 {
    font-size: 17px;
  }
}

/* ---------------------------------------------------------------------- */
/* Login page                                                              */
/* ---------------------------------------------------------------------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f7faf9 0%, #eef4f1 100%);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  padding: 24px;
}
.login-card {
  width: min(380px, 92vw);
  background: #fff;
  border: 1px solid #e6ebe8;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}
.login-card__brand {
  text-align: center;
  margin-bottom: 22px;
}
.login-card__logos {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.brand-logo--login {
  width: 80px;
  height: 80px;
  border-radius: 14px;
}
.login-card__brand h1 {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 700;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #374151;
  font-weight: 500;
}
.login-form input {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus {
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}
.login-btn {
  margin-top: 6px;
  padding: 11px 14px;
  border: 0;
  border-radius: 10px;
  background: #16a34a;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s;
}
.login-btn:hover {
  background: #15803d;
}
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
}

/* Sign-out link in header */
.logout-link {
  margin-left: 16px;
  color: #6b7280;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.logout-link:hover {
  background: #f3f4f6;
  color: #111827;
}
