:root {
  --forest: #1F3A2E;
  --forest-dark: #142B21;
  --stone: #EDEEE6;
  --stone-card: #FFFFFF;
  --ink: #1B1F1C;
  --wheat: #C9A227;
  --water: #2C6E8E;
  --soil: #8B5E34;
  --leaf: #4C7A5C;
  --danger: #B3432B;
  --border: #D9DAD0;

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100vw;
  overflow: hidden;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--font-body);
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* ---------- Sidebar (Left Side) ---------- */

.sidebar {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 360px;
  max-height: calc(100vh - 40px);
  z-index: 1000; /* Floating over map */
  
  /* Glassmorphism Effect */
  background: rgba(31, 58, 46, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  
  color: #F1F3EE;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Scrollbar styling for sidebar */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(241, 243, 238, 0.15);
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--wheat);
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.brand .subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: #C4CFC7;
}

.panel-block h2 {
  font-family: var(--font-display);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--wheat);
  margin: 0 0 10px;
}

.panel-block .hint {
  font-size: 13px;
  line-height: 1.5;
  color: #C4CFC7;
  margin: 0 0 10px;
}

.panel-block label {
  display: block;
  font-size: 12.5px;
  color: #C4CFC7;
  margin: 10px 0 4px;
}

.panel-block input[type="date"],
.panel-block input[type="number"],
.panel-block select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px solid rgba(241, 243, 238, 0.25);
  background: rgba(241, 243, 238, 0.06);
  color: #F1F3EE;
  font-family: var(--font-mono);
  font-size: 13px;
}

.panel-block select option { color: #1B1F1C; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-family: var(--font-mono);
  padding: 6px 10px;
  border-radius: 999px;
}

.status-pending {
  background: rgba(201, 162, 39, 0.15);
  color: var(--wheat);
}

.status-ready {
  background: rgba(76, 122, 92, 0.25);
  color: #8FD6A8;
}

.run-button {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: 0.02em;
  padding: 13px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--wheat);
  color: #23200F;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.run-button:hover:not(:disabled) { transform: translateY(-1px); }

.run-button:disabled {
  background: rgba(241, 243, 238, 0.15);
  color: rgba(241, 243, 238, 0.45);
  cursor: not-allowed;
}

.error-box, .warning-box {
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: 8px;
}

.error-box {
  background: rgba(179, 67, 43, 0.18);
  border: 1px solid rgba(179, 67, 43, 0.4);
  color: #F3B7A6;
}

.warning-box {
  background: rgba(201, 162, 39, 0.15);
  border: 1px solid rgba(201, 162, 39, 0.35);
  color: #EAD48A;
}

.loading-box {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #C4CFC7;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(241, 243, 238, 0.25);
  border-top-color: var(--wheat);
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Main Map Container ---------- */

.main {
  flex: 1;
  position: relative;
  height: 100vh;
}

#map {
  height: 100%;
  width: 100%;
}

/* ---------- Popup / Modal Overlay ---------- */

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(20, 43, 33, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.results-modal {
    position: fixed;
    inset: 0;

    display: flex;
    justify-content: center;
    align-items: center;

    background: rgba(20, 25, 35, .55);
    backdrop-filter: blur(4px);

    z-index: 99999;
}
.results-modal[hidden]{
    display:none !important;
}

.results-modal-content{
    width:min(1200px,95vw);
    max-height:92vh;

    display:flex;
    flex-direction:column;

    background:#fff;
    border-radius:18px;
    overflow:hidden;

    box-shadow:0 24px 60px rgba(0,0,0,.28);

    animation:popup .25s ease;
}

.results-modal-header{
    display:flex;
    justify-content:space-between;
    align-items:center;

    padding:18px 24px;

    background:#1f3a2e;
    color:#fff;
}

.results-modal-header h2{
    margin:0;
    font-size:22px;
    font-weight:600;
}

.results-modal-body{
    overflow-y:auto;
    padding:24px;
}
.modal-backdrop[hidden] {
  display: none !important;
}

.modal-container {
  background: var(--stone);
  width: 100%;
  max-width: 1080px;
  max-height: 90vh;
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 20px 28px;
  background: var(--forest-dark);
  color: #F1F3EE;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
  color: var(--wheat);
}

.close-btn {
  background: transparent;
  border: none;
  color: #F1F3EE;
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
  border-radius: 4px;
  transition: background 0.15s;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.modal-body {
  padding: 24px 28px 32px;
  overflow-y: auto;
}

/* ---------- Results Content Inside Modal ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.summary-card {
  background: var(--stone-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.summary-card .label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6B7268;
  margin-bottom: 6px;
}

.summary-card .value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--forest-dark);
}

.summary-card .value .unit {
  font-size: 13px;
  color: #6B7268;
  margin-left: 3px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.irrigation-panel {
  background: var(--stone-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--water);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 22px;
}

.irrigation-panel h2 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 10px;
  color: var(--forest-dark);
}

.irrigation-text {
  font-size: 14px;
  line-height: 1.6;
  color: #3A3F3B;
  margin: 0 0 14px;
}

.irrigation-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.irrigation-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6B7268;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.irrigation-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #F0F0EA;
  font-family: var(--font-mono);
}

.irrigation-table td.stage-critical {
  color: var(--soil);
  font-weight: 600;
  font-family: var(--font-body);
}

.irrigation-table-scroll {
  max-height: 260px;
  overflow-y: auto;
}

.irrigation-table td.scenario-name {
  font-family: var(--font-body);
  font-weight: 500;
}

.delta-positive { color: var(--leaf); font-weight: 600; }
.delta-negative { color: var(--danger); font-weight: 600; }
.delta-zero { color: #6B7268; }
.delta-pct { color: #6B7268; font-size: 12px; }

.chart-card {
  background: var(--stone-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  height: 260px;
}

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; }
  .main { height: calc(100vh - 300px); }
}