:root {
  --bg:        #f7f7f5;
  --card:      #ffffff;
  --text:      #1a1a1a;
  --muted:     #6b7280;
  --accent:    #f97316;
  --accent-2:  #fb923c;
  --border:    #e5e7eb;
  --danger:    #dc2626;
  --success:   #10b981;
  --shadow:    0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px;
  background: white;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
}

.device-select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.9rem;
}

.insights-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: 24px;
}

.insight {
  background: linear-gradient(135deg, #fff7ed 0%, #ffffff 100%);
  border: 1px solid #fed7aa;
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.insight-icon { font-size: 1.6rem; flex-shrink: 0; }
.insight h4   { margin: 0 0 4px; font-size: 0.95rem; font-weight: 600; }
.insight p    { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.4; }

.snapshots {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.snapshots img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.snapshot-item small {
  display: block;
  text-align: center;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-header button { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); }

#settings-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

#settings-form label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 400;
}

#settings-form input[type="text"],
#settings-form input[type="email"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}

#settings-form small {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 10px 18px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}

.behavior-card { background: linear-gradient(135deg, #fff7ed 0%, #ffffff 100%); }
.behavior-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.big-score {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.burst-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.burst-item:last-child { border-bottom: none; }
.events li small.ai-desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.user-info button {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.user-info button:hover {
  background: var(--bg);
}

main {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 24px;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  text-align: left;
}

.stat .big {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin: 4px 0;
}

.stat small {
  color: var(--muted);
  font-size: 0.85rem;
}

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

canvas {
  width: 100% !important;
  height: 100% !important;
}

.events {
  list-style: none;
  padding: 0;
  margin: 0;
}

.events li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.events li:last-child {
  border-bottom: none;
}

.events .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.animal  { background: #fed7aa; color: #c2410c; }
.badge.human   { background: #e0e7ff; color: #3730a3; }
.badge.vehicle { background: #d1fae5; color: #065f46; }
.badge.other   { background: #f3f4f6; color: #4b5563; }

.events time {
  color: var(--muted);
  font-size: 0.85rem;
}

.muted { color: var(--muted); font-size: 0.9rem; margin-top: -8px; }

.hidden { display: none; }

#error-banner {
  background: #fee2e2;
  color: var(--danger);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

footer {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: 0.85rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

@media (max-width: 600px) {
  header { padding: 16px 20px; flex-direction: column; gap: 12px; align-items: flex-start; }
  main { padding: 0 16px; margin: 20px auto; }
  .stat .big { font-size: 1.8rem; }
}

/* Live state card */
.live-state-card {
  text-align: center;
  padding: 28px 16px;
  background: linear-gradient(135deg, #fff8f0 0%, #ffeeda 100%);
  border: 1px solid #f4d4a8;
}
.live-state-card .big {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}
#live-state[data-state="active"]   { color: #d97706; }
#live-state[data-state="awake"]    { color: #ea580c; }
#live-state[data-state="quiet"]    { color: #6b7280; }
#live-state[data-state="sleeping"] { color: #4b5563; }
#live-state[data-state="unknown"]  { color: #9ca3af; }
