* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #f0f2f5; font-family: Roboto, Helvetica, Arial, sans-serif; color: #333; margin: 0; min-height: 100vh; position: relative; padding-bottom: 56px; }
nav {
  background: #1a1a2e; display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px; height: 56px;
}
nav .nav-brand { color: #fff; font-size: 17px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; }
nav ul { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; }
nav ul li a {
  color: rgba(255,255,255,0.75); text-decoration: none; font-size: 13px;
  padding: 8px 12px; border-radius: 6px; display: block; white-space: nowrap;
  transition: background .15s, color .15s;
}
nav ul li a:hover { background: rgba(255,255,255,0.1); color: #fff; }
nav ul li a.active { background: rgba(255,255,255,0.15); color: #fff; font-weight: 600; }
.page-wrap { padding: 24px; }
.user-pill {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  font-size: 13px; color: rgba(255,255,255,0.85);
}
.user-pill img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.user-pill button {
  margin-left: 8px; background: none; border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.85); cursor: pointer; font-size: 12px;
  font-weight: 600; padding: 4px 10px; border-radius: 4px;
}
.user-pill button:hover { background: rgba(255,255,255,0.1); }
.top-row { display: flex; gap: 16px; align-items: stretch; margin-bottom: 32px; }
.card { background: #fff; border-radius: 8px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); min-width: 180px; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #888; margin-bottom: 8px; }
.card .value { font-size: 28px; font-weight: 600; color: #1a1a2e; }
.card .sub { font-size: 12px; color: #aaa; margin-top: 4px; }
.search-bar { display: flex; gap: 10px; align-items: center; }
.search-bar input {
  padding: 9px 14px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; width: 280px; outline: none; transition: border-color .2s;
}
.search-bar input:focus { border-color: #4285f4; }
.search-bar button {
  padding: 9px 20px; background: #1a1a2e; color: #fff; border: none;
  border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity .2s;
}
.search-bar button:hover { opacity: .85; }
.btn-clear {
  padding: 9px 16px; background: none; color: #888;
  border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
  cursor: pointer; transition: background .15s, color .15s;
}
.btn-clear:hover { background: #f0f2f5; color: #333; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
th, td { text-align: left; padding: 12px 16px; font-size: 14px; }
th { background: #f7f8fa; color: #888; font-weight: 600; text-transform: uppercase; font-size: 12px; }
tr:not(:last-child) td { border-bottom: 1px solid #f0f2f5; }
#facility-results { display: none; }
#status { margin-top: 16px; font-size: 13px; color: #888; }
#error { margin-top: 16px; font-size: 13px; color: #c62828; }
#main { display: none; }

/* Integrations section */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 { font-size: 16px; color: #1a1a2e; font-weight: 600; }
.btn-refresh {
  padding: 7px 16px; background: #fff; color: #1a1a2e;
  border: 1px solid #ddd; border-radius: 6px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: background .15s;
  display: flex; align-items: center; gap: 6px;
}
.btn-refresh:hover { background: #f0f2f5; }
.btn-refresh:disabled { opacity: .55; cursor: default; }
.btn-export {
  padding: 7px 16px; background: #fff; color: #1a7a4a;
  border: 1px solid #b2dfcb; border-radius: 6px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: background .15s;
  display: flex; align-items: center; gap: 6px;
}
.btn-export:hover { background: #f0faf4; }
.btn-export:disabled { opacity: .55; cursor: default; }
.integrations-wrap { overflow-x: auto; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
#integrations-table th:first-child, #integrations-table td:first-child { width: 110px; }
#scroll-sentinel { height: 1px; }
.integrations-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.integrations-toolbar input {
  padding: 7px 12px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 13px; width: 200px; outline: none; transition: border-color .2s;
}
.integrations-toolbar input:focus { border-color: #4285f4; }
.btn-filter {
  padding: 7px 16px; background: #1a1a2e; color: #fff;
  border: none; border-radius: 6px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: opacity .2s;
}
.btn-filter:hover { opacity: .85; }
.filter-count { font-size: 13px; color: #888; }
#integrations-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
#integrations-table th.sortable:hover { color: #1a1a2e; }
#integrations-table th.sort-asc::after  { content: ' \25B4'; }
#integrations-table th.sort-desc::after { content: ' \25BE'; }
.app-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; background: #e3f2fd; color: #1565c0;
  margin: 2px 2px 2px 0; white-space: nowrap;
}
.config-block {
  font-family: monospace; font-size: 11px; background: #f7f8fa;
  border-radius: 4px; padding: 4px 8px; display: inline-block;
  color: #333; white-space: pre; max-width: 360px; overflow: auto;
}
#integrations-error { margin-top: 12px; font-size: 13px; color: #c62828; }
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(3px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 9999;
}
#loading-overlay.hidden { display: none; }
.overlay-spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 5px solid #e0e0e0;
  border-top-color: #1a1a2e;
  animation: spin .75s linear infinite;
}
#loading-overlay p {
  font-size: 15px; font-weight: 600; color: #1a1a2e; letter-spacing: .2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── New Integration form ───────────────────────────────── */
.setup-container { max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.setup-form { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; font-weight: 600; color: #555; }
.form-group .required { color: #c62828; margin-left: 2px; }
.form-group input {
  padding: 9px 14px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; outline: none; transition: border-color .2s;
  /* remove spinner arrows from number input */
  -moz-appearance: textfield;
}
.form-group input[type=number]::-webkit-inner-spin-button,
.form-group input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.form-group input:focus { border-color: #4285f4; }
.form-group input.input-error { border-color: #c62828; }
.field-error { font-size: 12px; color: #c62828; min-height: 16px; margin: 0; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.form-actions button {
  padding: 9px 20px; background: #1a1a2e; color: #fff; border: none;
  border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity .2s;
}
.form-actions button:hover { opacity: .85; }
.form-actions button:disabled { opacity: .55; cursor: default; }
.btn-danger {
  padding: 9px 20px; background: #c62828; color: #fff; border: none;
  border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity .2s;
}
.btn-danger:hover { opacity: .85; }
.btn-danger:disabled { opacity: .55; cursor: default; }
.setup-panel-warn { border: 1px solid #f9a825; }
.setup-panel-success { border: 1px solid #43a047; }
.panel-title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.panel-title.warn { color: #e65100; }
.panel-title.success { color: #2e7d32; }
.panel-desc { font-size: 13px; color: #555; margin-bottom: 12px; }
.panel-table-wrap { overflow-x: auto; border-radius: 6px; }
#setup-error { font-size: 13px; color: #c62828; min-height: 16px; }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  width: 100%; padding: 16px 24px; height: 56px;
  position: absolute; bottom: 0; background-color: #1a1a2e;
  text-align: center; font-size: 12px; color: rgba(255,255,255,0.6);
  display: flex; align-items: center; justify-content: center;
}
.site-footer a { color: rgba(255,255,255,0.6); text-decoration: underline; }
.site-footer a:hover { color: #fff; }

/* ── Go to top button ──────────────────────────────────── */
#btn-go-top {
  display: flex; align-items: center; justify-content: center;
  position: fixed; bottom: 72px; right: 24px;
  width: 44px; height: 44px; border-radius: 50%;
  background: #1a1a2e; color: #fff; font-size: 24px; line-height: 1;
  border: none; cursor: pointer; z-index: 9998;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#btn-go-top.visible { opacity: 1; pointer-events: auto; }

/* ── Delete button ──────────────────────────────────────── */
.btn-delete-integration {
  padding: 5px 12px; background: none; color: #c62828;
  border: 1px solid #c62828; border-radius: 6px; font-size: 12px;
  font-weight: 600; cursor: pointer; transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-delete-integration:hover { background: #c62828; color: #fff; }
.btn-delete-integration:disabled { opacity: .5; cursor: default; }

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: #1a1a2e; color: #fff; font-size: 14px; font-weight: 500;
  padding: 12px 24px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 10000; white-space: nowrap;
  animation: toast-in .2s ease;
}
.toast.hidden { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Confirm modal ──────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 10001;
}
.modal-backdrop.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 10px; padding: 28px 28px 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18); max-width: 420px; width: 90%;
}
.modal-title { font-size: 16px; font-weight: 700; color: #1a1a2e; margin-bottom: 10px; }
.modal-body { font-size: 14px; color: #555; line-height: 1.6; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Hamburger button (hidden on desktop) ───────────────── */
.nav-hamburger {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 36px; height: 36px; padding: 4px;
  background: none; border: none; cursor: pointer; flex-shrink: 0;
}
.nav-hamburger span {
  display: block; width: 22px; height: 2px;
  background: rgba(255,255,255,0.85); border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
/* Hide mobile-only user row in menu by default */
.nav-menu-user-row { display: none; }

/* ── Mobile responsiveness ──────────────────────────────── */
@media (max-width: 640px) {
  /* Nav */
  nav {
    height: auto;
    flex-wrap: wrap;
    padding: 0 16px;
    gap: 0;
    position: relative;
  }
  nav .nav-brand { padding: 14px 0; }
  .nav-hamburger { display: flex; margin-left: auto; }
  .user-pill { display: none; } /* replaced by in-menu row on mobile */

  /* Dropdown menu */
  nav ul#nav-menu {
    display: none;
    flex-direction: column;
    width: 100%;
    background: #1a1a2e;
    padding: 8px 0 12px;
    gap: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  nav ul#nav-menu.nav-menu-open { display: flex; }
  nav ul#nav-menu li a {
    padding: 12px 16px;
    font-size: 15px;
    border-radius: 0;
    display: block;
  }
  .nav-menu-user-row {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.1);
    margin-top: 4px; font-size: 13px; color: rgba(255,255,255,0.85);
  }
  .nav-menu-user-row img {
    width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
  }
  .nav-menu-user-row span { flex: 1; }
  .nav-menu-user-row button {
    background: none; border: 1px solid rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.85); cursor: pointer; font-size: 12px;
    font-weight: 600; padding: 4px 10px; border-radius: 4px;
  }

  /* Page padding */
  .page-wrap { padding: 12px; }

  /* Search bar */
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar input { width: 100%; }
  .search-bar button, .search-bar .btn-clear { width: 100%; }

  /* Section header */
  .section-header { flex-direction: column; align-items: center; gap: 10px; text-align: center; }

  /* Integrations toolbar */
  .integrations-toolbar { flex-direction: column; align-items: stretch; width: 100%; }
  .integrations-toolbar input { width: 100%; text-align: center; }
  .btn-filter, .btn-refresh { width: 100%; justify-content: center; }
  .filter-count { text-align: center; }

  /* Tables — card layout */
  .integrations-wrap, #facility-results { overflow-x: unset; }
  table, thead, tbody, th, tr { display: block; }
  table { min-width: unset; box-shadow: none; background: transparent; border-radius: 0; }
  thead { display: none; }
  tr {
    background: #fff; border-radius: 8px; margin-bottom: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1); overflow: hidden;
  }
  td {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 14px; font-size: 13px;
    border-bottom: 1px solid #f0f2f5;
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    color: #888; letter-spacing: .4px; min-width: 110px; flex-shrink: 0; padding-top: 1px;
  }

  /* Config block */
  .config-block { max-width: 100%; font-size: 10px; }

  /* Toast */
  .toast { white-space: normal; text-align: center; width: 90%; left: 5%; transform: none; bottom: 70px; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

  /* Setup form */
  .form-actions { flex-direction: column; }
  .form-actions button, .btn-danger, .btn-clear { width: 100%; }

  /* Top row cards */
  .top-row { flex-direction: column; }

  /* Home card centering */
  #page-home > div { padding: 8px !important; }

  /* Search results width matches viewport */
  #facility-results { width: 100%; max-width: 100%; }
}
