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

:root {
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --green: #16a34a;
  --red: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 12px;
  --header-height: 56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  color: var(--gray-800);
  background: var(--gray-100);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Header */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  max-width: 720px;
  margin: 0 auto;
}
.header-title {
  font-weight: 600;
  font-size: 1.1rem;
}

/* Main content */
.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--header-height) + 16px) 16px 32px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-success { background: var(--green); color: #fff; min-width: 176px; }
.btn-ghost { background: var(--gray-100); color: var(--gray-600); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 0.85rem; border-radius: 8px; }
.btn-full { width: 100%; }
.btn:disabled { background: var(--gray-200); color: var(--gray-400); cursor: not-allowed; pointer-events: none; }
.btn-success:disabled { background: var(--gray-200); color: var(--gray-400); }

/* Messages */
.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  padding: 10px 14px;
  background: #fef2f2;
  border-radius: 8px;
  margin-bottom: 12px;
}
.success-msg {
  color: var(--green);
  font-size: 0.85rem;
  padding: 10px 14px;
  background: #f0fdf4;
  border-radius: 8px;
  margin-bottom: 12px;
}

/* Loading */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  text-align: center;
  padding: 48px 32px;
  color: var(--gray-400);
}
.loading-state p {
  margin-top: 12px;
  font-size: 0.9rem;
}

/* Device grid */
.devices-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 540px) {
  .devices-grid { grid-template-columns: 1fr 1fr; }
}

/* Device card */
.device-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.device-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
  flex: 1;
}
.device-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--blue-light);
  color: var(--blue);
  white-space: nowrap;
  flex-shrink: 0;
}
.device-badge-hot {
  background: #fef2f2;
  color: var(--red);
}
.device-badge-cold {
  background: var(--blue-light);
  color: var(--blue);
}

.device-meta {
  font-size: 0.82rem;
  color: var(--gray-600);
  line-height: 1.6;
}
.device-meta span {
  display: block;
}
.meta-label {
  color: var(--gray-400);
  font-size: 0.75rem;
  font-weight: 500;
}

.device-state {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--green);
  margin-top: 2px;
}
.device-state.state-error {
  color: var(--red);
}

/* Reading panel inside card */
.device-reading {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 10px 12px;
}
.reading-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}
.reading-unit {
  font-size: 0.82rem;
  color: var(--gray-600);
  margin-left: 4px;
}
.reading-extra {
  font-size: 0.78rem;
  color: var(--gray-600);
  margin-top: 4px;
  line-height: 1.6;
}
.reading-extra span {
  display: inline-block;
  margin-right: 10px;
}
.reading-timestamp {
  font-size: 0.72rem;
  color: var(--gray-400);
  margin-top: 4px;
}
.reading-spinner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--gray-400);
}
.reading-error {
  font-size: 0.82rem;
  color: var(--red);
}

.device-card-footer {
  margin-top: 2px;
}
