/* =========================================================================
   AgriMonitor — design tokens
   Palet: hijau muda + putih dominan, dengan aksen teal untuk data IoT/sensor
   Tipografi: Plus Jakarta Sans (UI) + Fraunces (angka besar & judul seksi)
   Signature: "growth ring" gauge melingkar (terinspirasi lingkar tahun pohon)
              & garis pemisah bermotif tulang daun
   ========================================================================= */

:root {
  --bg: #ffffff;
  --bg-soft: #f3f9f1;
  --surface: #ffffff;
  --surface-alt: #eef7ea;

  --primary: #3f7d3f;
  --primary-dark: #2c5c30;
  --primary-light: #8fc93a;
  --primary-softer: #e3f3dc;

  --accent-sky: #2f8f8a;
  --accent-sky-soft: #e2f3f1;

  --warn: #e2a33b;
  --warn-soft: #fbf0dc;
  --danger: #d9605a;
  --danger-soft: #fbe4e2;

  --ink: #1e2b1e;
  --ink-soft: #5b6b5b;
  --ink-faint: #8a9a89;
  --line: #dcead6;

  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: 'Segoe UI', Arial, Helvetica, sans-serif;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-card: 0 4px 24px rgba(63, 125, 63, 0.08);
  --shadow-pop: 0 12px 32px rgba(44, 92, 48, 0.14);

  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-soft);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

/* ------------------------------------------------------------------ */
/* Shell layout                                                        */
/* ------------------------------------------------------------------ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.main-area {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark), var(--primary) 70%);
  color: #eafbe6;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  z-index: 40;
  transition: transform .28s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
}
.sidebar-brand .leaf-mark {
  width: 38px; height: 38px;
  flex-shrink: 0;
}
.sidebar-brand h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.1;
}
.sidebar-brand span {
  display: block;
  font-size: .68rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #cdeec4;
  margin-top: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-nav .nav-eyebrow {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #b7dfae;
  padding: 10px 12px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  color: #eafbe6;
  opacity: .82;
  transition: background .15s ease, opacity .15s ease;
}
.nav-link svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-link:hover {
  background: rgba(255,255,255,.08);
  opacity: 1;
}
.nav-link.active {
  background: rgba(255,255,255,.16);
  opacity: 1;
  box-shadow: inset 3px 0 0 var(--primary-light);
}
.nav-link .badge-soon {
  margin-left: auto;
  font-size: .62rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  letter-spacing: .03em;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.08);
  font-size: .78rem;
  color: #d9f2d2;
}
.sidebar-footer strong { display: block; color: #fff; font-size: .85rem; }

/* Mobile topbar + toggle */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.mobile-topbar .brand-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--primary-dark);
}
.nav-toggle {
  border: none;
  background: var(--primary-softer);
  color: var(--primary-dark);
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 20, .35);
  z-index: 35;
}

/* ------------------------------------------------------------------ */
/* Content header                                                      */
/* ------------------------------------------------------------------ */
.content {
  padding: 32px 36px 56px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.page-header .eyebrow {
  font-size: .74rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--primary);
  font-weight: 700;
  margin: 0 0 6px;
}
.page-header h2 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  margin: 0;
  color: var(--ink);
}
.page-header p.sub {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: .93rem;
  max-width: 520px;
}
.header-meta {
  text-align: right;
  font-size: .82rem;
  color: var(--ink-soft);
}
.header-meta strong { color: var(--ink); font-size: .95rem; }

/* Leaf-vein section divider — signature element */
.leaf-divider {
  width: 100%;
  height: 22px;
  margin: 34px 0 22px;
  opacity: .55;
}

/* ------------------------------------------------------------------ */
/* Cards & grid                                                         */
/* ------------------------------------------------------------------ */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 0;
  color: var(--ink);
}
.section-title a.see-all {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
}

.grid {
  display: grid;
  gap: 18px;
}
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.card.flush { padding: 0; overflow: hidden; }

/* Stat card w/ growth-ring gauge */
.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-card .gauge-wrap { flex-shrink: 0; position: relative; width: 74px; height: 74px; }
.stat-card .gauge-value {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}
.stat-card .stat-label {
  font-size: .8rem;
  color: var(--ink-soft);
  margin: 0 0 2px;
}
.stat-card .stat-detail {
  font-size: .78rem;
  color: var(--ink-faint);
  margin: 4px 0 0;
}

/* Weather widget */
.weather-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.weather-hero .temp-big {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 600;
  color: var(--primary-dark);
  line-height: 1;
}
.weather-hero .condition {
  color: var(--ink-soft);
  font-size: .92rem;
  margin-top: 6px;
}
.weather-icon { width: 56px; height: 56px; color: var(--primary); }
.weather-stats {
  display: flex;
  gap: 22px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.weather-stats .item { font-size: .82rem; color: var(--ink-soft); }
.weather-stats .item strong { display: block; color: var(--ink); font-size: .98rem; }

.forecast-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 4px;
}
.forecast-chip {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 14px 8px;
  text-align: center;
}
.forecast-chip .day { font-size: .78rem; font-weight: 700; color: var(--primary-dark); }
.forecast-chip svg { width: 26px; height: 26px; margin: 6px auto; color: var(--primary); }
.forecast-chip .range { font-size: .78rem; color: var(--ink-soft); }
.forecast-chip .rain { font-size: .7rem; color: var(--accent-sky); margin-top: 3px; }

