/* Custom design system -- no Bootstrap CSS loaded (see index.html).
   bootstrap.bundle.min.js stays for Modal/Toast a11y+interaction only;
   every visual class it and app.js reference (btn, card, badge, modal,
   toast, form-*, list-group, grid, utilities) is (re)defined below. */

:root {
  /* Neutral gray/black -- no blue (or any hue) tint mixed into the grays
     themselves, unlike the previous palette. Color only shows up in
     accent/state tokens below. */
  --bg: #0a0a0b;
  --surface: #151516;
  --surface-2: #1c1c1e;
  --surface-3: #252527;
  --border: #333335;
  --border-subtle: #212123;
  --text: #e9e9ea;
  --text-secondary: #8f8f93;
  --text-tertiary: #616164;

  --accent: #2fbd6b;
  --accent-strong: #4ad884;
  --success: #2fbd6b;
  --danger: #e5484d;
  --warning: #e8a23f;
  --info: #4ba3d6;
  --secondary: #6f6f73;
  --dark: #0d0d0e;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 8px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

/* ---- layout / grid ---- */

.container-fluid {
  width: 100%;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  margin: 0 auto;
}
.px-4 {
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}
.pb-4 {
  padding-bottom: 1.5rem;
}
.p-3 {
  padding: 1rem;
}

.row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
}
.row.g-4 {
  gap: 1.5rem;
}
.col-12 {
  grid-column: span 12;
}
.col-md-6 {
  grid-column: span 12;
}
.col-lg-4 {
  grid-column: span 12;
}
@media (min-width: 768px) {
  .col-md-6 {
    grid-column: span 6;
  }
}
@media (min-width: 992px) {
  .col-lg-4 {
    grid-column: span 4;
  }
}

/* ---- utilities used directly in markup ---- */

.d-flex {
  display: flex;
}
.d-grid {
  display: grid;
  gap: 0.6rem;
}
.d-none {
  display: none !important;
}
.align-items-center {
  align-items: center;
}
.align-items-start {
  align-items: flex-start;
}
.justify-content-between {
  justify-content: space-between;
}
.flex-wrap {
  flex-wrap: wrap;
}
.gap-2 {
  gap: 0.5rem;
}
.mb-0 {
  margin-bottom: 0;
}
.mb-4 {
  margin-bottom: 1.5rem;
}
.mt-1 {
  margin-top: 0.35rem;
}
.me-1 {
  margin-right: 0.3rem;
}
.me-2 {
  margin-right: 0.5rem;
}
.ms-3 {
  margin-left: 1rem;
}
.mx-2 {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
}
.m-auto {
  margin: auto;
}
.w-auto {
  width: auto;
}
.top-0 {
  top: 0;
}
.end-0 {
  right: 0;
}
.position-fixed {
  position: fixed;
}
.border-0 {
  border: 0 !important;
}
.bg-transparent {
  background: transparent !important;
}
.small {
  font-size: 0.8125rem;
}
.h5 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}
.fw-semibold {
  font-weight: 600;
}
.font-monospace {
  font-family: var(--font-mono);
}
.text-nowrap {
  white-space: nowrap;
}
.text-secondary {
  color: var(--text-secondary) !important;
}
.text-danger {
  color: var(--danger) !important;
}

/* ---- navbar ---- */

.navbar {
  display: flex;
  align-items: center;
  padding: 0.85rem 0;
  background: linear-gradient(180deg, var(--surface), var(--bg));
  border-bottom: 1px solid var(--border-subtle);
}
.navbar .container-fluid {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.navbar-brand {
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.conn-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.15);
}
.conn-dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(47, 189, 107, 0.18);
  animation: pulse-dot 2.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(47, 189, 107, 0.18);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(47, 189, 107, 0.08);
  }
}

/* ---- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card.shadow-sm:hover {
  border-color: #45454a;
  box-shadow: var(--shadow);
}
.card-header {
  padding: 0.85rem 1.1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  font-weight: 600;
}
.card-body {
  padding: 0.85rem 1.1rem;
}

#log-collapse-btn {
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* Site-direction color cue on the device cards -- data-direction is set
   explicitly by app.js (renderGroupCard/renderGateCard), not inferred from
   badge classes, so a "stale" badge (also text-bg-warning) never collides
   with it. Subtle full-ring tint, not a thick strip -- reads as a status
   frame rather than a decoration. */
