/* güncellendi - Tüm bileşen stilleri tek yerde toplandı ve tema token'larına bağlandı.
   Renk token'ları: assets/css/themes/theme-light.css ve theme-dark.css
   (ikisi de yüklenir, <html data-theme="light|dark"> ile seçilir). */

/* =========================================================
   0) Yedek token'lar
   Tema dosyası yüklenemezse arayüz okunaksız kalmasın diye açık tema
   değerleri burada varsayılan olarak durur; tema dosyaları bunları ezer.
   ========================================================= */
:root {
  --bg: #eef1f6; --bg-accent: #e3e8f0; --panel: #ffffff; --card-bg: #ffffff;
  --input-bg: #ffffff; --item-bg: #ffffff; --surface-2: #f3f5f9; --surface-3: #e7ecf3;
  --hover: rgba(15, 23, 42, 0.05);
  --text: #1e293b; --text-primary: #0f172a; --muted: #64748b;
  --link: #1d4ed8; --link-hover: #1e40af;
  --primary: #2563eb; --primary-2: #1d4ed8; --primary-soft: rgba(37, 99, 235, 0.08);
  --primary-ring: rgba(37, 99, 235, 0.35); --on-primary: #ffffff; --primary-text: #1d4ed8;
  --accent: #7c3aed; --accent-2: #6d28d9; --accent-border: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.10); --accent-glow: rgba(124, 58, 237, 0.26);
  --accent-glow-strong: rgba(124, 58, 237, 0.38);
  --border: #dfe4ec; --border-color: #dfe4ec; --border-strong: #c7d0de;
  --ring: rgba(37, 99, 235, 0.45);
  --green: #16a34a; --green-soft: rgba(22, 163, 74, 0.10); --green-text: #15803d; --green-solid: #15803d;
  --red: #dc2626; --red-soft: rgba(220, 38, 38, 0.10); --red-text: #b91c1c; --red-solid: #dc2626;
  --yellow: #d97706; --yellow-soft: rgba(217, 119, 6, 0.12);
  --pre-bg: #f1f5f9; --pre-text: #1e293b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 2px 10px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.16);
  --shadow-header: 0 1px 3px rgba(15, 23, 42, 0.08);
  --overlay: rgba(15, 23, 42, 0.45);
  --chart-line: #2563eb; --chart-fill: rgba(37, 99, 235, 0.12);
  --chart-grid: rgba(15, 23, 42, 0.08); --chart-tick: #64748b;
  --logo-wordmark: #141a2e; --logo-arrow-blue: #312783; --logo-arrow-red: #c00d0e;
}

/* =========================================================
   1) Temel
   ========================================================= */
*, *::before, *::after { box-sizing: border-box }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { min-height: 100vh }

a { color: var(--link); text-decoration: none; transition: color .15s ease }
a:hover { color: var(--link-hover) }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px }

h1, h2, h3, h4, h5, h6 { color: var(--text-primary) }
strong, b { color: var(--text-primary) }

img, svg { max-width: 100% }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px }
::-webkit-scrollbar-thumb:hover { background: var(--muted) }

/* =========================================================
   2) Üst bar / marka / navigasyon
   ========================================================= */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-header);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto }

/* Vektörel logo: en-boy oranı viewBox ile korunur, yalnızca yükseklik verilir */
.brand-logo { height: 40px; width: auto; display: block; flex: none }
.brand-logo .logo-wordmark { fill: var(--logo-wordmark) }
.brand-logo .logo-arrow-blue { fill: var(--logo-arrow-blue) }
.brand-logo .logo-arrow-red { fill: var(--logo-arrow-red) }

.title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
  color: var(--text-primary);
  padding-left: 12px;
  border-left: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: none;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}
.nav-item:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.nav-item:active { transform: translateY(0) }
.nav-item.active {
  background: var(--primary-soft);
  border-color: var(--primary-ring);
  color: var(--primary-text);
}
.nav-item .ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  line-height: 1;
}
.nav-item .ico svg { width: 16px; height: 16px; display: block }
.nav-item-btn { padding: 0 8px }

.btn-link { background: transparent; border: none; color: var(--text); cursor: pointer; font: inherit; padding: 0 }

/* Tema değiştirme butonu */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}
.theme-toggle:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.theme-toggle:active { transform: translateY(0) }
.theme-toggle svg { width: 17px; height: 17px; display: block }
/* Açık temada ay (koyuya geç), koyu temada güneş (açığa geç) ikonu gösterilir */
.theme-toggle .theme-icon-sun { display: none }
.theme-toggle .theme-icon-moon { display: block }
html[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block }
html[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none }

