/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #2563eb;
  --primary-dk: #1d4ed8;
  --accent:     #0ea5e9;
  --danger:     #ef4444;
  --success:    #22c55e;
  --warning:    #f59e0b;
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface2:   #273549;
  --border:     #334155;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --sidebar-w:  240px;
  --radius:     12px;
}

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

/* ── HOME ─────────────────────────────────────────────────────────────────── */
.home-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.home-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  z-index: 0;
}

.home-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(37, 99, 235, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(14, 165, 233, 0.1) 0%, transparent 40%);
}

.home-hero {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 8%;
  z-index: 1;
}

.home-hero-text h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

.home-hero-text h1 span {
  color: var(--accent);
}

.home-hero-text p {
  margin-top: 1rem;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.home-temp-widget {
  position: absolute;
  top: 1.5rem;
  right: 1.75rem;
  z-index: 3;
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
}

.home-temp-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding-right: 0.5rem;
  border-right: 1px solid rgba(255,255,255,0.12);
  margin-right: 0.1rem;
  white-space: nowrap;
}

.home-temp-icon {
  font-size: 0.85rem;
}

.home-temp-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.5px;
}

.home-temp-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.4rem;
}

.home-temp-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  border-left: 1px solid rgba(255,255,255,0.12);
  padding-left: 0.5rem;
}

.home-card {
  position: relative;
  z-index: 2;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  margin-right: 8%;
  margin-left: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

.home-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.home-card .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dk); transform: translateY(-1px); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar-brand .brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}

.nav-section {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.15s;
  border-radius: 0;
  margin: 0.1rem 0.5rem;
  border-radius: 8px;
}

.nav-link:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-link.active {
  background: rgba(37, 99, 235, 0.15);
  color: var(--primary);
  font-weight: 600;
}

.nav-link .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Refresh button ──────────────────────────────────────────────────────── */
.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  align-self: center;
  white-space: nowrap;
}

.btn-refresh:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-refresh.spinning {
  animation: spin 0.6s linear infinite;
}

