/* ===== TrackForce UI ===== */
:root {
  --brand: #0f766e;
  --brand-600: #0d6b63;
  --brand-50: #e7f5f3;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --live: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --topbar: 60px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); line-height: 1.45; font-size: 15px; }
h1, h2, h3 { margin: 0 0 .35em; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--brand); }
code { background: #eef1f4; padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ----- Buttons & forms ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger-soft { background: #fee2e2; color: #b91c1c; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .875rem; border-radius: 8px; }
.btn-xl { min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: .875rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); width: 100%;
  min-height: 42px; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid rgba(15, 118, 110, .25); outline-offset: 1px; border-color: var(--brand); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: .9rem; margin: 0 0 14px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; margin-top: 14px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-live { background: #dcfce7; color: #166534; }
.badge-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--live); animation: blink 1.6s infinite; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
@keyframes blink { 50% { opacity: .3; } }

.avatar {
  --hue: 170; position: relative; display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%; font-weight: 700; color: #fff;
  background: hsl(var(--hue) 55% 42%);
}
.avatar.sm { width: 38px; height: 38px; font-size: .85rem; }
.status-dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; background: #9ca3af; }
.status-dot.live { background: var(--live); }
.status-dot.warn { background: var(--warn); }

/* ----- Top bar ----- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.1rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }
.brand-lg { font-size: 1.3rem; margin-bottom: 18px; }
.brand-lg img { width: 38px; height: 38px; }
.mainnav { display: flex; gap: 4px; margin-left: 12px; }
.mainnav a { display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; }
.mainnav a:hover { background: #f3f4f6; color: var(--text); }
.mainnav a.active { background: var(--brand-50); color: var(--brand); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: .9rem; }

.toast {
  position: fixed; z-index: 100; left: 50%; top: calc(var(--topbar) + 12px); transform: translateX(-50%);
  padding: 10px 18px; border-radius: 10px; color: #fff; background: #111827; box-shadow: var(--shadow);
  font-weight: 600; font-size: .9rem; transition: opacity .3s, transform .3s; max-width: calc(100% - 32px);
}
.toast-error { background: var(--danger); }
.toast.hide { opacity: 0; transform: translate(-50%, -10px); pointer-events: none; }

/* ----- Auth ----- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 0%, #d6efec, transparent 50%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); padding: 32px 28px; border-radius: 18px; box-shadow: var(--shadow); }

/* ----- Generic page ----- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head p { max-width: 640px; margin: 0; }
.empty { text-align: center; padding: 60px 20px; background: var(--surface); border-radius: var(--radius); border: 1px dashed #d1d5db; }
.empty > svg { width: 44px; height: 44px; color: var(--muted); margin-bottom: 10px; }

/* ----- Employee cards ----- */
.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.emp-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.emp-card.is-disabled { opacity: .65; }
.emp-card-top { display: flex; align-items: center; gap: 12px; }
.emp-card-info { flex: 1; min-width: 0; }
.emp-card-info h3, .emp-card-info p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-card-info p { font-size: .85rem; }
.emp-meta { font-size: .82rem; margin: 0; }
.emp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

.menu { position: relative; margin-left: auto; }
.menu summary { list-style: none; font-size: 1.2rem; letter-spacing: 1px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 10; min-width: 180px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu-pop form { margin: 0; }
.menu-pop button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: none; font: inherit; border-radius: 8px; cursor: pointer; }
.menu-pop button:hover { background: #f3f4f6; }
.menu-pop .danger { color: var(--danger); }

/* ----- Modal ----- */
.modal { border: 0; border-radius: 18px; padding: 24px; width: min(460px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal::backdrop { background: rgba(17, 24, 39, .45); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.qr { display: grid; place-items: center; padding: 14px; margin: 6px 0 14px; background: #f9fafb; border-radius: 12px; min-height: 60px; }
.qr img, .qr canvas { max-width: 100%; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: .85rem; }
.share-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.share-btns .btn { flex: 1; }

/* ===== Map pages ===== */
.map-page { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.live { flex: 1; min-height: 0; display: flex; position: relative; }
.panel { width: 360px; flex: none; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; z-index: 5; }
.panel-head { padding: 16px; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.panel-handle { display: none; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { display: grid; gap: 1px; padding: 8px 4px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font: inherit; cursor: pointer; text-align: center; }
.stat b { font-size: 1.15rem; }
.stat span { font-size: .72rem; color: var(--muted); font-weight: 600; }
.stat.active { border-color: var(--brand); background: var(--brand-50); }
.stat.active span { color: var(--brand); }
.search { min-height: 40px; }
.emp-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.emp-list-empty { padding: 30px 16px; text-align: center; }
.emp-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; border-radius: 12px; background: none; font: inherit; text-align: left; cursor: pointer; color: inherit; }
.emp-row:hover { background: #f6f7f9; }
.emp-row.selected { background: var(--brand-50); }
.emp-row:disabled { cursor: default; opacity: .6; }
.emp-row-text { flex: 1; min-width: 0; display: grid; }
.emp-row-text b, .emp-row-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-row-text small { color: var(--muted); font-size: .8rem; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--line); font-size: .8rem; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--live); animation: blink 1.6s infinite; }

.map-wrap { flex: 1; position: relative; min-width: 0; }
.map { position: absolute; inset: 0; background: #e5e7eb; }
.map-tools { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; pointer-events: none; z-index: 2; }
.map-tools > * { pointer-events: auto; }
.place-search { flex: 0 1 380px; min-width: 0; }
.place-search input, .place-search gmp-place-autocomplete { width: 100%; box-shadow: var(--shadow); border: 0; border-radius: 10px; color-scheme: light; }
.map-btn { margin-left: auto; width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 10px; background: #fff; box-shadow: var(--shadow); cursor: pointer; color: var(--text); }
.map-error { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 420px; width: calc(100% - 32px); background: #fff; padding: 18px; border-radius: 12px; box-shadow: var(--shadow); color: #991b1b; z-index: 3; }

/* Live marker */
.pin { --hue: 170; position: relative; display: flex; flex-direction: column; align-items: center; cursor: pointer; transform: translateY(6px); }
.pin-face {
  position: relative; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: hsl(var(--hue) 55% 42%); color: #fff; font: 700 13px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); z-index: 1;
}
.pin-name {
  margin-top: 3px; padding: 1px 7px; border-radius: 6px; background: rgba(17, 24, 39, .82); color: #fff;
  font: 600 11px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis;
}
.pin-arrow { position: absolute; top: -9px; left: 50%; width: 0; height: 0; margin-left: -6px; border: 6px solid transparent; border-bottom: 9px solid hsl(var(--hue) 55% 35%); transform-origin: 50% 28px; }
.pin[data-status="live"] .pin-face::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 3px solid var(--live); animation: ping 2s ease-out infinite; }
.pin[data-status="nosignal"] .pin-face { filter: saturate(.4); border-color: #fde68a; }
.pin[data-status="stopped"] .pin-face, .pin[data-status="never"] .pin-face { filter: grayscale(1); opacity: .75; }
.pin.selected .pin-face { transform: scale(1.15); border-color: var(--brand); }
@keyframes ping { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.8); opacity: 0; } }

/* Info window */
.iw { min-width: 220px; font-size: .85rem; }
.iw-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .95rem; margin-bottom: 2px; }
.iw dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0; }
.iw dt { color: var(--muted); }
.iw dd { margin: 0; font-weight: 600; }
.iw-addr { font-size: .8rem; margin-bottom: 10px; }
.iw-actions { display: flex; flex-wrap: wrap; gap: 12px; padding-top: 8px; border-top: 1px solid var(--line); }
.iw-actions a { font-weight: 600; text-decoration: none; }

/* History */
.panel-history { overflow-y: auto; }
.h-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px 16px 0; }
.h-stats div { background: #f9fafb; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; }
.h-stats b { font-size: 1.1rem; }
.h-stats span { font-size: .75rem; color: var(--muted); font-weight: 600; }
.player { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.player-row { display: flex; align-items: center; gap: 10px; }
.player-row input[type=range] { flex: 1; min-height: 0; padding: 0; border: 0; accent-color: var(--brand); }
.player-row select { width: auto; min-height: 36px; padding: 4px 8px; font-size: .8rem; }
.player-meta { display: flex; justify-content: space-between; font-size: .8rem; margin-top: 6px; }
.stop-list { list-style: none; margin: 0; padding: 8px; }
.stop-list button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border: 0; background: none; border-radius: 10px; font: inherit; text-align: left; cursor: pointer; }
.stop-list button:hover { background: #f6f7f9; }
.stop-list span:last-child { display: grid; }
.h-empty { padding: 20px 16px; text-align: center; }
.hpin { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #fff; font: 700 12px/1 -apple-system, BlinkMacSystemFont, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .35); flex: none; }
.hpin-start { background: var(--live); }
.hpin-end { background: var(--danger); }
.hpin-stop { background: var(--warn); width: 24px; height: 24px; font-size: 11px; }
.hpin-play { width: 20px; height: 20px; background: var(--brand); border-width: 3px; box-shadow: 0 0 0 6px rgba(15, 118, 110, .25); }

/* ===== Employee tracker app ===== */
.tracker-page { min-height: 100vh; min-height: 100dvh; background: var(--bg); }
.tk { max-width: 480px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.tk-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 2px; }
.tk-user { display: grid; text-align: right; font-size: .9rem; }
.tk-card { background: var(--surface); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.tk-center { text-align: center; }
.tk-center h1 { font-size: 1.35rem; margin-top: 14px; }
.tk-center p { min-height: 2.9em; }
.ring { --c: #9ca3af; position: relative; width: 112px; height: 112px; margin: 6px auto 0; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 14%, #fff); color: var(--c); }
.ring svg { width: 46px; height: 46px; }
.ring::before, .ring::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--c); opacity: 0; }
.ring[data-state="active"], .ring[data-state="saver"] { --c: var(--live); }
.ring[data-state="active"]::before, .ring[data-state="active"]::after { animation: ripple 2.4s ease-out infinite; }
.ring[data-state="active"]::after { animation-delay: 1.2s; }
.ring[data-state="saver"]::before { opacity: .5; }
.ring[data-state="search"] { --c: var(--warn); }
.ring[data-state="search"]::before { opacity: 1; border-color: transparent; border-top-color: var(--warn); animation: spin 1s linear infinite; }
.ring[data-state="error"], .ring-error { --c: var(--danger); }
@keyframes ripple { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(1.45); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.tk-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.tk-stats div { background: #f9fafb; border-radius: 12px; padding: 10px 12px; }
.tk-stats dt { font-size: .75rem; color: var(--muted); font-weight: 600; }
.tk-stats dd { margin: 2px 0 0; font-weight: 700; }
.tk-pending { font-size: .85rem; margin: 10px 0 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); cursor: pointer; }
.switch-row span { display: grid; gap: 2px; }
.switch-row small { font-size: .8rem; }
.switch { appearance: none; -webkit-appearance: none; flex: none; width: 46px; min-height: 0; height: 28px; padding: 0; border: 0; border-radius: 99px; background: #d1d5db; position: relative; cursor: pointer; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(18px); }
.ios-steps { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.inline-ic { width: 16px; height: 16px; vertical-align: -3px; }
.tk-tips ul { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 6px; font-size: .9rem; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .mainnav a span { display: none; }
  .mainnav a { padding: 9px; }
  .hide-sm { display: none; }
}

@media (max-width: 768px) {
  :root { --topbar: 56px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .brand span { display: none; }
  .mainnav { margin-left: 0; }
  .mainnav a span { display: inline; font-size: .82rem; }
  .mainnav a { padding: 8px 10px; }
  .mainnav a svg { display: none; }
  .page { padding: 18px 16px 40px; }
  .page-head { flex-direction: column; }
  .page-head .btn { width: 100%; }
  .emp-grid { grid-template-columns: 1fr; }

  /* Bottom sheet panel over full-screen map */
  .live { flex-direction: column; }
  .map-wrap { position: absolute; inset: 0; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: 100%; max-height: 78%;
    border-right: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, .15);
    transform: translateY(calc(100% - 152px)); transition: transform .3s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(0); }
  .panel-history { transform: translateY(calc(100% - 200px)); }
  .panel-handle { display: grid; place-items: center; width: 100%; height: 22px; border: 0; background: none; cursor: pointer; flex: none; }
  .panel-handle span { width: 40px; height: 5px; border-radius: 99px; background: #d1d5db; }
  .panel-head { padding-top: 4px; }
  .map-tools { top: 10px; left: 10px; right: 10px; }
  .place-search { flex: 1; }
}

@media (max-width: 380px) {
  .mainnav a { padding: 8px 6px; }
  .stats { gap: 4px; }
  .stat span { font-size: .66rem; }
}