/* Çıkış butonu - mor, modern */
.logout-form { margin: 0; display: flex }
.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--accent-glow);
  transition: box-shadow .18s ease, transform .12s ease, filter .18s ease;
}
.logout-btn:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px var(--accent-glow-strong);
  transform: translateY(-1px);
}
.logout-btn:active {
  transform: translateY(0) scale(.98);
  filter: brightness(.94);
  box-shadow: 0 2px 6px var(--accent-glow);
}
.logout-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
.logout-btn svg { width: 16px; height: 16px; display: block }

/* =========================================================
   3) Yerleşim
   ========================================================= */
.container { padding: 20px 16px 32px; max-width: 1180px; margin: 0 auto }
.page-title { margin: 0 0 16px; font-size: 20px; font-weight: 650; letter-spacing: -.01em; color: var(--text-primary) }

.grid.dashboard { display: grid; grid-template-columns: minmax(520px, 680px) 1fr; gap: 24px; align-items: start }
.grid.admin { display: grid; grid-template-columns: 1fr; gap: 12px }

.devices, .alarms { align-self: start }

/* =========================================================
   4) Kartlar
   ========================================================= */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.card-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-header-inline h3 { margin: 0; font-size: 15px; font-weight: 650 }

.alarms .card { margin-bottom: 16px }
.alarms .card:last-child { margin-bottom: 0 }
.alarms .toolbar { display: none; margin: 0; padding: 0; height: 0 }

.inline-controls { display: flex; align-items: center; gap: 8px }

.device {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.device .header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px }
.device .meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 12px }

/* =========================================================
   5) Göstergeler
   ========================================================= */
.led { display: inline-flex; align-items: center; gap: 6px; color: var(--text) }
.led .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none }
.led.green .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft) }
.led.red   .dot { background: var(--red);   box-shadow: 0 0 0 3px var(--red-soft) }
/* güncellendi - Üçüncü durum: bilinmiyor / pasif. Gri ve sönük. */
.led.off   .dot { background: var(--border-strong); box-shadow: none }
.led.off   { color: var(--muted) }

.big-led { display: inline-flex; align-items: center; gap: 6px; color: var(--text) }
.big-led .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); flex: none }
.big-led.green .dot { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft) }
.big-led.red .dot { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft) }

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0 }
.metric {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.metric .label { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; align-items: center; gap: 6px }
.metric .value { font-size: 13px; font-weight: 600; color: var(--text-primary) }

.alarm {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.alarm:hover { background: var(--surface-3) }

/* =========================================================
   6) Butonlar
   ========================================================= */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--primary-2);
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .12s ease, filter .15s ease;
}
.btn:hover { background: var(--primary-2); transform: translateY(-1px) }
.btn:active { transform: translateY(0) }
.btn.small { padding: 6px 10px; font-size: 12px }
.btn.medium { padding: 10px 16px; font-size: 14px }
.btn.pill { border-radius: 999px }
.btn.outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.outline:hover { background: var(--hover); color: var(--text-primary) }
.btn.critical { background: var(--red-solid); border-color: var(--red-solid); color: #fff; box-shadow: 0 4px 14px var(--red-soft) }
.btn.critical:hover { filter: brightness(1.06); background: var(--red-solid) }

.toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin: 4px 0 10px }

/* =========================================================
   7) Form elemanları
   ========================================================= */
.form-grid { display: grid; grid-template-columns: 220px 1fr; gap: 10px; margin: 10px 0; align-items: center }
.form-inline form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px }

.input, select.input, textarea.input {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--muted) }
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* =========================================================
   8) Tablo ve kod bloğu
   ========================================================= */
.table { width: 100%; border-collapse: collapse; color: var(--text) }
.table th, .table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  font-size: 14px;
}
.table th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px }
.table tbody tr:hover { background: var(--hover) }

.pre {
  max-height: 300px;
  overflow: auto;
  background: var(--pre-bg);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  color: var(--pre-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 12px;
}

.muted { color: var(--muted); font-size: 12px }
.error { color: var(--red-text) }

/* =========================================================
   9) "Son veri" satırı
   ========================================================= */
.latest-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--item-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  transition: background .18s ease, border-color .18s ease;
}
.latest-row:hover { background: var(--surface-2); border-color: var(--border-strong) }
.latest-row .btn.tiny {
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.1;
  white-space: nowrap;
  border-radius: 6px;
}

.latest-list { max-height: 320px; overflow-y: auto }

/* =========================================================
   10) Alarm modalı
   ========================================================= */
.alarm-modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.alarm-modal .alarm-modal-content {
  width: min(560px, 92vw);
  max-width: 100%;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}