/* ── Logs ─────────────────────────────────────────────────────────────────── */
.log-devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.log-device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.log-device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.log-device-id {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.log-device-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.log-payload {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.log-payload-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.log-payload-key {
  color: var(--text-muted);
  flex-shrink: 0;
}

.log-payload-val {
  color: var(--text);
  font-weight: 500;
  text-align: right;
  word-break: break-all;
}

.log-device-footer {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-copy-log {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-copy-log:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-delete-device {
  background: none;
  border: 1px solid rgba(239,68,68,0.3);
  color: rgba(239,68,68,0.7);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-delete-device:hover {
  background: rgba(239,68,68,0.1);
  color: #ef4444;
  border-color: #ef4444;
}

.btn-delete-log {
  background: none;
  border: 1px solid rgba(239,68,68,0.3);
  color: rgba(239,68,68,0.7);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  margin-left: 0.25rem;
}

.btn-delete-log:hover {
  background: rgba(239,68,68,0.1);
  color: #ef4444;
  border-color: #ef4444;
}

.log-reset-badge {
  font-size: 0.68rem;
  font-weight: 600;
  font-family: monospace;
  background: rgba(251,191,36,0.12);
  color: #fbbf24;
  border: 1px solid rgba(251,191,36,0.3);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  white-space: nowrap;
}

.log-payload-empty {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.log-table-wrap {
  overflow-x: auto;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.log-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}

.log-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: top;
}

.log-table-time {
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.75rem;
}

.log-device-badge {
  background: rgba(37,99,235,0.12);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.log-table-payload {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.log-kv {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
  justify-content: center;
  transition: all 0.2s;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.08);
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2rem;
  min-height: 100vh;
}

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.page-header p {
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── Stats cards ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-unit {
  font-size: 1rem;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

.stat-card .stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.color-blue  { color: var(--primary); }
.color-cyan  { color: var(--accent); }
.color-green { color: var(--success); }
.color-amber { color: var(--warning); }

/* ── Horas de frío panel ──────────────────────────────────────────────────── */
.cold-hours-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: start;
}

.cold-hours-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

.cold-card {
  background: var(--surface);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(135deg, var(--surface) 60%, rgba(37,99,235,0.08));
}

.cold-card-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.cold-card-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.cold-card-value {
  font-size: 2.4rem;
  font-weight: 700;
  color: #93c5fd;
  line-height: 1;
}

.cold-card-unit {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

/* Card de última lectura */
.last-reading-card {
  background: linear-gradient(135deg, var(--surface) 60%, rgba(14,165,233,0.08));
}

.last-reading-sensors {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.last-reading-temp {
  font-size: 1.9rem;
  font-weight: 700;
  color: #7dd3fc;
  line-height: 1;
}

.last-reading-sep {
  font-size: 1.4rem;
  color: var(--text-muted);
  font-weight: 300;
}

.last-reading-date {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.stale-icon {
  font-size: 1.1rem;
  display: block;
  margin-top: 0.3rem;
  animation: pulse-warn 1.5s ease-in-out infinite;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Selector de fecha */
.cold-date-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  min-width: 230px;
}

.cold-date-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.cold-date-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.cold-date-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  min-width: 0;
  color-scheme: dark;
}

.cold-date-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

.btn-save-date {
  padding: 0.5rem 0.9rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-save-date:hover { background: var(--primary-dk); }

.cold-date-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.cold-date-hint strong { color: #93c5fd; }

@media (max-width: 900px) {
  .cold-hours-panel {
    grid-template-columns: 1fr;
  }
  .cold-hours-cards {
    grid-template-columns: 1fr;
  }
}

/* ── Chart card ───────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.chart-card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.chart-card-header button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
  line-height: 1;
}

.chart-card-header button:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.chart-card-header button.spinning {
  animation: spin 0.6s linear infinite;
}

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

.chart-card-header .badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  background: rgba(37, 99, 235, 0.15);
  color: var(--accent);
  border-radius: 100px;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  height: 360px;
}

/* ── Dashboard welcome ────────────────────────────────────────────────────── */
.welcome-card {
  background: linear-gradient(135deg, var(--primary) 0%, #0ea5e9 100%);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.welcome-card::after {
  content: '';
  position: absolute;
  right: -2rem;
  top: -2rem;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}

.welcome-card h2 {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.welcome-card p {
  opacity: 0.85;
  font-size: 0.95rem;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.menu-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  display: block;
}

.menu-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.menu-card-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.menu-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.menu-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── No data ──────────────────────────────────────────────────────────────── */
.no-data {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.no-data .no-data-icon { font-size: 3rem; margin-bottom: 1rem; }
.no-data h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--text); }
.no-data code {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--accent);
}

/* ── Calendario de Siembra ────────────────────────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.5rem;
}

.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.cal-nav-btn:hover { background: var(--surface2); border-color: var(--text-muted); }

.cal-range {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.cal-btn-today {
  padding: 0.4rem 0.85rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.cal-btn-today:hover { color: var(--text); border-color: var(--text-muted); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.cal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cal-card:hover { border-color: #334155; box-shadow: 0 4px 16px rgba(0,0,0,0.25); }

.cal-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.cal-card-emoji { font-size: 2rem; line-height: 1; }

.cal-card-actions { display: flex; gap: 0.25rem; opacity: 0; transition: opacity 0.15s; }
.cal-card:hover .cal-card-actions { opacity: 1; }

.cal-btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.cal-btn-icon:hover { background: var(--surface2); color: var(--text); }
.cal-btn-icon.danger:hover { background: rgba(239,68,68,0.1); color: #ef4444; border-color: rgba(239,68,68,0.4); }

.cal-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-top: 0.1rem;
}

.cal-card-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.cal-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}

.cal-badge-tipo  { background: rgba(37,99,235,0.12); color: var(--accent); border: 1px solid rgba(37,99,235,0.2); }
.cal-badge-stock { background: rgba(34,197,94,0.12); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.cal-badge-nostock { background: rgba(255,255,255,0.04); color: var(--text-muted); border: 1px solid var(--border); }

.cal-card-range {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.cal-card-cosecha {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cal-card-notas {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
  margin-top: 0.1rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Gestión - lista de todas las plantas */
.cal-todas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.cal-todas summary {
  cursor: pointer;
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: color 0.15s;
}

.cal-todas summary:hover { color: var(--text); }
.cal-todas[open] summary { border-bottom: 1px solid var(--border); color: var(--text); }

.cal-todas-body { padding: 0.75rem 1.25rem; }

.cal-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.87rem;
}

.cal-row:last-child { border-bottom: none; }
.cal-row-name { flex: 1; font-weight: 600; min-width: 0; }
.cal-row-range { color: var(--text-muted); white-space: nowrap; font-size: 0.8rem; }
.cal-row-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* Modal */
.cal-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.cal-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.cal-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.cal-modal-header h3 { font-size: 1.15rem; font-weight: 700; }

.cal-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.cal-form-row.triple { grid-template-columns: 1fr 1fr 1fr; }

.cal-form-group { margin-bottom: 1rem; }
.cal-form-group:last-child { margin-bottom: 0; }

.cal-form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

.cal-input, .cal-select, .cal-textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  color-scheme: dark;
}

.cal-select option { background: var(--surface); }
.cal-textarea { resize: vertical; min-height: 72px; font-family: inherit; }

.cal-input:focus, .cal-select:focus, .cal-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

.cal-check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.cal-check-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

.cal-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.cal-btn-cancel {
  padding: 0.55rem 1.1rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.cal-btn-cancel:hover { color: var(--text); border-color: var(--text-muted); }

.cal-btn-save {
  padding: 0.55rem 1.25rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.cal-btn-save:hover { background: var(--primary-dk); }
.cal-btn-save:disabled { opacity: 0.5; cursor: not-allowed; }

.cal-btn-add {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.cal-btn-add:hover { background: var(--primary-dk); }

/* ── Calendar: window rows ───────────────────────────────────────────────── */
.cal-window-row { margin-bottom: 0.6rem; }

.cal-window-pair {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.cal-window-field { flex: 1; min-width: 140px; }

.cal-window-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.cal-win-remove { flex-shrink: 0; margin-bottom: 2px; }

.cal-btn-add-window {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.cal-btn-add-window:hover { border-color: var(--primary); color: var(--primary); }

/* ── Calendar: season badges ─────────────────────────────────────────────── */
.cal-card-seasons { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }

.cal-badge-season          { font-size: 0.72rem; }
.cal-badge-season-spring   { background: rgba(180,230,160,0.25); color: #4a8c35; }
.cal-badge-season-summer   { background: rgba(255,210,100,0.25); color: #9a6e00; }
.cal-badge-season-autumn   { background: rgba(230,150, 60,0.25); color: #8a4a00; }
.cal-badge-season-winter   { background: rgba(140,190,240,0.25); color: #2055a0; }

/* ── Humidity device cards ────────────────────────────────────────────────── */
.humidity-device-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.humidity-device-card:hover {
  border-color: var(--primary, #0ea5e9);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(14,165,233,0.15);
}

.humidity-device-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.humidity-device-value {
  font-size: 2rem;
  font-weight: 700;
  color: #0ea5e9;
  line-height: 1;
}

.humidity-device-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

.humidity-device-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.humidity-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 0.75rem;
  transition: color 0.2s;
}

.humidity-back-link:hover {
  color: var(--primary, #0ea5e9);
}

.humidity-device-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── Edición inline de device ─────────────────────────────────────────────── */
.device-name-editable {
  border-bottom: 1px dashed transparent;
  padding: 0 0.15rem;
  border-radius: 4px;
  outline: none;
  cursor: text;
  transition: background 0.2s, border-color 0.2s;
}

.device-name-editable:hover {
  border-bottom-color: var(--text-muted);
}

.device-name-editable:focus {
  background: rgba(14,165,233,0.08);
  border-bottom-color: #0ea5e9;
}

.device-name-status {
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.device-name-status.loading { color: var(--text-muted); }
.device-name-status.ok      { color: #10b981; }
.device-name-status.error   { color: #ef4444; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .home-hero { display: none; }
  .home-card { margin: 1rem; max-width: 100%; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .main-content { margin-left: 0; padding: 1rem; }
  .app-layout { flex-direction: column; }
  .chart-wrap { height: 250px; }
}