#devices .card[data-direction="outbound"] {
  border-color: rgba(47, 189, 107, 0.55);
}
#devices .card[data-direction="inbound"] {
  border-color: rgba(75, 163, 214, 0.55);
}
#devices .card[data-direction="gate"] {
  border-color: rgba(232, 162, 63, 0.55);
}

/* height (not max-height) + resize: vertical -- a max-height would cap how
   far the user could drag this open, defeating the point. height is just
   the starting size; min-height stops it collapsing to nothing. */
.log-body {
  height: 480px;
  min-height: 150px;
  overflow-y: auto;
  resize: vertical;
}

/* Device cards feel tall with everything they now show (status fields,
   Success/Fail, Auto toggle, Pickup Timeout input) -- let the user drag the
   bottom-right corner to shrink/grow one, native browser resize handle.
   overflow: auto (not visible) is required for `resize` to take effect at
   all, and gives a scrollbar once shrunk below the content's natural
   height. Vertical-only -- width stays under the grid column, horizontal
   resize would fight that layout. */
#devices .card {
  resize: vertical;
  overflow: auto;
  min-height: 160px;
}

/* Collapsed (g.collapsed in app.js) drops the whole detailsHtml block, but
   render() still reapplies any manually-dragged/persisted inline height to
   every card unconditionally -- without this override the container kept
   its old tall height with nothing left to fill it. !important beats that
   inline style; resize:none because there's nothing left to drag either. */
#devices .card.is-collapsed {
  height: auto !important;
  min-height: 0;
  resize: none;
}

/* ---- badges ---- */

.badge {
  display: inline-block;
  padding: 0.28em 0.55em;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.3;
}
.text-bg-primary {
  background: rgba(47, 189, 107, 0.16);
  color: var(--accent-strong);
}
.text-bg-info {
  background: rgba(75, 163, 214, 0.16);
  color: var(--info);
}
.text-bg-success {
  background: rgba(47, 189, 107, 0.16);
  color: var(--success);
}
.text-bg-danger {
  background: rgba(229, 72, 77, 0.16);
  color: var(--danger);
}
.text-bg-warning {
  background: rgba(232, 162, 63, 0.18);
  color: var(--warning);
}
.text-bg-secondary {
  background: var(--surface-3);
  color: var(--text-secondary);
}
.text-bg-dark {
  background: var(--dark);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.badge.border {
  border: 1px solid var(--border) !important;
}

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
  background: var(--surface-3);
  color: var(--text);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}
.btn-success {
  background: var(--success);
  color: #06251b;
}
.btn-success:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn-warning {
  background: var(--warning);
  color: #2b1c00;
}
.btn-warning:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-outline-secondary,
.btn-outline-danger,
.btn-outline-warning,
.btn-outline-light {
  background: transparent;
}
.btn-outline-secondary {
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-outline-secondary:hover:not(:disabled) {
  border-color: var(--text-secondary);
  color: var(--text);
}
.btn-outline-secondary.active {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--text);
}
.btn-outline-danger {
  border-color: rgba(229, 72, 77, 0.4);
  color: var(--danger);
}
.btn-outline-danger:hover:not(:disabled) {
  background: rgba(229, 72, 77, 0.12);
  border-color: var(--danger);
}
.btn-outline-warning {
  border-color: rgba(232, 162, 63, 0.5);
  color: var(--warning);
}
.btn-outline-warning:hover:not(:disabled) {
  background: rgba(232, 162, 63, 0.12);
}
.btn-outline-light {
  border-color: var(--border);
  color: var(--text-secondary);
  padding: 0.15rem 0.45rem;
}
.btn-outline-light:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-secondary);
}

.btn-group {
  display: inline-flex;
}
.btn-group .btn {
  border-radius: 0;
}
.btn-group .btn:first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
}
.btn-group .btn:last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}
.btn-group .btn:not(:first-child) {
  margin-left: -1px;
}
.btn-group-sm > .btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-close {
  width: 0.9rem;
  height: 0.9rem;
  padding: 0;
  border: 0;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%238f8f93'%3E%3Cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3E%3C/svg%3E") center/0.7rem no-repeat;
  cursor: pointer;
  opacity: 0.75;
}
.btn-close:hover {
  opacity: 1;
}
.btn-close.btn-close-white {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3E%3Cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3E%3C/svg%3E") center/0.7rem no-repeat;
}

