/* =============================================================
 * IoT Panel — Self-contained CSS
 * Tailwind benzeri utility class'ları, sadece kullandığımız altküme.
 * ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: #f8fafc;
  color: #0f172a;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- Renk paleti ---------- */
:root {
  --c-bg:        #f8fafc;
  --c-card:      #ffffff;
  --c-border:    #e2e8f0;
  --c-text:      #0f172a;
  --c-text-2:    #475569;
  --c-text-3:    #94a3b8;
  --c-text-4:    #cbd5e1;

  --c-brand:     #2563eb;
  --c-brand-h:   #1d4ed8;
  --c-brand-bg:  #dbeafe;

  --c-on:        #10b981;
  --c-on-bg:     #d1fae5;
  --c-warn:      #d97706;
  --c-warn-bg:   #fef3c7;
  --c-err:       #dc2626;
  --c-err-bg:    #fee2e2;

  --c-temp:      #ea580c;     /* turuncu */
  --c-temp-bg:   #ffedd5;
  --c-hum:       #0284c7;     /* mavi */
  --c-hum-bg:    #e0f2fe;
  --c-press:     #7c3aed;     /* mor */
  --c-press-bg:  #ede9fe;
  --c-other:     #475569;
  --c-other-bg:  #f1f5f9;
}

/* ---------- Layout ---------- */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ---------- Page transition ---------- */
.page { transition: opacity 200ms ease; }
.page.hidden { opacity: 0; pointer-events: none; position: absolute; left: -9999px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--c-border);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* ---------- Status dot ---------- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--c-text-4);
  flex-shrink: 0;
}
.status-dot.connected  { background: var(--c-on); }
.status-dot.connecting { background: var(--c-text-4); animation: pulse-soft 2s ease-in-out infinite; }

@keyframes pulse-soft {
  50% { opacity: 0.5; }
}

/* ---------- Login card ---------- */
.login-wrap { width: 100%; max-width: 380px; }
.login-header { text-align: center; margin-bottom: 32px; }
.login-emoji { font-size: 60px; margin-bottom: 12px; }
.login-title { font-size: 22px; font-weight: 600; color: var(--c-text); margin: 0; }
.login-subtitle { font-size: 14px; color: var(--c-text-3); margin-top: 4px; }
.login-card {
  background: var(--c-card);
  border-radius: 16px;
  border: 1px solid var(--c-border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 8px;
}
.login-badge .label { font-size: 12px; color: var(--c-text-3); }
.login-badge .value { font-size: 14px; font-weight: 500; color: var(--c-text-2); }
.login-error {
  padding: 12px;
  background: var(--c-err-bg);
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 14px;
  color: var(--c-err);
}
.login-fields { display: flex; flex-direction: column; gap: 12px; }
.login-fields label.field-label { display: block; font-size: 14px; font-weight: 500; color: var(--c-text-2); margin-bottom: 4px; }
.login-fields input[type="text"],
.login-fields input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 16px;
  color: var(--c-text);
  outline: none;
  transition: border-color 150ms;
}
.login-fields input:focus {
  border-color: var(--c-brand);
  background: var(--c-card);
}
.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--c-text-2);
  padding-top: 4px;
  cursor: pointer;
  user-select: none;
}
.remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--c-brand);
  cursor: pointer;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--c-brand);
  color: white;
  font-weight: 500;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: background-color 150ms;
}
.btn-primary:hover, .btn-primary:active { background: var(--c-brand-h); }
.btn-primary:disabled { background: var(--c-text-4); cursor: not-allowed; }
.login-footer {
  text-align: center;
  font-size: 12px;
  color: var(--c-text-4);
  margin-top: 24px;
}

/* ---------- Topbar text ---------- */
.dev-id {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-text {
  font-size: 12px;
  color: var(--c-text-3);
}
.status-text.connected { color: var(--c-on); }
.btn-link {
  font-size: 14px;
  color: var(--c-text-2);
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  transition: background-color 150ms;
}
.btn-link:hover { background: var(--c-bg); color: var(--c-text); }

/* ---------- Loading ---------- */
.loading {
  text-align: center;
  padding: 48px 0;
  color: var(--c-text-4);
}
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-brand);
  border-radius: 999px;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Element cards ---------- */
.cards { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--c-card);
  border-radius: 16px;
  border: 1px solid var(--c-border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
  transition: opacity 150ms;
}
.card.pending { opacity: 0.6; pointer-events: none; }

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--c-other-bg);
  color: var(--c-other);
  transition: background-color 200ms, color 200ms;
}
.card-icon svg { width: 24px; height: 24px; }
.card-icon.relay-on  { background: var(--c-on-bg); color: var(--c-on); }
.card-icon.relay-off { background: var(--c-other-bg); color: var(--c-text-4); }
.card-icon.temp      { background: var(--c-temp-bg);  color: var(--c-temp); }
.card-icon.humidity  { background: var(--c-hum-bg);   color: var(--c-hum); }
.card-icon.pressure  { background: var(--c-press-bg); color: var(--c-press); }

.card-text { flex: 1; min-width: 0; }
.card-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub {
  font-size: 12px;
  color: var(--c-text-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub.warn { color: var(--c-warn); }

/* Sensör değer */
.card-value {
  text-align: right;
  flex-shrink: 0;
}
.card-value .v {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.card-value .u {
  font-size: 12px;
  color: var(--c-text-3);
}
.card-value.temp .v     { color: var(--c-temp); }
.card-value.humidity .v { color: var(--c-hum); }
.card-value.pressure .v { color: var(--c-press); }

/* Switch */
.switch {
  flex-shrink: 0;
  margin-left: 8px;
}
.switch-track {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--c-text-4);
  position: relative;
  transition: background-color 200ms;
}
.switch-track.on { background: var(--c-on); }
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.switch-track.on .switch-knob { transform: translateX(20px); }

/* Fallback (bilinmeyen tip) */
.card-fallback {
  background: var(--c-warn-bg);
  border-color: #fde68a;
  display: block;
  padding: 16px;
}
.card-fallback .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.card-fallback .head svg {
  width: 20px;
  height: 20px;
  color: var(--c-warn);
}
.card-fallback .head .title {
  font-size: 14px;
  font-weight: 500;
  color: #78350f;
}
.card-fallback pre {
  font-size: 12px;
  color: #92400e;
  margin: 0;
  white-space: pre-wrap;
  overflow-x: auto;
}