@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-light: #dcfce7;
  --primary-text: #14532d;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #2563eb;
  --info-light: #dbeafe;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --nav-h: 64px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100dvh;
  padding-bottom: var(--nav-h);
}

/* ── Header ────────────────────────────────────────────── */
.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header h1 svg { width: 22px; height: 22px; }

.weather-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-600);
  background: var(--gray-100);
  border-radius: 20px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.weather-pill:hover { background: var(--gray-200); }
.weather-pill svg { width: 14px; height: 14px; }

/* ── Bottom Navigation ─────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: white;
  border-top: 1px solid var(--gray-200);
  display: flex;
  z-index: 20;
  safe-area-inset-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.15s;
  padding: 8px 4px;
  font-family: inherit;
}

.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--primary); }
.nav-btn:hover:not(.active) { color: var(--gray-600); }

/* ── Main Content ──────────────────────────────────────── */
#tab-content {
  padding: 16px;
  max-width: 680px;
  margin: 0 auto;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-title svg { width: 16px; height: 16px; }

.card-subtitle {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ── Zone Cards ────────────────────────────────────────── */
.zone-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .zone-grid { grid-template-columns: 1fr 1fr; }
}

.zone-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.zone-card.running {
  border-color: var(--primary);
  background: #f0fdf4;
}

.zone-card.inactive { opacity: 0.6; }

.zone-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.on { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.status-dot.off { background: var(--gray-300); }
.status-dot.unknown { background: var(--gray-300); border: 1px dashed var(--gray-400); }

.zone-meta {
  font-size: 12px;
  color: var(--gray-500);
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 12px;
}

.zone-meta span { display: flex; align-items: center; gap: 4px; }
.zone-meta svg { width: 12px; height: 12px; flex-shrink: 0; }

.timer-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-light);
  color: var(--primary-text);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.zone-actions {
  display: flex;
  gap: 8px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.97); }

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}
.btn-danger:hover { background: #fecaca; }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-sm svg { width: 13px; height: 13px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Weather Card ──────────────────────────────────────── */
.weather-card {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

.weather-card-title {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.8;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.weather-card-title svg { width: 14px; height: 14px; }

.weather-stats {
  display: flex;
  gap: 20px;
}

.weather-stat { flex: 1; }

.weather-stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.weather-stat-label {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 4px;
}

.weather-thresholds {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.25);
  display: flex;
  gap: 16px;
}

.threshold-item {
  font-size: 11px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 4px;
}

.threshold-item svg { width: 12px; height: 12px; }

.threshold-ok { color: #bbf7d0; }
.threshold-warn { color: #fde68a; }

/* ── Section Title ─────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 10px;
}

.section-title:first-child { margin-top: 4px; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-800);
  background: white;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus { border-color: var(--primary); }

.form-input-row {
  display: flex;
  gap: 8px;
}

.form-hint {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ── Range Slider ──────────────────────────────────────── */
.slider-group { margin-bottom: 16px; }

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.slider-label { font-size: 13px; font-weight: 500; color: var(--gray-700); }
.slider-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  min-width: 50px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--gray-200);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
  transition: box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.2);
}

/* ── Weekday Picker ────────────────────────────────────── */
.weekday-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.day-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--gray-200);
  background: white;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.day-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.day-btn:hover:not(.selected) {
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Toggle ────────────────────────────────────────────── */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.toggle-group:last-child { border-bottom: none; }

.toggle-label { font-size: 14px; font-weight: 500; color: var(--gray-700); }
.toggle-hint { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Device List ───────────────────────────────────────── */
.device-item {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.device-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.device-online-dot.online { background: var(--primary); }
.device-online-dot.offline { background: var(--gray-300); }

.device-name { font-size: 14px; font-weight: 600; color: var(--gray-800); }
.device-type { font-size: 11px; color: var(--gray-500); font-family: monospace; }

.device-channels { border-top: 1px solid var(--gray-100); }

.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  gap: 12px;
}

.channel-row:last-child { border-bottom: none; }

.channel-info { flex: 1; min-width: 0; }
.channel-label { font-size: 13px; font-weight: 500; color: var(--gray-700); }
.channel-assigned { font-size: 12px; color: var(--primary); margin-top: 2px; font-weight: 500; }
.channel-unassigned { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* ── Log ───────────────────────────────────────────────── */
.log-entry {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-100);
}

.log-entry:last-child { border-bottom: none; }

.log-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}

.log-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.log-icon svg { width: 14px; height: 14px; }
.log-icon.started { background: var(--primary-light); color: var(--primary); }
.log-icon.skipped { background: var(--warning-light); color: var(--warning); }
.log-icon.error { background: var(--danger-light); color: var(--danger); }
.log-icon.info { background: var(--info-light); color: var(--info); }
.log-icon.stopped { background: var(--gray-100); color: var(--gray-500); }
.log-icon.manual { background: var(--info-light); color: var(--info); }

.log-zone { font-size: 14px; font-weight: 600; color: var(--gray-800); }
.log-action { font-size: 12px; color: var(--gray-500); }
.log-time { font-size: 11px; color: var(--gray-400); margin-left: auto; white-space: nowrap; }
.log-reason { font-size: 12px; color: var(--gray-600); margin-top: 4px; padding-left: 38px; }
.log-weather { font-size: 11px; color: var(--gray-400); margin-top: 2px; padding-left: 38px; }

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  opacity: 0.4;
}

.empty-state p { font-size: 14px; color: var(--gray-500); margin-top: 8px; }

/* ── Toast ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--gray-900);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease-out;
  max-width: 300px;
  text-align: center;
  pointer-events: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.success { background: var(--primary-dark); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.15s ease;
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  animation: slide-up 0.2s ease;
}

@media (min-width: 480px) {
  .modal {
    border-radius: var(--radius-lg);
    margin: 16px;
  }
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}

/* ── Info Banner ───────────────────────────────────────── */
.info-banner {
  background: var(--info-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: #1e40af;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.info-banner svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

.warn-banner {
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: #92400e;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.warn-banner svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── Geocode results ───────────────────────────────────── */
.geocode-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 30;
  max-height: 200px;
  overflow-y: auto;
}

.geocode-result-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.1s;
}

.geocode-result-item:hover { background: var(--gray-50); }
.geocode-result-item:last-child { border-bottom: none; }

.location-search-wrap { position: relative; }

/* ── Loading skeleton ──────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  height: 16px;
}

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

/* ── Divider ───────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--gray-100);
  margin: 12px 0;
}

/* ── Next run info ─────────────────────────────────────── */
.next-run-card {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--primary-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.next-run-card svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
