/* KLM UFP Pilot dashboard - mobile-first, big touch targets,
   KLM blue (#005AAA) as the brand accent. */

:root {
  --klm-blue: #005AAA;
  --klm-blue-deep: #003F77;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #15181c;
  --muted: #6c757d;
  --border: #e3e6ea;
  --danger: #D43A3A;
  --warn: #E2A53E;
  --ok: #21A352;
  --zone-color: var(--muted);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  font: inherit;
  cursor: pointer;
}

/* --- Top bar ---------------------------------------------------------- */

.topbar {
  background: var(--klm-blue);
  color: white;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-actions button {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  min-height: 44px;
  font-weight: 500;
}
.topbar-actions button:hover { background: rgba(255,255,255,0.22); }
.topbar-actions button.ghost {
  background: transparent;
}
.topbar-actions button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
.topbar-actions #find-id {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  min-height: 44px;
  width: 200px;
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
}
.topbar-actions #find-id::placeholder { color: rgba(255,255,255,0.55); }
.topbar-actions #find-id:focus { outline: 2px solid rgba(255,255,255,0.6); }

/* --- Main grid -------------------------------------------------------- */

main {
  flex: 1;
  padding: 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

#empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  background: var(--card);
  border-radius: 12px;
  border: 1px dashed var(--border);
}
#empty-state p { margin: 8px 0; }
#empty-state code {
  background: #eef0f3;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

#bracelets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* --- Cards ------------------------------------------------------------ */

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-left: 4px solid var(--zone-color);
  transition: opacity 0.15s, box-shadow 0.4s;
}
.card.dim {
  opacity: 0.3;
}
.card.highlighted {
  box-shadow: 0 0 0 3px var(--klm-blue), 0 4px 16px rgba(0,90,170,0.25);
  animation: card-pulse 1.6s ease-out 2;
}
@keyframes card-pulse {
  0%   { box-shadow: 0 0 0 3px var(--klm-blue), 0 0 0 12px rgba(0,90,170,0.0); }
  40%  { box-shadow: 0 0 0 3px var(--klm-blue), 0 0 0 12px rgba(0,90,170,0.25); }
  100% { box-shadow: 0 0 0 3px var(--klm-blue), 0 0 0 12px rgba(0,90,170,0.0); }
}

.card-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.card-header .name {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  outline: none;
  border-radius: 4px;
  padding: 2px 4px;
}
.card-header .name:focus {
  background: #f0f3f7;
  outline: 2px solid var(--klm-blue);
}
.card-header .battery {
  font-size: 13px;
  color: var(--muted);
}
.card-header .bracelet-id {
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
  font-size: 12px;
  color: var(--muted);
  background: #f0f3f7;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}
.card-header .offline {
  font-size: 11px;
  background: var(--danger);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.card-header .remove {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
}
.card-header .remove:hover {
  background: #f0f3f7;
  color: var(--danger);
}

/* Level row */
.level-row {
  display: grid;
  grid-template-columns: 90px 1fr 40px;
  align-items: center;
  gap: 10px;
}
.zone-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--zone-color);
  letter-spacing: 0.5px;
}
.level-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, var(--ok) 0%, var(--warn) 50%, var(--danger) 100%);
  border-radius: 3px;
  outline: none;
}
.level-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: white;
  border: 3px solid var(--zone-color);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.level-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: white;
  border: 3px solid var(--zone-color);
  border-radius: 50%;
  cursor: pointer;
}
.level-value {
  font-size: 22px;
  font-weight: 700;
  text-align: right;
  color: var(--zone-color);
}

/* Mode row */
.mode-row {
  display: grid;
  grid-template-columns: 60px 1fr 1fr;
  align-items: center;
  gap: 8px;
}
.mode-row .label {
  font-size: 13px;
  color: var(--muted);
}
.mode-btn {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
}
.mode-btn.active {
  background: var(--klm-blue);
  color: white;
  border-color: var(--klm-blue);
}
.mode-btn[data-mode="TRIL"].active {
  background: var(--warn);
  border-color: var(--warn);
  color: white;
}

/* Action buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.action {
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
}
.action.vibrate {
  background: var(--warn);
  color: white;
}
.action.alert {
  background: var(--danger);
  color: white;
}

/* --- Status bar ------------------------------------------------------- */

.status-bar {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--muted);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
#conn-status { font-weight: 600; }
#api-base { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* --- Small screens ---------------------------------------------------- */
@media (max-width: 480px) {
  .topbar { padding: 12px; }
  .brand h1 { font-size: 16px; }
  main { padding: 12px; }
  #bracelets { grid-template-columns: 1fr; }
}