.alarm-modal .alarm-gif { max-width: 100%; max-height: 420px; object-fit: contain; display: block }
.alarm-modal .btn { width: 100% }
.alarm-modal .modal-title { font-weight: 650; font-size: 16px; text-align: center; margin: 8px 0 4px; color: var(--text-primary) }
.alarm-modal .modal-text { font-size: .95rem; text-align: center; margin-bottom: 8px; min-height: 1.2em; color: var(--text) }
.alarm-modal .alarm-modal-header { background: var(--red-soft); color: var(--red-text); border-bottom: 1px solid var(--border) }
.alarm-modal .alarm-modal-text { color: var(--text) }
.alarm-modal .alarm-modal-footer { border-top: 1px solid var(--border) }
.alarm-modal #btn-alarm-ack { background: var(--red-solid); color: #fff; border: 1px solid var(--red-solid) }

/* =========================================================
   11) Paylaşılan sayfa bileşenleri (gecmis / reports / admin)
   ========================================================= */
.device-chart-card, .recent-data-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.recent-data-item { background: var(--item-bg); border-left-color: var(--primary) }

.quick-date-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.quick-date-btn:hover { background: var(--surface-3); border-color: var(--border-strong) }

/* =========================================================
   12) Duyarlı (responsive) düzen
   ========================================================= */
@media (max-width: 1024px) {
  .grid.dashboard { grid-template-columns: 1fr }
  .metrics { grid-template-columns: 1fr }
}

/* Dar masaüstü / tablet: üst bar tek satırda kalsın diye menü sadece ikon gösterir */
@media (min-width: 769px) and (max-width: 1100px) {
  .nav-item .nav-text, .logout-btn .logout-text { display: none }
  .nav-item { padding: 0 10px }
  .logout-btn { padding: 0 11px }
}

@media (max-width: 768px) {
  .app-header { flex-wrap: wrap; padding: 10px 12px; gap: 10px }

  .brand { flex: 1 1 100%; justify-content: center }
  .brand-logo { height: 34px }
  .title { font-size: 13px; padding-left: 10px }

  .top-nav { flex: 1 1 100%; justify-content: center; gap: 6px; flex-wrap: wrap }
  .nav-item { font-size: 12px; height: 32px; padding: 0 11px }
  .theme-toggle { width: 32px; height: 32px }
  .logout-btn { height: 32px; padding: 0 13px; font-size: 12px }

  .container { padding: 14px 10px 24px }
  .page-title { font-size: 17px; margin-bottom: 12px }

  .grid.dashboard { grid-template-columns: 1fr; gap: 12px }

  .device { padding: 10px }
  .device .header { flex-direction: column; align-items: flex-start; gap: 6px }
  .device .meta { width: 100%; justify-content: flex-start }

  .metrics { grid-template-columns: 1fr; gap: 6px }

  .card { padding: 12px }
  .alarms .card { margin-bottom: 12px }
  .card-header-inline { flex-direction: column; align-items: stretch; gap: 8px }
  .card-header-inline h3 { text-align: left }
  .card-header-inline .inline-controls { width: 100%; justify-content: stretch }
  .card-header-inline .inline-controls .btn { flex: 1 }

  .btn { font-size: 13px; padding: 8px 12px }
  .btn.small { font-size: 12px; padding: 6px 10px }

  .form-grid { grid-template-columns: 1fr; gap: 6px }
  .input { font-size: 14px; padding: 8px 10px }

  .alarm { flex-direction: column; gap: 8px }

  .alarm-modal .alarm-modal-content { width: 100%; max-width: 360px; max-height: 85vh }
  .alarm-modal .alarm-gif { max-height: 280px }

  .latest-row { padding: 10px; gap: 10px }
  .latest-row > div:first-child { flex: 1; font-size: 12px; line-height: 1.4; padding-right: 6px }
  .latest-row .btn.tiny { padding: 5px 10px; font-size: 11px; min-width: 60px; text-align: center; flex-shrink: 0 }

  .latest-list { max-height: 400px }

  .table { font-size: 13px }
  .table th, .table td { padding: 7px 8px }
}

@media (max-width: 480px) {
  .brand-logo { height: 30px }
  .title { font-size: 12px }

  .nav-item .nav-text, .logout-btn .logout-text { display: none }
  .nav-item { padding: 0 10px }
  .logout-btn { padding: 0 11px }

  .page-title { font-size: 16px }
  .container { padding: 12px 8px 20px }

  .device { padding: 8px }
  .metric { padding: 6px 8px }
  .metric .label { font-size: 10px }
  .metric .value { font-size: 12px }

  .latest-row { padding: 8px; gap: 8px }
  .latest-row > div:first-child { font-size: 11px }
  .latest-row .btn.tiny { padding: 4px 8px; font-size: 10px; min-width: 55px }
}

/* Hareket azaltma tercihi */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important }
}
