/* ============================================================
   OpenClaw Grow Dashboard — Dark Theme + Glassmorphism
   ============================================================ */

/* --- Google Fonts ------------------------------------------ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* --- Design Tokens (Custom Properties) --------------------- */
:root {
  /* backgrounds */
  --bg-body:        #0a0a0f;
  --bg-card:        #12131a;
  --bg-card-hover:  #181924;
  --bg-input:       #1a1b26;
  --bg-modal:       rgba(0, 0, 0, 0.7);

  /* borders */
  --border-card:    1px solid rgba(255, 255, 255, 0.05);
  --border-input:   1px solid rgba(255, 255, 255, 0.1);
  --border-radius:  12px;

  /* glassmorphism */
  --glass-blur:     blur(12px);
  --glass-gradient: linear-gradient(
                      135deg,
                      rgba(255, 255, 255, 0.03) 0%,
                      rgba(255, 255, 255, 0.01) 100%
                    );

  /* accent colours */
  --green:   #22c55e;
  --amber:   #f59e0b;
  --red:     #ef4444;
  --cyan:    #06b6d4;

  /* text */
  --text-primary:   rgba(255, 255, 255, 0.9);
  --text-secondary: rgba(255, 255, 255, 0.5);

  /* typography */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* spacing */
  --gap:     1.25rem;
  --padding: 1.5rem;
}


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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  padding: var(--padding);
  max-width: 1400px;
  margin: 0 auto;
}


/* --- Utility ----------------------------------------------- */
.hidden {
  display: none !important;
}

.value {
  font-family: var(--font-mono);
  font-weight: 600;
}


/* --- Keyframe Animations ----------------------------------- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%   { transform: scale(1);   opacity: 1;   }
  50%  { transform: scale(1.5); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1;   }
}

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

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


/* --- Card (base) ------------------------------------------- */
.card {
  background: var(--bg-card);
  background-image: var(--glass-gradient);
  border: var(--border-card);
  border-radius: var(--border-radius);
  padding: var(--padding);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: fadeIn 0.6s ease-out both;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.15);
}

/* staggered entry */
.card:nth-child(1) { animation-delay: 0s;    }
.card:nth-child(2) { animation-delay: 0.1s;  }
.card:nth-child(3) { animation-delay: 0.2s;  }
.card:nth-child(4) { animation-delay: 0.3s;  }

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}


/* --- Header ------------------------------------------------ */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--gap);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#admin-toggle {
  background: transparent;
  border: var(--border-input);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--text-secondary);
}

#admin-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}


/* --- Status Dot -------------------------------------------- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  background: var(--red);
  transition: background 0.3s ease;
}

.status-dot.online {
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
}


/* --- Offline State ----------------------------------------- */
body.offline .value {
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

/* --- Offline Banner ---------------------------------------- */
#offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}


/* --- Toast Notification ------------------------------------ */
.toast {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 1100;
  min-width: 260px;
  max-width: 380px;
  padding: 0.85rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  background: var(--green);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: slideIn 0.35s ease-out;
}

.toast.error {
  background: var(--red);
}

.toast.dismissing {
  animation: slideOut 0.3s ease-in forwards;
}


/* --- Main Grid --------------------------------------------- */
main {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.grid-top {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

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

.right-column {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}


/* --- Grow Overview ----------------------------------------- */
.grow-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.meta-item .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.meta-item span:last-child {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.live-values {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1rem;
}

.value-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.value-item .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.label-hint {
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.65rem;
  opacity: 0.7;
}

.value-item .value {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
}

.value-item .unit {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 0.15em;
}


/* --- Camera Section ---------------------------------------- */
.camera-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

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

.camera-grid figure {
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  position: relative;
  cursor: pointer;
}

.camera-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  border-radius: 8px 8px 0 0;
  background: var(--bg-body);
}

.camera-grid figcaption {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 0.5rem 0.6rem;
}

.camera-grid .cam-timestamp {
  font-family: var(--font-mono);
  font-size: 0.7rem;
}


/* --- Parameters Form --------------------------------------- */
#parameters h2 {
  margin-bottom: 1rem;
}

.param-group {
  margin-bottom: 1rem;
}

.param-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}

.param-group input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: var(--border-input);
  border-radius: 8px;
  outline: none;
  transition: all 0.3s ease;
}

