/* === AGRISENSE theme — built on Bootstrap 5.3 ===
 * This file is a thin THEME LAYER on top of Bootstrap 5.3.3.
 * It does NOT re-implement components that Bootstrap already provides
 * (cards, nav, badges, progress, tables, grids, buttons, toasts, etc.).
 * It only:
 *   1. Maps the AGRISENSE palette onto Bootstrap CSS variables (--bs-*).
 *   2. Defines Inter as the base font + Material Symbols sizing.
 *   3. Adds custom layout primitives Bootstrap lacks: login photo column,
 *      app-shell/sidebar grid, top header, profile card, mic/voice visuals.
 * Agents E/F/G should prefer Bootstrap utility classes for everything else.
 * See public/DESIGN.md for the full contract.
 */

/* 1. Bootstrap variable overrides (color tokens) */
:root {
  --bs-primary: #228B22;
  --bs-primary-rgb: 34, 139, 34;
  --bs-link-color: #228B22;
  --bs-link-hover-color: #0c611d;

  /* AGRISENSE palette (mapped) */
  --ag-forest: #228B22;
  --ag-forest-dark: #0c611d;
  --ag-lime: #8BC34A;
  --ag-gold: #F9A825;
  --ag-ink: #17231a;
  --ag-muted: #6f7d72;
  --ag-line: #dfe8df;
  --ag-off: #FAFAFA;
  --ag-soft: #f2f7f1;
  --ag-shadow: 0 16px 35px rgba(18, 55, 24, .08);
}

/* 2. Base overrides */
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; background: var(--ag-off); color: var(--ag-ink); overflow-x: hidden; }
html { overflow-x: hidden; }
h1, h2, h3, h4, h5, h6 { font-family: 'Inter', system-ui, -apple-system, sans-serif; }

.btn-primary {
  --bs-btn-bg: var(--ag-forest);
  --bs-btn-border-color: var(--ag-forest);
  --bs-btn-hover-bg: var(--ag-forest-dark);
  --bs-btn-hover-border-color: var(--ag-forest-dark);
  --bs-btn-active-bg: var(--ag-forest-dark);
  --bs-btn-active-border-color: var(--ag-forest-dark);
  --bs-btn-disabled-bg: var(--ag-forest);
  --bs-btn-disabled-border-color: var(--ag-forest);
}
.btn-outline-primary {
  --bs-btn-color: var(--ag-forest);
  --bs-btn-border-color: var(--ag-forest);
  --bs-btn-hover-bg: var(--ag-forest);
  --bs-btn-hover-border-color: var(--ag-forest);
  --bs-btn-active-bg: var(--ag-forest);
  --bs-btn-active-border-color: var(--ag-forest);
}
.btn-warning {
  --bs-btn-color: #000;
  --bs-btn-bg: var(--ag-gold);
  --bs-btn-border-color: var(--ag-gold);
}
.link-primary { color: var(--ag-forest) !important; }
.text-primary { color: var(--ag-forest) !important; }
.text-muted { color: var(--ag-muted) !important; }
.bg-primary { background-color: var(--ag-forest) !important; }
.bg-soft { background-color: var(--ag-soft) !important; }
.border-primary { border-color: var(--ag-forest) !important; }
a { color: var(--ag-forest); }

/* 3. Material Symbols sizing */
.material-symbols-rounded { font-size: 1.5rem; vertical-align: middle; line-height: 1; }
.material-symbols-rounded.sm { font-size: 1.125rem; }
.material-symbols-rounded.lg { font-size: 2rem; }
.material-symbols-rounded.xl { font-size: 2.5rem; }
.nav-link .material-symbols-rounded { font-size: 1.25rem; }

/* 4. Custom components NOT covered by Bootstrap */

