/* ── Garden Controller Styles ─────────────────────────────────────────── */

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --danger: #ef4444;
  --warn: #f59e0b;
  --blue: #3b82f6;
  --purple: #a855f7;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────────────────────────── */

.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.app-header h1 span { color: var(--text); }

.header-status {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--accent); }
.status-dot.offline { background: var(--danger); }

/* ── Tabs ──────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  padding: 0 24px;
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); background: var(--bg-hover); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Main Content ──────────────────────────────────────────────────────── */

.main-content {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }
.btn-icon { padding: 6px; background: none; border: none; color: var(--text-dim); cursor: pointer; }
.btn-icon:hover { color: var(--text); }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover { background: var(--accent-hover); }
.btn-warning { background: var(--warn); color: #000; }
.btn-warning:hover { background: #d97706; }

/* ── Grids ─────────────────────────────────────────────────────────────── */

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

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Forms ─────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 500;
}

.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border 0.2s;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
}

.form-select {
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 { font-size: 1.1rem; margin-bottom: 16px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ── Garden Map ────────────────────────────────────────────────────────── */

.garden-map {
  position: relative;
  background: #1a2332;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 400px;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-content: flex-start;
}

.map-container {
  position: relative;
  width: 100px;
  height: 100px;
  background: rgba(34, 197, 94, 0.1);
  border: 2px solid var(--accent);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  padding: 4px;
  user-select: none;
}

.map-container:hover {
  background: rgba(34, 197, 94, 0.2);
  transform: scale(1.05);
}

.map-container .plant-name {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.map-container .moisture {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.map-container .container-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  position: absolute;
  top: 4px;
  left: 6px;
}

.moisture-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.moisture-dot.wet { background: #3b82f6; }
.moisture-dot.good { background: var(--accent); }
.moisture-dot.dry { background: var(--warn); }
.moisture-dot.critical { background: var(--danger); }

/* ── Empty state ───────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.empty-state p { margin-bottom: 12px; }

/* ── Lists / Tables ────────────────────────────────────────────────────── */

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.list-item .item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item .item-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.list-item .item-detail {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.list-item .item-actions {
  display: flex;
  gap: 6px;
}

/* ── Stats / Dashboard ─────────────────────────────────────────────────── */

.stat-card {
  text-align: center;
  padding: 20px 16px;
}

.stat-card .stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Activity log ──────────────────────────────────────────────────────── */

.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.activity-dot.on { background: var(--accent); }
.activity-dot.off { background: var(--text-dim); }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 0.85rem;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.toast.success { background: var(--accent); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--blue); color: #fff; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Watering Controls ─────────────────────────────────────────────────── */

.source-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

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

.source-card .source-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.source-card .source-status {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 4px;
}

.source-status.running {
  background: rgba(34,197,94,0.2);
  color: var(--accent);
}

.source-status.idle {
  background: rgba(148,163,184,0.2);
  color: var(--text-dim);
}

.source-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ── Sensor readings ───────────────────────────────────────────────────── */

.reading-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.reading-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s;
}

.reading-bar-fill.good { background: var(--accent); }
.reading-bar-fill.dry { background: var(--warn); }
.reading-bar-fill.critical { background: var(--danger); }
.reading-bar-fill.wet { background: var(--blue); }

/* ── Scrollbar ─────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
