:root {
  --bg: #0f1220; --panel: #191d33; --panel2: #222741; --line: #2d3350;
  --text: #e7e9f3; --muted: #9aa0c0; --accent: #5b7cfa; --accent2: #3a56d4;
  --ok: #35c58a; --warn: #f2b53c; --danger: #ff4d5e; --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg);
  color: var(--text); height: 100vh; overflow: hidden;
}
button {
  font: inherit; cursor: pointer; border: none; border-radius: 8px; padding: 9px 14px;
  background: var(--accent); color: #fff; transition: .15s;
}
button:hover { background: var(--accent2); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover { background: var(--panel2); }
button.danger { background: var(--danger); }
button.sm { padding: 5px 10px; font-size: 13px; }
input, select {
  font: inherit; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }

/* Giriş ekranı */
#auth {
  height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #23294a, var(--bg));
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.brand { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.brand .shield { color: var(--accent); }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }
.switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.switch a { color: var(--accent); cursor: pointer; }

/* Uygulama düzeni */
#appwrap { height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#side .top { padding: 18px; border-bottom: 1px solid var(--line); }
#childList { flex: 1; overflow: auto; padding: 8px; }
.child {
  padding: 12px; border-radius: 10px; cursor: pointer; margin-bottom: 6px;
  border: 1px solid transparent;
}
.child:hover { background: var(--panel2); }
.child.active { background: var(--panel2); border-color: var(--accent); }
.child .name { font-weight: 600; }
.child .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.on { background: var(--ok); } .dot.off { background: var(--muted); }
#side .bottom { padding: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

#main { display: flex; flex-direction: column; overflow: hidden; }
#tabs { display: flex; gap: 6px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--text); }
#view { flex: 1; overflow: auto; padding: 18px; }

#map { height: 100%; min-height: 420px; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.bar { height: 8px; background: var(--panel2); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* En çok kullanılan uygulamalar bar grafiği */
.chart { display: flex; flex-direction: column; gap: 10px; }
.chart-row { display: grid; grid-template-columns: 180px 1fr 72px; align-items: center; gap: 12px; }
.chart-row .bar { height: 16px; }
.chart-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chart-val { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .chart-row { grid-template-columns: 110px 1fr 60px; gap: 8px; } }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.badge.block { background: rgba(255,77,94,.15); color: var(--danger); }
.badge.ok { background: rgba(53,197,138,.15); color: var(--ok); }
/* Uygulama durumu rozetleri */
.badge.on { background: rgba(53,197,138,.15); color: var(--ok); }
.badge.off { background: rgba(154,160,192,.18); color: var(--muted); }
.badge.use { background: rgba(91,124,250,.18); color: var(--accent); }
.limit-row.app-passive { opacity: .55; }
.limit-name .badge { margin-left: 6px; font-size: 11px; vertical-align: middle; }

/* Ayarlar grid paneli */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-bottom: 20px; }
@media (max-width: 768px) { .settings-grid { grid-template-columns: 1fr; } }

/* Sekme stilleri (Kullanım ve Limitler ekranları) */
.u-tabs, .lim-tabs { display: flex; gap: 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.u-tab, .lim-tab { padding: 10px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
.u-tab:hover, .lim-tab:hover { color: var(--text); }
.u-tab.active, .lim-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.u-content, .lim-content { animation: fadeIn .15s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Acil yardım kaplaması. z-index Leaflet'in kontrol/katman öğelerinden
   (en çok ~1000) YÜKSEK olmalı: aksi halde arka plandaki Konum haritasının
   katmanları bu pencerenin üstüne biniyor ve Kapat düğmesi tıklanamıyordu. */
#emergency {
  position: fixed; inset: 0; background: rgba(10,10,20,.85); display: grid; place-items: center; z-index: 3000;
}
.emg-card {
  background: var(--panel); border: 2px solid var(--danger); border-radius: 16px; width: min(880px, 94vw);
  padding: 20px; box-shadow: 0 0 0 6px rgba(255,77,94,.15);
}
.emg-head { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; color: var(--danger); }
#emgBanner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2900; padding: 12px 16px; text-align: center;
  background: var(--danger); color: #fff; font-weight: 700; cursor: pointer;
  animation: emgBlink 1s infinite; box-shadow: 0 4px 20px rgba(255,77,94,.5);
}
@keyframes emgBlink { 0%,100%{filter:brightness(1);} 50%{filter:brightness(.7);} }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.3;} }
.emg-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-top: 14px; }
#emgVideo { width: 100%; background: #000; border-radius: 10px; aspect-ratio: 4/3; }
#emgMap { width: 100%; height: 260px; border-radius: 10px; }
/* Leaflet harita kapları kendi yığılma bağlamına hapsedilir: içlerindeki
   yüksek z-index'li panel/kontrol öğeleri (400–1000) dışarı sızıp başka
   pencereleri örtemez. */
