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

:root {
  --green-dark:  #2a8a5c;
  --green-mid:   #3eb476;
  --green-light: #7dd8a4;
  --green-pale:  #e8f7f0;
  --green-glow:  #b8ecd2;
  --text-dark:   #111827;
  --text-mid:    #374151;
  --text-soft:   #6b7280;
  --white:       #ffffff;
  --danger:      #c0392b;
  --danger-pale: #fbeae8;
  --radius:      16px;
  --radius-sm:   10px;
  --shadow:      0 4px 24px rgba(62,180,118,.15);
  --shadow-lg:   0 12px 48px rgba(62,180,118,.22);
  --border:      rgba(62,180,118,.18);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  color: var(--text-dark);
  background: var(--green-pale);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 28px;
  border-radius: 50px;
  font-size: .95rem;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s, background .2s, color .2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--green-mid), var(--green-dark));
  color: var(--white);
  border: none;
  box-shadow: 0 6px 24px rgba(62,180,118,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 32px rgba(62,180,118,.45); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: transparent;
  color: var(--green-dark);
  border: 2px solid var(--green-mid);
}
.btn-secondary:hover { background: var(--green-pale); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: .8rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-pale); }

/* ─── Forms ───────────────────────────────────────────── */
form label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-mid);
  margin: 16px 0 6px;
}
form label:first-of-type { margin-top: 0; }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="time"] {
  width: 100%;
  padding: 13px 16px;
  font-size: 1rem;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-dark);
}
input:focus { outline: none; border-color: var(--green-mid); box-shadow: 0 0 0 3px var(--green-glow); }
.form-error {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--danger-pale);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
}
.form-success {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--green-pale);
  color: var(--green-dark);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
}

/* ─── Auth (login) page ───────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f0faf5 0%, #ffffff 55%, #e6f5ee 100%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  text-align: center;
}
.auth-logo { height: 48px; margin-bottom: 20px; }
.auth-card h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
.auth-sub { color: var(--text-soft); font-size: .9rem; margin-bottom: 24px; }
.auth-card form { text-align: left; }
.auth-card .btn-primary { margin-top: 24px; }

/* ─── App shell / nav ─────────────────────────────────── */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-nav-logo img { height: 36px; display: block; }
.app-nav-links { display: flex; align-items: center; gap: 18px; }
.app-nav-links a {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-mid);
  text-decoration: none;
  padding: 6px 4px;
}
.app-nav-links a.active { color: var(--green-dark); border-bottom: 2px solid var(--green-mid); }

.page { max-width: 960px; margin: 0 auto; padding: 28px 20px 60px; }
.page h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 20px; }

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

.back-link {
  display: inline-block;
  font-size: .9rem;
  font-weight: 600;
  color: var(--green-dark);
  text-decoration: none;
  margin-bottom: 16px;
}

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

/* ─── Device list ─────────────────────────────────────── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.device-card {
  display: block;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform .2s, box-shadow .2s;
}
.device-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.device-card-thumb {
  aspect-ratio: 4/3;
  background: var(--green-pale);
  display: flex;
  align-items: center;
  justify-content: center;
}
.device-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.device-card-body { padding: 16px 18px; }
.device-card-body h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 2px; }
.device-card-id { font-size: .78rem; color: var(--text-soft); margin-bottom: 12px; }
.device-card-meta { display: flex; gap: 8px; }

.empty-thumb {
  color: var(--text-soft);
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.led-badge, .water-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: .75rem;
  font-weight: 700;
  background: var(--green-pale);
  color: var(--text-mid);
}
.led-badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-soft);
}
.led-badge.on { color: var(--green-dark); }
.led-badge.on::before { background: var(--green-mid); box-shadow: 0 0 6px var(--green-mid); }

/* ─── Device detail page ──────────────────────────────── */
.device-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  align-items: start;
}
.picture-card { text-align: center; }
.picture-wrap {
  aspect-ratio: 4/3;
  border-radius: var(--radius-sm);
  background: var(--green-pale);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  overflow: hidden;
}
.picture-wrap img { width: 100%; height: 100%; object-fit: cover; }
.upload-label { display: inline-flex; }

.status-card { display: flex; flex-direction: column; gap: 18px; }
.status-row { display: flex; align-items: center; justify-content: space-between; }
.status-row .label { font-size: .78rem; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.status-row .value { font-size: 1.15rem; font-weight: 700; }

.switch {
  width: 52px;
  height: 30px;
  border-radius: 50px;
  border: none;
  background: #d1d5db;
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background .2s;
}
.switch.on { background: var(--green-mid); }
.switch-knob {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .2s;
}
.switch.on .switch-knob { transform: translateX(22px); }

.water-gauge {
  height: 18px;
  border-radius: 50px;
  background: var(--green-pale);
  border: 1px solid var(--border);
  overflow: hidden;
}
.water-gauge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green-light), var(--green-mid));
  transition: width .4s ease;
}

.details-card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }

@media (max-width: 640px) {
  .app-nav { padding: 12px 16px; }
  .page { padding: 20px 14px 48px; }
  .card { padding: 18px; }
}
