/* ══════════════════════════════════════════════════════════
   TAPIR · components.css
   Reusable UI components
   ══════════════════════════════════════════════════════════ */

/* ── Button base ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--tr), border-color var(--tr), box-shadow var(--tr), transform var(--tr-fast);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent); color: var(--bg);
  border-color: var(--accent);
}
.btn-primary:hover { box-shadow: 0 0 16px var(--accent-glow); }

.btn-ghost {
  background: transparent; color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: var(--border-hi); }

.btn-danger {
  background: rgba(239,68,68,.1); color: var(--red);
  border-color: rgba(239,68,68,.25);
}
.btn-danger:hover { background: rgba(239,68,68,.18); }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--r-sm);
}
.btn-icon-round { border-radius: 50%; }

.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-lg { padding: 11px 20px; font-size: 13px; }

/* ── FAB (Floating Action Button) ── */
.fab {
  position: relative;   /* bukan absolute: harus ikut alur flex di .fab-cluster */
  flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform var(--tr), box-shadow var(--tr);
  box-shadow: var(--shadow-float);
  border: 1px solid var(--border-hi);
  z-index: 400;
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(.94); }
.fab-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.fab-surface { background: var(--surface2); color: var(--accent); }

/* ── Toggle switch ── */
.tog { position: relative; display: inline-flex; cursor: pointer; flex-shrink: 0; }
.tog input { opacity: 0; width: 0; height: 0; position: absolute; }
.tog-track {
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--border-hi);
  transition: background var(--tr);
  position: relative;
}
.tog-track::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px;
  transition: transform var(--tr);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.tog input:checked ~ .tog-track { background: var(--accent); }
.tog input:checked ~ .tog-track::after { transform: translateX(16px); }

/* ── Panel (slide dari bawah) ── */
.panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 600;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-panel);
  transform: translateY(100%);
  transition: transform var(--tr-slow);
  display: flex; flex-direction: column;
  max-height: 88dvh;
  will-change: transform;
}
.panel.open { transform: translateY(0); }

.panel-pill {
  width: 36px; height: 3px;
  background: var(--border-hi);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 13px; font-weight: 600; }

.panel-body {
  flex: 1; overflow-y: auto;
  padding-bottom: calc(var(--safe-b) + 12px);
  overscroll-behavior: contain;
}

/* ── Scrim ── */
.scrim {
  position: fixed; inset: 0;
  z-index: 590;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--tr);
}
.scrim.open { opacity: 1; pointer-events: auto; }

/* ── Drawer (slide dari kiri) ── */
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 700;
  width: min(300px, 85vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform var(--tr-slow);
  display: flex; flex-direction: column;
  will-change: transform;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 6px 0 calc(var(--safe-b) + 16px);
}

/* ── Drawer section ── */
.ds { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.ds:last-child { border-bottom: none; }
.ds-label {
  font-size: 9px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted-hi);
  margin-bottom: 8px;
}
.ds-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; gap: 8px;
}
.ds-row-label { font-size: 11.5px; color: var(--text); flex: 1; min-width: 0; }
.ds-hint { font-size: 10px; color: var(--muted-hi); margin-top: 3px; }

/* ── Form controls ── */
.field-group { margin-bottom: 8px; }
.field-label {
  font-size: 10px; color: var(--muted-hi); font-weight: 500;
  margin-bottom: 4px; display: block;
}
.field-input {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text);
  font-family: var(--sans); font-size: 12px;
  padding: 7px 10px;
  transition: border-color var(--tr);
}
.field-input:focus { outline: none; border-color: var(--accent); }
.field-input::placeholder { color: var(--muted-hi); }