/* ---- forms ---- */

.form-control,
.form-select {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control::placeholder {
  color: var(--text-tertiary);
}
.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 189, 107, 0.18);
}
.form-select-sm {
  padding: 0.3rem 1.6rem 0.3rem 0.55rem;
  font-size: 0.8125rem;
}
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%238f8f93'%3E%3Cpath d='M8 11 3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 0.7rem;
  padding-right: 1.7rem;
  cursor: pointer;
}
.form-text {
  font-size: 0.8rem;
  margin-top: 0.35rem;
}

.input-group {
  display: flex;
  align-items: stretch;
}
.input-group > .form-control {
  flex: 1;
  border-radius: 0;
}
.input-group-text {
  display: flex;
  align-items: center;
  padding: 0 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-right: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
  white-space: nowrap;
}
.input-group > .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.input-group-sm .form-control,
.input-group-sm .input-group-text,
.input-group-sm .btn {
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  font-size: 0.8rem;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.form-check-label {
  color: var(--text-secondary);
  cursor: pointer;
}
.form-check.form-switch .form-check-input {
  appearance: none;
  width: 2.15rem;
  height: 1.2rem;
  margin: 0;
  border-radius: 2rem;
  border: 1px solid var(--border);
  background-color: var(--surface-3);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='6' cy='8' r='4.5' fill='%23616164'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left center;
  background-size: contain;
  cursor: pointer;
  transition: background-color 0.15s ease, background-position 0.15s ease;
}
.form-check.form-switch .form-check-input:checked {
  background-color: var(--accent);
  background-position: right center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='10' cy='8' r='4.5' fill='white'/%3E%3C/svg%3E");
}
.form-check-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- list group (device card detail rows) ---- */

.list-group {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-group-flush {
  border-top: 1px solid var(--border-subtle);
}
.list-group-item {
  padding: 0.4rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.875rem;
}
.list-group-item:last-child {
  border-bottom: none;
}

/* ---- event log ---- */

.log-entry {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.log-entry:last-child {
  border-bottom: none;
}
.log-entry-error {
  background: rgba(229, 72, 77, 0.06);
  border-left: 2px solid var(--danger);
}

.log-entry .font-monospace {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}

/* ---- toast ---- */

.toast-container {
  /* Drops it below the navbar (site dropdown lives there) instead of
     overlapping it at the very top of the viewport. */
  top: 4.25rem;
  z-index: 1080;
}
.toast {
  position: relative;
  display: none;
  width: 350px;
  max-width: 350px;
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 1;
  transition: opacity 0.15s linear;
  margin-bottom: 0.5rem;
}
.toast.showing {
  opacity: 0;
}
.toast.show {
  display: block;
}
.toast-body {
  padding: 0.75rem 2rem 0.75rem 0.9rem;
  font-size: 0.875rem;
}
/* Pinned to the toast's own top-right corner instead of centered in the
   flex row -- centering made its position swing with body height (a
   one-line vs. wrapped title), which read as inconsistent across toasts. */
.toast .btn-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
}
.text-bg-danger.toast {
  background: #3a1518;
  color: #ffd9da;
  border: 1px solid rgba(229, 72, 77, 0.35);
}
.text-bg-warning.toast {
  background: #3a2c0f;
  color: #ffe6b3;
  border: 1px solid rgba(232, 162, 63, 0.35);
}

/* ---- modal ---- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1055;
  display: none;
  outline: 0;
}
.modal.show {
  display: block;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1050;
  background: rgba(4, 6, 10, 0.65);
  opacity: 0;
  transition: opacity 0.15s linear;
}
.modal-backdrop.show {
  opacity: 1;
}
.modal-dialog {
  margin: 1.75rem auto;
  max-width: 500px;
  transform: translateY(-20px);
  transition: transform 0.2s ease-out;
}
.modal.show .modal-dialog {
  transform: none;
}
.modal-dialog-centered {
  display: flex;
  align-items: center;
  min-height: calc(100% - 3.5rem);
}
.modal-sm {
  max-width: 340px;
}
.modal-content {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.modal-body {
  padding: 1.1rem;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
}
