:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(26, 34, 52, 0.95);
  --bg-darker: #070a11;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: #38bdf8;
  
  --primary: #0284c7;
  --primary-glow: rgba(2, 132, 199, 0.35);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.35);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.35);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.35);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

body {
  background-color: var(--bg-main);
  background-image: radial-gradient(circle at 10% 20%, rgba(2, 132, 199, 0.08) 0%, transparent 40%),
                    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.06) 0%, transparent 40%);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding: 1.5rem;
  line-height: 1.5;
}

.app-layout {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ÜST BAŞLIK */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo {
  width: 46px;
  height: 46px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 0 20px var(--primary-glow);
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 10px #34d399;
  animation: pulse-animation 2s infinite;
}

.pulse-dot-sm {
  width: 6px;
  height: 6px;
  background-color: #38bdf8;
  border-radius: 50%;
  animation: pulse-animation 1.5s infinite;
}

@keyframes pulse-animation {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.6; }
}

.header-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* KPI / İSTATİSTİK KARTLARI */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.2);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.icon-blue { background: rgba(2, 132, 199, 0.15); color: #38bdf8; }
.icon-purple { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.icon-emerald { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.icon-rose { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.icon-amber { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.kpi-value small {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* ANA PANEL DÜZENİ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* CİHAZ KARTLARI */
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.device-card {
  background: var(--bg-darker);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.device-card:hover {
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.device-card.breach-alert {
  border-color: rgba(239, 68, 68, 0.7);
  box-shadow: 0 0 20px var(--danger-glow);
  animation: border-pulse 1.5s infinite;
}

.device-card.stale-warning {
  border-color: rgba(245, 158, 11, 0.75);
  box-shadow: 0 0 22px rgba(245, 158, 11, 0.3);
  animation: stale-border-pulse 2s infinite;
}

@keyframes stale-border-pulse {
  0%, 100% { border-color: rgba(245, 158, 11, 0.85); box-shadow: 0 0 20px rgba(245, 158, 11, 0.35); }
  50% { border-color: rgba(245, 158, 11, 0.3); box-shadow: 0 0 8px rgba(245, 158, 11, 0.15); }
}

@keyframes border-pulse {
  0%, 100% { border-color: rgba(239, 68, 68, 0.8); }
  50% { border-color: rgba(239, 68, 68, 0.3); }
}

.dev-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dev-id-badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.9rem;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.dev-status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
}

.dev-status-pill.online {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.dev-status-pill.offline {
  background: rgba(100, 116, 139, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

.dev-status-pill.stale {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.5);
  animation: stale-badge-pulse 2s infinite;
}

@keyframes stale-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.stale-alert-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(239, 68, 68, 0.18));
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fbbf24;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0;
  line-height: 1.35;
}

.dashboard-alert-banner {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.22), rgba(245, 158, 11, 0.22));
  border: 1px solid rgba(245, 158, 11, 0.65);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  color: #fef08a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.25);
  animation: stale-border-pulse 2.5s infinite;
  gap: 1rem;
}

.dashboard-alert-banner.hidden {
  display: none !important;
}

.alert-banner-content {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.alert-banner-icon {
  font-size: 1.6rem;
}

.alert-banner-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.alert-banner-desc {
  font-size: 0.82rem;
  color: #fde68a;
}

/* Sıcaklık Göstergesi */
.dev-temp-hero {
  text-align: center;
  padding: 1rem 0;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.temp-number {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-family: 'JetBrains Mono', monospace;
}

.temp-number.normal {
  color: #34d399;
  text-shadow: 0 0 15px var(--success-glow);
}

.temp-number.breach {
  color: #f87171;
  text-shadow: 0 0 20px var(--danger-glow);
}

.temp-status-sub {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

.temp-status-sub.normal { color: #34d399; }
.temp-status-sub.breach { color: #f87171; }

.dev-measured-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.65rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: all 0.2s ease;
}

.dev-measured-badge .measured-icon {
  font-size: 0.85rem;
}

.dev-measured-badge .measured-label {
  color: var(--text-muted);
  font-weight: 500;
}

.dev-measured-badge .measured-time {
  color: #e2e8f0;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
}

.dev-measured-badge .measured-rel {
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 500;
}

.dev-measured-badge.stale {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
}

.dev-measured-badge.stale .measured-time {
  color: #fbbf24;
}

.dev-measured-badge.stale .measured-rel {
  color: #fde68a;
  font-weight: 600;
}

.dev-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
}

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

.meta-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.meta-val {
  color: var(--text-main);
  font-weight: 600;
}

/* ALARMLAR LİSTESİ */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 280px;
  overflow-y: auto;
}

.alert-item {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.alert-header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: #f87171;
}

.alert-meta {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* CANLI MQTT KONSOLU */
.console-body {
  background: #04070d;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  height: 260px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.console-line {
  line-height: 1.4;
  word-break: break-all;
}

.console-line .c-time { color: #64748b; }
.console-line .c-topic { color: #38bdf8; font-weight: 600; }
.console-line .c-alert { color: #f87171; font-weight: 700; }
.console-line .c-payload { color: #e2e8f0; }

/* BUTONLAR */
.btn {
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover {
  background: #0369a1;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-text:hover { color: var(--text-main); }

.badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-count {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .form-group { flex: 1; }

input {
  background: var(--bg-darker);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  color: var(--text-main);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
}

input:focus {
  border-color: var(--border-focus);
}

.input-readonly {
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.03);
}

.modal-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.5rem;
}

.empty-state-sm {
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.hidden { display: none !important; }

/* KULLANICI YÖNETİMİ & TABLOLAR */
.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.anon-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.anon-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}

/* Küçük Toggle Switch */
.switch-sm {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
}

.switch-sm input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-sm {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  transition: .25s;
  border-radius: 18px;
}

.slider-sm:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .25s;
  border-radius: 50%;
}

input:checked + .slider-sm {
  background-color: #10b981;
}

input:checked + .slider-sm:before {
  transform: translateX(16px);
}

/* Tablo Tasarımı */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background 0.15s ease;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: #38bdf8;
}

.user-cell .user-icon {
  font-size: 1rem;
}

.badge-role {
  background: rgba(2, 132, 199, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.3);
  font-size: 0.7rem;
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.7rem;
}

.action-btns {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: #ef4444;
  color: white;
}