.field-select {
  appearance: none;
  background: var(--surface2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234d6a84' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text);
  font-family: var(--sans); font-size: 12px;
  padding: 7px 28px 7px 10px;
  transition: border-color var(--tr); cursor: pointer;
}
.field-select:focus { outline: none; border-color: var(--accent); }

.field-row {
  display: flex; gap: 8px; align-items: center;
}
.field-row .field-label-inline {
  font-size: 11px; color: var(--text-dim); flex-shrink: 0; width: 80px;
}
.field-row .field-input,
.field-row .field-select { flex: 1; }

/* ── Search field ── */
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 10px;
  transition: border-color var(--tr);
}
.search-wrap:focus-within { border-color: var(--accent); }
.search-wrap svg { color: var(--muted-hi); flex-shrink: 0; }
.search-wrap input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--sans); font-size: 12px;
}
.search-wrap input::placeholder { color: var(--muted-hi); }

/* ── Autocomplete dropdown ── */
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border-hi);
  border-radius: var(--r-sm); box-shadow: var(--shadow-md);
  max-height: 220px; overflow-y: auto;
  display: none;
}
.ac-dropdown.open { display: block; }
.ac-item {
  padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--tr-fast);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.focused { background: var(--surface2); }
.ac-item-name { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ac-item-detail { font-size: 10px; color: var(--muted-hi); margin-top: 2px; }
.ac-item-freq { color: var(--accent); font-family: var(--mono); }
.ac-empty { padding: 12px; text-align: center; font-size: 11px; color: var(--muted-hi); }

/* ── Service badge ── */
.svc-badge {
  display: inline-block;
  font-family: var(--mono); font-size: 8px; font-weight: 700;
  border: 1px solid currentColor; border-radius: var(--r-xs);
  padding: 1px 4px; opacity: .85; flex-shrink: 0;
}

/* ── Stat chip ── */
.stat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px;
  font-family: var(--mono); font-size: 10px;
}
.stat-chip-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  box-shadow: 0 0 5px var(--accent-glow);
}
.stat-chip-val { font-weight: 700; color: var(--accent); }
.stat-chip-lbl { color: var(--muted-hi); }

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-item {
  flex: 1; padding: 8px 6px 9px;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  color: var(--muted-hi); cursor: pointer;
  transition: color var(--tr), border-color var(--tr);
}
.tab-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count {
  font-family: var(--mono); font-size: 9px;
  background: var(--surface2); border-radius: 8px;
  padding: 1px 5px; margin-left: 3px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--surface2); border: 1px solid var(--border-hi);
  border-radius: var(--r-sm); padding: 9px 16px;
  font-size: 11px; white-space: nowrap;
  box-shadow: var(--shadow-float);
  z-index: 900; opacity: 0; pointer-events: none;
  transition: opacity var(--tr), transform var(--tr);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok   { border-color: rgba(0,229,255,.3); color: var(--accent); }
.toast.warn { border-color: rgba(234,179,8,.3);  color: var(--yellow); }
.toast.err  { border-color: rgba(239,68,68,.3);  color: var(--red); }

/* ── Tag / chip list ── */
.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-family: var(--mono); font-size: 9px; font-weight: 700;
  border: 1px solid currentColor; border-radius: var(--r-xs);
  padding: 2px 7px;
}
.chip-ok   { color: var(--green);  border-color: rgba(34,197,94,.3);  background: rgba(34,197,94,.07);  }
.chip-warn { color: var(--yellow); border-color: rgba(234,179,8,.3);  background: rgba(234,179,8,.07);  }
.chip-err  { color: var(--red);    border-color: rgba(239,68,68,.3);  background: rgba(239,68,68,.07);  }
.chip-info { color: var(--accent); border-color: rgba(0,229,255,.3);  background: rgba(0,229,255,.07);  }

/* ── Divider ── */
.divider { height: 1px; background: var(--border); margin: 8px 0; }

/* ── Loading skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-xs);
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Leaflet overrides ── */
.leaflet-control-attribution {
  font-size: 8px !important; opacity: .4 !important;
  background: transparent !important;
  color: var(--muted-hi) !important;
}
.leaflet-control-attribution a { color: var(--muted-hi) !important; }
.tapir-tip {
  background: var(--surface) !important; border: 1px solid var(--border-hi) !important;
  color: var(--text) !important; font-size: 11px !important;
  border-radius: var(--r-xs) !important; padding: 4px 8px !important;
  box-shadow: var(--shadow-md) !important;
}