.param-group input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

#save-config {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.7rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: var(--green);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#save-config:hover {
  background: #1db851;
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.35);
}


/* --- Charts Section ---------------------------------------- */
.charts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.charts-header h2 {
  margin-bottom: 0;
}

.range-buttons {
  display: flex;
  gap: 0.4rem;
}

.range-btn {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  border: var(--border-input);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
}

.range-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.range-btn.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.chart-wrapper {
  margin-bottom: 1.5rem;
}

.chart-wrapper:last-child {
  margin-bottom: 0;
}

.chart-wrapper h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
}

.chart-wrapper canvas {
  width: 100% !important;
  max-height: 220px;
}


/* --- Admin Modal ------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-modal);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 90%;
  max-width: 380px;
  padding: 2rem;
  text-align: center;
}

.modal-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

#token-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: var(--border-input);
  border-radius: 8px;
  outline: none;
  margin-bottom: 1rem;
  transition: all 0.3s ease;
}

#token-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.modal-buttons {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.modal-buttons button {
  padding: 0.55rem 1.4rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#token-save {
  background: var(--green);
  color: #fff;
}

#token-save:hover {
  background: #1db851;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.3);
}

#token-logout {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

#token-logout:hover {
  background: rgba(239, 68, 68, 0.25);
}

#modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.3s ease;
}

#modal-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}


/* --- Responsive -------------------------------------------- */
@media (max-width: 767px) {
  body {
    padding: 1rem;
  }

  header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .header-left h1 {
    font-size: 1.1rem;
  }

  .grow-meta {
    grid-template-columns: repeat(2, 1fr);
  }

  .live-values {
    grid-template-columns: repeat(2, 1fr);
  }

  .value-item .value {
    font-size: 1.25rem;
  }

  .charts-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-wrapper canvas {
    max-height: 180px;
  }
}


/* --- Scrollbar --------------------------------------------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}


/* --- Auth Overlay ------------------------------------------ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 17, 23, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-overlay-box {
  text-align: center;
  max-width: 420px;
  padding: 2rem;
}

.auth-overlay-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.auth-overlay-box p {
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.6;
}

/* --- Device Management ------------------------------------- */
#device-management hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
}

.device-alert {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 0.5rem;
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.device-name {
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
}
.device-name:hover { border-bottom-color: var(--accent); }
.rename-input {
  font-size: 0.9rem;
  padding: 2px 6px;
  width: 160px;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  border-radius: 4px;
}

.device-meta {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
}

.device-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

.btn-sm:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

.status-active { color: #22c55e; }
.status-locked { color: #ef4444; }

.link-create {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.link-create input[type="text"] {
  flex: 1 1 100%;
}

.link-create select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

#link-result {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

#link-url {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.4rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.8);
}

.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.8rem;
  gap: 0.5rem;
}

.link-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.link-meta {
  color: rgba(255, 255, 255, 0.5);
}

.link-id {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.3);
}

.muted {
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.85rem;
}

/* --- Selection --------------------------------------------- */
::selection {
  background: rgba(34, 197, 94, 0.3);
  color: #fff;
}

/* --- Timelapse Preview (hover on camera images) ------------ */
.timelapse-preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px 8px 0 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 1;
}

.camera-grid figure:hover .timelapse-preview {
  opacity: 1;
}

.timelapse-play-icon {
  position: absolute;
  top: calc(50% - 1rem);
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 48px;
  height: 48px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.timelapse-play-icon::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent white;
  margin-left: 3px;
}

.camera-grid figure:hover .timelapse-play-icon {
  opacity: 1;
}

/* --- Timelapse Overlay (maximized view) -------------------- */
.timelapse-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.timelapse-overlay.hidden {
  display: none;
}

.timelapse-overlay-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timelapse-overlay-content video {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--border-radius);
  outline: none;
  background: #000;
}

.timelapse-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 2rem;
  cursor: pointer;
  transition: color 0.2s ease;
  line-height: 1;
}

.timelapse-close:hover {
  color: #fff;
}

.timelapse-hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.75rem;
  margin-top: 0.5rem;
}