/* Irrigation zone cards */
.zone-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.zone-card .zone-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.zone-card h4 {
  margin: 0;
  font-size: 1rem;
  color: var(--ink);
}
.zone-card .sensor-name {
  font-size: .76rem;
  color: var(--ink-faint);
  margin-top: 2px;
}
.status-pill {
  font-size: .7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: .02em;
}
.status-pill.on { background: var(--primary-softer); color: var(--primary-dark); }
.status-pill.off { background: #eef1ee; color: var(--ink-faint); }

.moisture-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}
.moisture-track > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-sky), var(--primary-light));
  border-radius: 999px;
}
.moisture-label {
  display: flex;
  justify-content: space-between;
  font-size: .74rem;
  color: var(--ink-soft);
}

.zone-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.mode-switch {
  display: flex;
  background: var(--surface-alt);
  border-radius: 999px;
  padding: 3px;
  font-size: .76rem;
  font-weight: 600;
}
.mode-switch button {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
}
.mode-switch button.active {
  background: var(--primary);
  color: #fff;
}

.valve-toggle {
  position: relative;
  width: 46px; height: 26px;
  border-radius: 999px;
  background: #dfe6df;
  border: none;
  cursor: pointer;
  transition: background .2s ease;
}
.valve-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s ease;
}
.valve-toggle.is-on { background: var(--primary); }
.valve-toggle.is-on::after { transform: translateX(20px); }
.valve-toggle:disabled { opacity: .5; cursor: not-allowed; }

.zone-footnote {
  font-size: .72rem;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
}

/* Device / IoT connectivity strip */
.device-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.device-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-sky-soft);
  color: var(--accent-sky);
  font-weight: 600;
}
.device-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-sky); }
.device-chip.offline { background: var(--danger-soft); color: var(--danger); }
.device-chip.offline .dot { background: var(--danger); }

/* Coming soon */
.coming-soon-card {
  text-align: center;
  padding: 64px 24px;
}
.coming-soon-card .icon-wrap {
  width: 84px; height: 84px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--primary-softer);
  display: flex; align-items: center; justify-content: center;
}
.coming-soon-card .icon-wrap svg { width: 40px; height: 40px; color: var(--primary); }
.coming-soon-card h3 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 8px;
}
.coming-soon-card p {
  color: var(--ink-soft);
  max-width: 440px;
  margin: 0 auto 22px;
  font-size: .93rem;
  line-height: 1.55;
}
.coming-soon-card ul.feature-preview {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.coming-soon-card ul.feature-preview li {
  font-size: .78rem;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--primary-dark);
  font-weight: 600;
}
.notify-form {
  display: flex;
  gap: 8px;
  justify-content: center;
  max-width: 380px;
  margin: 0 auto;
}
.notify-form input {
  flex: 1;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: .88rem;
}
.notify-form button {
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
}

/* Alert banner (moisture rendah, dsb) */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--warn-soft);
  color: #8a5c14;
  font-size: .86rem;
  margin-bottom: 20px;
}
.alert-banner svg { width: 20px; height: 20px; flex-shrink: 0; }

/* Toast (hasil aksi AJAX) */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: .86rem;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all .25s ease;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */
@media (max-width: 1080px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
  }
  .sidebar {
    position: fixed;
    top: 74px;
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    max-width: none;
    padding: 14px;
    gap: 12px;
    transform: translateY(-118%);
    border-radius: 20px;
    box-shadow: var(--shadow-pop);
    z-index: 45;
  }
  .sidebar.open {
    transform: translateY(0);
  }
  .sidebar-brand {
    display: none;
  }
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .sidebar-nav .nav-eyebrow {
    display: none;
  }
  .nav-link {
    flex: 1 1 calc(50% - 8px);
    min-width: 126px;
    justify-content: center;
    text-align: center;
    padding: 11px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
  }
  .nav-link.active {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 -3px 0 var(--primary-light);
  }
  .sidebar-footer {
    display: none;
  }
  .sidebar-scrim {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .sidebar-scrim.show {
    opacity: 1;
    pointer-events: auto;
  }
  .main-area {
    margin-left: 0;
  }
  .mobile-topbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-card);
  }
  .content {
    padding: 88px 16px 44px;
  }
}

@media (max-width: 640px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .forecast-row { grid-template-columns: repeat(5, minmax(64px,1fr)); overflow-x: auto; }
  .weather-hero .temp-big { font-size: 2.3rem; }
  .page-header { align-items: flex-start; }
  .header-meta { text-align: left; }
}