#map, #emgMap { position: relative; z-index: 0; isolation: isolate; overflow: hidden; }
.emg-status { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* Genel */
.h { font-size: 18px; font-weight: 700; margin: 0 0 14px; }
.muted { color: var(--muted); }
.pill { background: var(--panel2); border: 1px solid var(--line); padding: 12px 16px; border-radius: 10px; }
.code { font-family: ui-monospace, monospace; font-size: 26px; letter-spacing: 6px; color: var(--accent); }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

/* Uygulama içi metin/onay penceresi */
.ui-modal { position: fixed; inset: 0; background: rgba(10,10,20,.6); display: grid; place-items: center; z-index: 4000; }
.ui-modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.ui-modal-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.ui-modal-input { width: 100%; }
.ui-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.app-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.app-row { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.app-row:last-child { border-bottom: none; }
.app-row:hover { background: var(--panel2); }
.app-name { font-size: 14px; }
.app-pkg { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* İkonlu limit listesi */
.app-ic { width: 32px; height: 32px; border-radius: 7px; flex: 0 0 auto; }
.limit-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.limit-row:last-child { border-bottom: none; }
.limit-name { flex: 1; font-size: 14px; }
.lim-min { width: 70px; text-align: center; }
.lim-block { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.lim-block input, .day-chip input { width: auto; }
.day-chip { display: flex; align-items: center; gap: 4px; font-size: 13px; background: var(--panel2); border: 1px solid var(--line); padding: 5px 9px; border-radius: 8px; cursor: pointer; }
#appLimitList { border: 1px solid var(--line); border-radius: 10px; overflow-y: auto; flex: 1; min-height: 300px; }
.lim-content { display: flex; flex-direction: column; }

/* Konum haritası: insan işareti ve üzerindeki konum saati */
.person-mk { background: none; border: none; text-align: center; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.leaflet-tooltip.ptime { background: rgba(15,18,32,.88); color: #fff; border: 1px solid var(--line); padding: 1px 5px; font-size: 11px; border-radius: 8px; box-shadow: none; }
.leaflet-tooltip.ptime::before { display: none; }
.leaflet-tooltip.ptime-cur { background: var(--ok); color: #06210f; font-weight: 700; border-color: var(--ok); }
#listPane table { margin-bottom: 8px; }
.stop-mk { background: none; border: none; }
.stop-pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: #f2b53c; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.5); display: grid; place-items: center; }
.stop-pin { font-size: 0; }
.stop-pin::after { content: "⏸"; font-size: 14px; transform: rotate(45deg); color: #3b2a00; }
.leaflet-tooltip.stop-lbl { background: #f2b53c; color: #2a1d00; border-color: #fff; font-weight: 600; text-align: center; white-space: nowrap; }
.leaflet-tooltip.stop-lbl::before { display: none; }

/* Konum ekranı: harita boş kalan alanın tamamını kaplar */
.map-screen { display: flex; flex-direction: column; height: 100%; min-height: 520px; }
.map-screen #mapPane { flex: 1; min-height: 360px; position: relative; }
.map-screen #mapPane #map { position: absolute; inset: 0; height: auto; min-height: 0; }
.map-screen #listPane { flex: 1; overflow: auto; min-height: 0; }
.map-note { position: relative; max-width: 340px; padding: 8px 26px 8px 10px; font-size: 12px; line-height: 1.4; color: var(--text);
  background: rgba(15,18,32,.92); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.map-note-x { position: absolute; top: 2px; right: 8px; cursor: pointer; font-size: 18px; color: var(--muted); }
.map-note-x:hover { color: var(--text); }
