/* KidsGPS — parent app */

:root {
  --accent: #6d5efc;
  --accent-2: #8b7dff;
  --accent-soft: rgba(109, 94, 252, 0.12);
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --moving: #10b981;
  --still: #3b82f6;
  --offline: #94a3b8;
  --nodata: #f59e0b;

  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --glass: rgba(255, 255, 255, 0.82);
  --text: #12131a;
  --muted: #6b7280;
  --muted-2: #d6d8e1;
  --border: rgba(17, 24, 39, 0.08);
  --shadow-sm: 0 2px 8px rgba(17, 24, 39, 0.08);
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.12), 0 2px 6px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 -12px 40px rgba(17, 24, 39, 0.16);

  --radius: 22px;
  --radius-sm: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0b0c12;
  --surface: #15161f;
  --surface-2: #1d1f2b;
  --glass: rgba(21, 22, 31, 0.8);
  --text: #f3f4f8;
  --muted: #9aa0b4;
  --muted-2: #343747;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 -12px 40px rgba(0, 0, 0, 0.55);
  --accent-soft: rgba(139, 125, 255, 0.18);
  color-scheme: dark;
}

:root[dir='rtl'] { --font: 'Tajawal', 'Inter', system-ui, sans-serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
.ic { width: 20px; height: 20px; flex: none; }
.ic.big { width: 44px; height: 44px; opacity: 0.35; }
.hidden { display: none !important; }

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 6px; }

/* ---------- Floating chrome ---------- */

.glass {
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.topbar {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  inset-inline: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 20;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.top-actions { display: flex; gap: 10px; }

.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding-inline: 6px 16px;
  border-radius: 999px;
  max-width: 62vw;
  transition: transform .15s;
}
.chip:active { transform: scale(.97); }
.chip-avatar {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  background: color-mix(in srgb, var(--kid) 18%, var(--surface));
  box-shadow: inset 0 0 0 2.5px var(--kid);
}
.chip-avatar .dot { position: absolute; bottom: -1px; inset-inline-end: -1px; border: 2.5px solid var(--surface); width: 13px; height: 13px; }
.chip-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge[hidden] { display: none; }
.chip-chevron { width: 16px; height: 16px; opacity: .6; }

.icon-btn {
  width: 50px; height: 50px;
  border-radius: 50%;
  display: grid; place-items: center;
  position: relative;
  transition: transform .15s, background .2s, color .2s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.active { color: var(--accent); }
.icon-btn.flat { width: 40px; height: 40px; background: var(--surface-2); box-shadow: none; }
.badge {
  position: absolute; top: 4px; inset-inline-end: 4px;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
}

.fab-col {
  position: fixed;
  inset-inline-end: 12px;
  top: calc(var(--safe-top) + 74px);
  display: flex; flex-direction: column; gap: 10px;
  z-index: 15;
}

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--offline); flex: none; }
.dot.status-moving { background: var(--moving); box-shadow: 0 0 0 0 rgba(16, 185, 129, .6); animation: ping 1.8s infinite; }
.dot.status-still { background: var(--still); }
.dot.status-offline { background: var(--offline); }
.dot.status-noData { background: var(--nodata); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,.55); } 80%, 100% { box-shadow: 0 0 0 9px rgba(16,185,129,0); } }

body.offline-link .chip::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--warn);
  margin-inline-start: -4px;
}

/* ---------- Kid marker ---------- */

.kid-marker { position: relative; width: 64px; height: 64px; display: grid; place-items: center; --kid: var(--accent); }
.kid-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px;
  background: #fff;
  box-shadow: 0 0 0 4px var(--kid), 0 8px 20px rgba(0,0,0,.28);
  position: relative; z-index: 2;
  transition: transform .3s;
}
.kid-pulse {
  position: absolute; inset: 9px;
  border-radius: 50%;
  background: var(--kid);
  opacity: 0;
}
.kid-marker.status-moving .kid-pulse { animation: halo 2s ease-out infinite; }
.kid-marker.status-still .kid-pulse { animation: halo 3.2s ease-out infinite; }
@keyframes halo { 0% { transform: scale(1); opacity: .45; } 100% { transform: scale(2.3); opacity: 0; } }
.kid-heading {
  position: absolute; inset: 0;
  z-index: 1;
  opacity: 0;
  transition: transform .6s;
}
.kid-heading::before {
  content: ''; position: absolute; top: -2px; left: 50%;
  transform: translateX(-50%);
  border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-bottom: 13px solid var(--kid);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.25));
}
.kid-marker.status-moving .kid-heading { opacity: 1; }
.kid-marker.status-offline .kid-avatar { filter: grayscale(1); box-shadow: 0 0 0 4px var(--offline), 0 8px 20px rgba(0,0,0,.25); }