/* Login screen — branded gradient + logo lockup column */
.login-screen { display: grid; grid-template-columns: 1.08fr .92fr; min-height: 100vh; }
.login-photo {
  position: relative;
  background: linear-gradient(135deg, var(--ag-forest) 0%, var(--ag-forest-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-overlay { display: none; } /* kept for legacy markup; gradient replaces old photo */
.login-brand { position: relative; text-align: center; color: #fff; padding: 2rem; max-width: 540px; }
.login-brand p { font-size: 1.15rem; margin-top: 1rem; opacity: .92; line-height: 1.55; }
.login-brand .logo-img-large {
  width: 280px;
  background: rgba(255, 255, 255, .95);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .18);
  margin: 0 auto 20px;
}
.login-panel { display: grid; place-items: center; padding: 3rem; }

/* Voice mic + waveform animation */
@keyframes ag-pulse { 0% { box-shadow: 0 0 0 0 rgba(249, 168, 37, .45); } 100% { box-shadow: 0 0 0 28px rgba(249, 168, 37, 0); } }
@keyframes ag-wave { 50% { height: 18px; } }
.mic-btn {
  width: 88px; height: 88px; border-radius: 50%; border: 0;
  background: var(--ag-forest); color: #fff;
  display: grid; place-items: center; cursor: pointer; margin: 0 auto;
  transition: background .2s ease;
}
.mic-btn.recording { animation: ag-pulse 1.6s infinite; background: var(--ag-gold); }
.mic-btn .material-symbols-rounded { font-size: 2.5rem; }
.wave { display: flex; gap: 4px; align-items: center; justify-content: center; height: 32px; margin: 16px 0; }
.wave span { width: 4px; height: 10px; background: var(--ag-lime); border-radius: 2px; animation: ag-wave 1s infinite; }
.wave span:nth-child(2n) { animation-delay: .15s; }
.wave span:nth-child(3n) { animation-delay: .3s; }

/* App shell — sidebar + workspace grid */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: #fff; border-right: 1px solid var(--ag-line);
  padding: 1.5rem 1.125rem;
  display: flex; flex-direction: column; gap: 1.375rem;
}
.sidebar .nav-link {
  color: #59665c; border-radius: 12px; margin-bottom: 4px;
  font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.sidebar .nav-link:hover { background: #f4faef; color: #324336; }
.sidebar .nav-link.active { background: var(--ag-forest); color: #fff; }
.sidebar .nav-link .material-symbols-rounded { font-size: 1.25rem; margin-right: 4px; }

/* Profile card in sidebar */
.profile-card {
  margin-top: auto;
  background: #f5f9f4;
  border: 1px solid var(--ag-line);
  border-radius: 16px;
  padding: 14px;
  display: flex; gap: 12px; align-items: center;
}
.profile-card small { display: block; color: var(--ag-muted); margin: 3px 0; }
.avatar { width: 46px; height: 46px; border-radius: 12px; background: var(--ag-forest); color: #fff; display: grid; place-items: center; font-weight: 800; }
.status-dot { font-size: 12px; color: var(--ag-forest); font-weight: 700; }
.status-dot::before { content: ""; display: inline-block; width: 8px; height: 8px; background: var(--ag-lime); border-radius: 50%; margin-right: 6px; }

/* Top header */
.top-header {
  height: 92px; background: #fff; border-bottom: 1px solid var(--ag-line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; position: sticky; top: 0; z-index: 3;
}
.top-header p { margin: 7px 0 0; color: var(--ag-muted); }

/* Logo */
.logo-img { display: block; width: 178px; max-width: 100%; height: auto; object-fit: contain; }
.sidebar-logo { width: 190px; }
.mobile-brand .logo-img { width: 170px; }

/* Login panel responsive padding */
.login-panel { display: grid; place-items: center; padding: 3rem; }

/* Responsive table wrapper (for recommendations) */
.table-responsive-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 6. Responsive */
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

@media (max-width: 991.98px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .top-header {
    height: auto;
    padding: .75rem 1rem;
    flex-wrap: wrap;
    gap: .5rem;
  }
  .top-header > div:last-child { width: 100%; justify-content: flex-end; }
  .top-header .input-group { max-width: 200px; }
}

@media (max-width: 767.98px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-photo { display: none; }
  .login-panel { padding: 1.5rem 1.25rem; }
  .mobile-brand { text-align: center; }

  .top-header { padding: .625rem .875rem; }
  .top-header .input-group { display: none; }
  .top-header #pageTitle { font-size: 1.1rem; }
  .top-header #pageSubtitle { display: none; }

  .page-content { padding: 1rem .875rem !important; }

  /* container-fluid has negative margins that overflow on mobile */
  .container-fluid { padding-left: 0; padding-right: 0; }

  /* Row negative-margin fix: prevent .row from spilling outside viewport on mobile */
  .row { margin-left: 0; margin-right: 0; }
  .row > * { padding-left: .375rem; padding-right: .375rem; }

  /* Metric rows: stack vertically instead of 3-across */
  .row-cols-3 { --bs-cols: 1; }
  .row.row-cols-3 > .col { flex: 0 0 100%; max-width: 100%; }

  /* Recommendations table: horizontal scroll inside card only */
  .table { min-width: 600px; }
  .table-responsive-wrap { overflow-x: auto; }

  .btn-group { flex-wrap: wrap; }

  /* Forecast strip: allow horizontal scroll within the card, not the page */
  .overflow-auto { max-width: 100%; }

  /* Prices cards stack */
  .col-md-4 { flex: 0 0 100%; max-width: 100%; }

  /* Nutrition cards: 2-up on small screens */
  .col-md-3 { flex: 0 0 50%; max-width: 50%; }

  /* === Compact mobile sizing: smaller icons, tighter spacing === */
  /* Shrink all Material Symbols on mobile */
  .material-symbols-rounded { font-size: 1.125rem; }
  .material-symbols-rounded.sm { font-size: .875rem; }
  .material-symbols-rounded.lg { font-size: 1.5rem; }
  .material-symbols-rounded.xl { font-size: 1.875rem; }

  /* Shrink Bootstrap Icons on mobile */
  .bi { font-size: .875rem; }
  .bi.fs-1 { font-size: 1.5rem !important; }
  .bi.fs-5 { font-size: 1rem !important; }

  /* Compact cards: less padding */
  .card-body { padding: .875rem .75rem; }

  /* Compact headings */
  .card-title { font-size: 1rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.05rem; }
  h5 { font-size: .95rem; }

  /* Smaller metrics */
  .fs-2 { font-size: 1.25rem !important; }
  .fs-4 { font-size: 1rem !important; }
  .fs-5 { font-size: .875rem !important; }

  /* Tighter badges */
  .badge { font-size: .65rem; padding: .25em .45em; }

  /* Smaller buttons */
  .btn { font-size: .8125rem; padding: .3125rem .625rem; }
  .btn-sm { font-size: .75rem; padding: .1875rem .5rem; }
  .btn-lg { font-size: .9375rem; padding: .5rem 1rem; }

  /* Compact list items */
  .list-group-item { padding: .5rem .625rem; }

  /* Tighter progress bars */
  .progress { height: .5rem; }

  /* Section labels smaller */
  .text-uppercase.small { font-size: .65rem !important; }

  /* Soil/weather large icons in cards: smaller */
  .card .material-symbols-rounded { font-size: 1rem; }
}

@media (max-width: 400px) {
  .login-panel { padding: 1rem .875rem; }
  .login-brand .logo-img-large { width: 220px; }
  .logo-img, .sidebar-logo { width: 150px; }
  .mobile-brand .logo-img { width: 140px; }
}