:root {
  --brand-navy: #252458;
  --brand-navy-soft: #3a3a72;
  --accent-teal: #459D8A;
  --accent-mid: #365972;
  --accent-olive: #5C7467;
  --accent-lime: #8DA660;
  --accent-glow: #B8D15A;
  --accent-deep: #2d4f6a;

  --bg-page: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-soft: #fafbfc;
  --bg-input: #ffffff;
  --bg-input-focus: #ffffff;

  --border: #e4e6eb;
  --border-strong: #d4d7de;
  --border-focus: #459D8A;

  --text-primary: #1a1c2e;
  --text-secondary: #4a5066;
  --text-muted: #7a8194;
  --text-dim: #a8adba;
  --text-on-accent: #ffffff;

  --error: #d94562;

  --radius: 10px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 2px rgba(37, 36, 88, 0.04);
  --shadow-md: 0 2px 8px rgba(37, 36, 88, 0.06);
  --shadow-focus: 0 0 0 3px rgba(69, 157, 138, 0.15);

  --gradient-solar: linear-gradient(135deg, #459D8A 0%, #365972 38%, #5C7467 66%, #8DA660 89%, #B8D15A 100%);
  --gradient-button: linear-gradient(135deg, #365972 0%, #459D8A 50%, #8DA660 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 420px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-surface);
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.sidebar-inner {
  padding: 28px 24px 40px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.brand .logo-img {
  height: 24px;
  width: auto;
  display: block;
  color: var(--brand-navy);
}
.brand h1 {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .01em;
  line-height: 1.4;
}
.brand h1 strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand-navy);
  letter-spacing: -.01em;
}

.location-pick {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 24px;
  position: relative;
}

.location-pick .section-label,
.params .section-label,
.results .section-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.coord-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}
.coord-box {
  flex: 1 1 0;
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.coord-box .val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.coord-box .lbl {
  font-size: .6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-top: 3px;
}
.location-empty {
  font-size: .78rem;
  color: var(--text-muted);
  font-style: italic;
}

.params { margin-bottom: 24px; min-width: 0; }

.field { margin-bottom: 14px; min-width: 0; }
.field label {
  display: block;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field input[type="number"],
.field input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .88rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: border .15s, box-shadow .15s;
  -moz-appearance: textfield;
  appearance: textfield;
}
.field input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.field input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}
.field input::placeholder { color: var(--text-dim); }
.field input[type="date"] {
  color-scheme: light;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}
.field-hint {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn {
  width: 100%;
  padding: 12px;
  background: var(--brand-navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .005em;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:hover {
  background: var(--brand-navy-soft);
  box-shadow: 0 4px 14px rgba(37, 36, 88, 0.18);
}
.btn:active { transform: translateY(1px); }
.btn:disabled {
  background: var(--border-strong);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

.loader {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  color: var(--accent-teal);
  font-size: .82rem;
  font-weight: 500;
}
.loader.active { display: flex; }
.loader .spin {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-teal);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  color: var(--error);
  font-size: .8rem;
  margin: 10px 0;
  padding: 9px 12px;
  background: rgba(217, 69, 98, 0.06);
  border: 1px solid rgba(217, 69, 98, 0.18);
  border-radius: var(--radius-sm);
  display: none;
}
.error.show { display: block; }

.results { margin-top: 24px; min-width: 0; }
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  position: relative;
}
.stat::before {
  content: '';
  position: absolute;
  top: 0; left: 12px; right: 12px;
  height: 2px;
  background: var(--gradient-solar);
  border-radius: 0 0 2px 2px;
}
.stat .val {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--brand-navy);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stat .uom {
  font-size: .68rem;
  color: var(--accent-teal);
  font-weight: 500;
  margin-top: 2px;
}
.stat .lbl {
  font-size: .62rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.chart-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.chart-wrap .chart-title {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.chart-wrap canvas { max-height: 180px; }

.detail-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.detail-wrap .chart-title {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.detail-wrap .formula-note {
  font-size: .65rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.detail-legend {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.legend-item {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: .65rem;
  line-height: 1.4;
}
.legend-key {
  flex: 0 0 auto;
  min-width: 78px;
  font-weight: 600;
  color: var(--brand-navy);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.legend-desc {
  color: var(--text-muted);
  flex: 1 1 auto;
}
.legend-desc b {
  color: var(--accent-teal);
  font-weight: 600;
}
.detail-table {
  min-width: 100%;
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
}
.detail-table col.col-jam { width: 56px; }
.detail-table th, .detail-table td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.detail-table th:first-child, .detail-table td:first-child {
  width: 56px;
  min-width: 56px;
  max-width: 56px;
  box-sizing: border-box;
  padding-left: 12px;
  padding-right: 12px;
}
.detail-table th {
  font-weight: 600;
  color: var(--brand-navy);
  text-transform: uppercase;
  font-size: .58rem;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-strong);
  z-index: 2;
}
.detail-table th:first-child {
  text-align: left;
  color: var(--brand-navy);
  font-weight: 600;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
}
.detail-table td {
  position: relative;
  z-index: 0;
}
.detail-table td:first-child {
  text-align: left;
  color: var(--text-primary);
  font-weight: 500;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
}
.detail-table tr.daylight td { color: var(--text-primary); }
.detail-table tr.night td { color: var(--text-dim); }
.detail-table tr.night td:first-child { color: var(--text-muted); }
.detail-scroll {
  max-height: 380px;
  overflow: auto;
}
.detail-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.detail-scroll::-webkit-scrollbar-track { background: transparent; }
.detail-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

#map { width: 100%; height: 100%; }
.leaflet-popup-content-wrapper {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.leaflet-popup-tip { background: var(--bg-surface); }
.leaflet-popup-content { font-family: inherit; font-size: .82rem; }

.leaflet-control-geosearch { max-width: 320px; }
.leaflet-control-geosearch form {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
  overflow: hidden;
}
.leaflet-control-geosearch form input {
  font-family: 'Inter', system-ui, sans-serif !important;
  font-size: .82rem !important;
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 10px 36px 10px 12px !important;
  height: auto !important;
  box-shadow: none !important;
}
.leaflet-control-geosearch form input:focus {
  outline: none;
  box-shadow: none !important;
}
.leaflet-control-geosearch form:focus-within {
  border-color: var(--border-focus) !important;
  box-shadow: var(--shadow-focus) !important;
}
.leaflet-control-geosearch .reset {
  color: var(--text-muted) !important;
}
.leaflet-control-geosearch .results {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  border-top: none !important;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
  margin: 0 !important;
}
.leaflet-control-geosearch .results > * {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border) !important;
  font-size: .8rem !important;
  padding: 8px 12px !important;
}
.leaflet-control-geosearch .results > *:hover,
.leaflet-control-geosearch .results > *.active {
  background: var(--bg-soft) !important;
  color: var(--accent-teal) !important;
  border-left: 3px solid var(--accent-teal) !important;
  padding-left: 9px !important;
}
.leaflet-bar a {
  background: var(--bg-surface) !important;
  color: var(--brand-navy) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover {
  background: var(--bg-soft) !important;
  color: var(--accent-teal) !important;
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
  #map { min-height: 50vh; }
}