.ghost-marker {
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 5px #ec4899, 0 6px 14px rgba(0,0,0,.3);
}
.stay-marker {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface); color: var(--text);
  font-weight: 800; font-size: 13px;
  box-shadow: 0 0 0 3px #6d5efc, var(--shadow-sm);
}
.place-label {
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 12.5px;
  box-shadow: 0 0 0 2px var(--place), var(--shadow-sm);
  white-space: nowrap;
}

/* ---------- Bottom sheet ---------- */

.sheet, .panel {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 30;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: calc(var(--safe-bottom) + 8px);
}
.sheet {
  max-height: calc(300px + var(--safe-bottom));
  overflow: hidden;
  transition: max-height .38s cubic-bezier(.2,.8,.2,1), transform .35s cubic-bezier(.2,.8,.2,1);
}
.sheet.expanded { max-height: 82vh; overflow-y: auto; }
.sheet.hidden { display: block !important; transform: translateY(110%); }
.sheet-handle { padding: 10px 0 4px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--muted-2); }
.sheet-content { padding: 4px 18px 6px; }

.card-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 24px;
  background: color-mix(in srgb, var(--kid) 16%, var(--surface));
  box-shadow: inset 0 0 0 2.5px var(--kid);
}
.avatar-lg { width: 56px; height: 56px; font-size: 32px; }
.avatar-xl { width: 76px; height: 76px; font-size: 44px; }
.who { flex: 1; min-width: 0; }
.name { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 600; font-size: 14px; margin-top: 2px; }
.updated { font-size: 12.5px; color: var(--muted); white-space: nowrap; align-self: flex-start; padding-top: 6px; }

.address {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 14px 0 12px;
  font-size: 14.5px; font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}
.address .ic { color: var(--accent); margin-top: 1px; width: 18px; height: 18px; }
.address span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 6px 9px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-align: center;
}
.stat .ic { color: var(--muted); width: 19px; height: 19px; }
.stat b { font-size: 15px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--muted); font-weight: 600; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 6px; }
.actions button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 2px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  transition: transform .15s;
}
.actions button:active { transform: scale(.95); }

.today { margin-top: 18px; }
.section-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
:root[dir='rtl'] .section-title { letter-spacing: 0; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.summary div {
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.summary b { font-size: 18px; font-weight: 800; }
.summary span { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- Timeline ---------- */

.timeline { display: flex; flex-direction: column; position: relative; }
.tl-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px;
  text-align: start;
  border-radius: 12px;
  position: relative;
}
.tl-item:active { background: var(--surface-2); }
.tl-item + .tl-item::before {
  content: ''; position: absolute; top: -12px; height: 22px;
  inset-inline-start: 23px; width: 2px; background: var(--muted-2);
}
.tl-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 19px;
  position: relative; z-index: 1;
}
.tl-stay .tl-icon { background: rgba(59,130,246,.12); color: var(--still); }
.tl-trip .tl-icon { background: rgba(16,185,129,.12); color: var(--moving); }
.tl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tl-main b { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-main small { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.tl-side { font-size: 12.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }

/* ---------- Panels ---------- */

.panel {
  height: 86vh;
  transform: translateY(105%);
  transition: transform .4s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.panel.open { transform: translateY(0); }
.panel-history { height: 52vh; }
.panel-placeEdit { height: auto; max-height: 60vh; }
.panel-places { height: 60vh; }
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px 10px;
}
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 800; flex: 1; }
.panel-sub { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: capitalize; }
.panel-body { padding: 4px 18px 18px; overflow-y: auto; flex: 1; }
.panel-body.list { display: flex; flex-direction: column; gap: 8px; }

.day-chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 18px 10px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.day-chip {
  flex: none; padding: 8px 14px; border-radius: 999px;
  background: var(--surface-2); font-weight: 700; font-size: 13px;
  text-transform: capitalize;
}
.day-chip.on { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(109,94,252,.35); }

.replay { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.replay .icon-btn { width: 44px; height: 44px; background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(109,94,252,.35); }
.replay input { flex: 1; accent-color: var(--accent); }
.replay-time { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 48px; text-align: end; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: start;
  width: 100%;
}
.row.on { box-shadow: inset 0 0 0 2px var(--accent); }
.row-main-btn { display: flex; align-items: center; gap: 12px; flex: 1; text-align: start; min-width: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-main b { font-weight: 700; }
.row-main small { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.place-icon {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 21px;
  background: color-mix(in srgb, var(--place) 16%, var(--surface));
}

.alert-list { display: flex; flex-direction: column; gap: 6px; }
.alert-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.alert-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--still); flex: none; }
.alert-in .alert-dot { background: var(--moving); }
.alert-out .alert-dot { background: var(--warn); }
.alert-alarm .alert-dot { background: var(--danger); }
.alert-moving .alert-dot { background: var(--moving); opacity: .55; }
.alert-stopped .alert-dot { background: var(--still); opacity: .55; }
.alert-text { flex: 1; font-weight: 600; font-size: 14px; }
.alert-time { display: flex; flex-direction: column; align-items: flex-end; font-weight: 700; font-size: 13px; }
.alert-time small { color: var(--muted); font-weight: 600; text-transform: capitalize; }

/* ---------- Forms & buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px;
  border-radius: 16px;
  font-weight: 700; font-size: 15px;
  transition: transform .15s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; }
.btn-block { width: 100%; margin-top: 10px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 10px 24px rgba(109,94,252,.35); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn-row { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: 14px; }

.group { background: var(--surface-2); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input:not([type='range']) {
  height: 48px; padding: 0 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field input[type='range'] { accent-color: var(--accent); }
.kid-edit { display: flex; align-items: center; gap: 14px; }
.kid-edit .field { flex: 1; }

.segmented { display: flex; background: var(--surface); border-radius: 14px; padding: 4px; gap: 4px; border: 1px solid var(--border); }
.segmented button { flex: 1; padding: 9px 6px; border-radius: 10px; font-weight: 700; font-size: 13.5px; color: var(--muted); transition: background .2s, color .2s; }
.segmented button.on { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(109,94,252,.3); }

.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emoji-grid button { height: 46px; border-radius: 14px; font-size: 24px; background: var(--surface); border: 1.5px solid var(--border); }
.emoji-grid button.on { border-color: var(--accent); background: var(--accent-soft); }
.emoji-grid.places { margin: 12px 0; }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-row button { width: 34px; height: 34px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px var(--surface), 0 0 0 0 var(--c); transition: box-shadow .2s; }
.color-row button.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }

.hint { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; margin: 6px 0; }
.hint.ok { color: var(--ok); font-weight: 700; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--muted); padding: 30px 10px; font-weight: 500; }
.empty.small { padding: 10px; font-size: 13.5px; }
.empty p { margin: 0; max-width: 280px; line-height: 1.4; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--muted-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { display: flex; flex-direction: column; gap: 12px; padding: 6px 0 14px; }
.skeleton i { height: 18px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--muted-2), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton i:first-child { height: 52px; width: 70%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Place editor */
.placement-pin {
  width: 34px; height: 40px; pointer-events: none;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%236d5efc' d='M12 2a8 8 0 0 0-8 8c0 6 8 12 8 12s8-6 8-12a8 8 0 0 0-8-8Z'/%3E%3Ccircle cx='12' cy='10' r='3' fill='white'/%3E%3C/svg%3E");
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.3));
}
body.placing .fab-col { display: none; }

/* ---------- Login ---------- */

.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(109,94,252,.35), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(236,72,153,.28), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: 28px;
  padding: 30px 24px 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo {
  width: 76px; height: 76px; margin: 0 auto 4px;
  border-radius: 24px;
  display: grid; place-items: center;
  font-size: 42px;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  box-shadow: 0 14px 30px rgba(109,94,252,.4);
}
.login-card h1 { margin: 0; text-align: center; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.login-tagline { margin: -4px 0 10px; text-align: center; color: var(--muted); }
.login-card input {
  height: 52px; padding: 0 16px;
  border-radius: 16px; border: 1.5px solid var(--border);
  background: var(--surface-2); outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.login-error { color: var(--danger); font-size: 13.5px; font-weight: 600; min-height: 18px; text-align: center; }
.login-lang { margin-top: 8px; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed; z-index: 200;
  top: calc(var(--safe-top) + 72px);
  inset-inline: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 420px;
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--text); color: var(--surface);
  font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow);
  transform: translateY(-14px); opacity: 0;
  transition: transform .3s, opacity .3s;
}
.toast.show { transform: none; opacity: 1; }
.toast-error { background: var(--danger); color: #fff; }

/* ---------- Large screens: card + panels on the side ---------- */

@media (min-width: 820px) {
  .sheet, .panel {
    inset-inline-start: 16px; inset-inline-end: auto;
    bottom: 16px; width: 400px;
    border-radius: var(--radius);
  }
  .sheet { max-height: calc(100vh - 110px); }
  .sheet.expanded { max-height: calc(100vh - 110px); }
  .panel { top: 80px; height: auto !important; max-height: none; transform: translateX(-120%); }
  :root[dir='rtl'] .panel { transform: translateX(120%); }
  .panel.open { transform: none !important; }
  .topbar { inset-inline-start: 16px; }
}
