* { box-sizing: border-box; }

:root {
  /* #loadingScreen/#grid/#mapContainer/.screen/#siteViewer all size themselves
     off this rather than a hardcoded pixel value, so the header only needs
     resizing in one place. Sized up ~12.5% from the original 48px for easier
     reading/tapping (first tried +50%, dialed back 25% as too big) - same on
     both the admin and customer views. */
  --topbar-height: 54px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #14181d;
  color: #e6e9ec;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

#topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: #1c2128;
  border-bottom: 1px solid #2a303a;
}

#title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.topbar-logo { height: 29px; width: auto; flex-shrink: 0; }

#summary {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: #9aa4af;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: #c3cad3;
  background: #20262e;
  padding: 4px 11px;
  border-radius: 11px;
  white-space: nowrap;
}
.status-pill.total { color: #8b95a1; background: transparent; padding: 4px 0; }

button {
  background: #2a303a;
  color: #e6e9ec;
  border: 1px solid #3a4250;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
button:hover { background: #343c48; }
button.primary { background: #2f6fe0; border-color: #3f7bf0; }
button.primary:hover { background: #3a7bf0; }
button.danger { background: transparent; border-color: #5a2a2a; color: #ff8080; }
button.danger:hover { background: #3a2020; }
.hidden { display: none !important; }

/* A styled link that should look like button.primary - for cases like the
   report download action, which is a plain <a href> (so the file downloads/
   opens normally) rather than a <button>, but should carry the same visual
   weight as the other primary actions on the page. */
a.btn-primary {
  display: inline-block;
  background: #2f6fe0;
  color: #e6e9ec;
  border: 1px solid #3f7bf0;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
a.btn-primary:hover { background: #3a7bf0; }

.nav-group { display: flex; gap: 9px; }
.nav-btn.active { background: #2f6fe0; border-color: #3f7bf0; }

/* Header buttons only (Back/nav/Refresh/Sign out/+Add site) sized up to match
   the rest of the header - scoped to #topbar so modal and table buttons
   elsewhere aren't affected. */
#topbar button { font-size: 14px; padding: 7px 14px; }

#loadingScreen {
  position: fixed;
  inset: var(--topbar-height) 0 0 0;
  background: #14181d;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #9aa4af;
  font-size: 13px;
  z-index: 5;
}
#loadingScreen.hidden { display: none !important; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #2a303a;
  border-top-color: #2f6fe0;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.screen {
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 20px 24px;
}
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.screen-header h2 { margin: 0; font-size: 16px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal-box {
  background: #1c2128;
  border: 1px solid #3a4250;
  border-radius: 10px;
  padding: 20px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-wide { width: 460px; max-height: 80vh; overflow-y: auto; }

.modal-box h3 { margin: 0; font-size: 15px; }

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #9aa4af;
}

.modal-box input, .modal-box select, .modal-box textarea {
  background: #14181d;
  border: 1px solid #3a4250;
  border-radius: 6px;
  color: #e6e9ec;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
}
.modal-box input:focus, .modal-box select:focus, .modal-box textarea:focus {
  outline: none;
  border-color: #4a90e2;
}

.modal-row { display: flex; gap: 10px; align-items: flex-end; }
.modal-row label { flex: 1; min-width: 0; }
.modal-row select { flex: 1; }
.modal-row button { flex-shrink: 0; }

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
}
.checkbox-row input { width: auto; }

.modal-error { color: #ff8080; font-size: 12px; }

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.modal-actions-right { display: flex; gap: 8px; }

.grid-toolbar {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: #14181d;
  border-bottom: 1px solid #2a303a;
}
.grid-toolbar input,
.grid-toolbar select {
  background: #1c2128;
  border: 1px solid #3a4250;
  border-radius: 6px;
  color: #e6e9ec;
  padding: 5px 8px;
  font-size: 12px;
}
.grid-toolbar input { flex: 1; max-width: 280px; }

#grid {
  height: calc(100vh - var(--topbar-height) - 40px);
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  align-content: start;
}

.card {
  background: #1c2128;
  border: 1px solid #2a303a;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: #4a5568; transform: translateY(-1px); }
.card:focus-visible, table tbody tr:focus-visible {
  outline: 2px solid #4a90e2;
  outline-offset: -2px;
}

.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; flex-shrink: 0; }
.dot.online { background: #3fd97f; box-shadow: 0 0 6px #3fd97f88; }
.dot.down { background: #ff5c5c; box-shadow: 0 0 6px #ff5c5c88; }
.dot.unconfirmed { background: #f5c542; box-shadow: 0 0 6px #f5c54288; animation: pulse 1.4s ease-in-out infinite; }
.dot.pending { background: #6b7280; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.monitor-id { font-size: 11px; color: #8b95a1; }
.uptime { margin-left: auto; font-size: 10px; color: #8b95a1; }

.edit-btn {
  background: transparent;
  border: none;
  color: #8b95a1;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  margin-left: auto;
}
.edit-btn:hover { color: #e6e9ec; background: transparent; }

.primary-line { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ip-sub { font-size: 11px; color: #8b95a1; margin-bottom: 2px; }
.dust-reading { font-size: 11px; color: #e6b34d; margin-bottom: 4px; }

.meta {
  font-size: 11px;
  color: #8b95a1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.meta span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.meta .status.online { color: #3fd97f; }
.meta .status.down { color: #ff5c5c; font-weight: 600; }
.meta .status.unconfirmed { color: #f5c542; }
.meta .status.pending { color: #8b95a1; }

.card.down { border-color: #4a2a2a; }
.card.unconfirmed { border-color: #4a3f1f; }

#mapContainer { height: calc(100vh - var(--topbar-height)); background: #0d1013; }

.marker-dot {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #14181d;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
}

/* Wind barb overlay */
.wind-barb {
  pointer-events: none;
  transform-origin: center;
}
.wind-barb .arrow { stroke: #7fd0ff; }

/* Leaflet permanent tooltip used for the site name/number label (replaces the
   old hand-positioned .marker-label div) - only shown past MARKER_LABEL_MIN_ZOOM
   in shared.js, so labels don't overlap at the default full-fleet zoom. */
.leaflet-tooltip.site-tooltip {
  background: rgba(20, 24, 29, 0.85);
  border: none;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.leaflet-tooltip.site-tooltip::before { display: none; }

.leaflet-popup-content-wrapper {
  background: #1c2128;
  color: #e6e9ec;
  border: 1px solid #3a4250;
  border-radius: 8px;
}
.leaflet-popup-tip { background: #1c2128; }
.leaflet-popup-content { margin: 10px 12px; }

.popup-title { font-weight: 600; font-size: 13px; }
.popup-name { font-size: 12px; color: #c3cad3; }
.popup-ip { font-size: 11px; color: #8b95a1; margin-bottom: 4px; }
.popup-status { font-size: 11px; font-weight: 600; margin-bottom: 8px; }
.popup-status.online { color: #3fd97f; }
.popup-status.down { color: #ff5c5c; }
.popup-status.unconfirmed { color: #f5c542; }
.popup-status.pending { color: #8b95a1; }
.popup-dust { font-size: 11px; color: #e6b34d; margin-bottom: 4px; }
.popup-wind { font-size: 11px; color: #7fd0ff; margin-bottom: 8px; }

.popup-open-btn { width: 100%; background: #2f6fe0; border-color: #3f7bf0; }
.popup-open-btn:hover { background: #3a7bf0; }

/* Site page viewer (iframe) */
#siteViewer {
  height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
}
#siteViewerBar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #171b20;
  border-bottom: 1px solid #2a303a;
  font-size: 12px;
  color: #9aa4af;
}
#siteViewerFrameWrap {
  position: relative;
  flex: 1;
}
#siteViewerFrameWrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}
.site-viewer-loading {
  position: absolute;
  inset: 0;
  background: #14181d;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #9aa4af;
  font-size: 13px;
  z-index: 2;
}
.site-viewer-loading.hidden { display: none !important; }

/* Per-monitor detail page (also used by the Settings screen's boxes, so both
   share the same denser padding/gap - kept consistent rather than having the
   detail page's Overview column look tighter than everything else). */
.detail-box { width: auto; max-width: 640px; margin-bottom: 16px; padding: 14px 18px; gap: 9px; }

/* 3-column dashboard layout so the whole page fits on one screen without
   scrolling at desktop/tablet width - each column's own lists (tickets,
   files, readings) still scroll internally via .scroll-list. Falls back to
   the single-column stack (original .detail-box behavior) below 1100px,
   where 3 columns would get too cramped to read. */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.detail-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.detail-grid .detail-box { max-width: none; margin-bottom: 0; }
#detailScreen .screen-header { margin-bottom: 10px; }
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
}
.trend-chart { color: #7fd0ff; }
.trend-current { font-size: 11px; color: #c3cad3; margin-top: 4px; }
.trend-current strong { color: #e6e9ec; }
.csv-download-link { display: inline-block; margin-top: 6px; font-size: 11px; color: #7fd0ff; }
.trend-chart .muted { color: #8b95a1; font-size: 11px; }
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding: 5px 0;
  border-bottom: 1px solid #22262c;
}
.file-row:last-child { border-bottom: none; }
.file-row a { color: #7fd0ff; }
.file-row button {
  background: transparent;
  border: none;
  color: #ff8080;
  padding: 0 4px;
}

/* Login page */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #1c2128;
  border: 1px solid #3a4250;
  border-radius: 12px;
  padding: 28px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { width: 100%; max-width: 220px; height: auto; align-self: center; margin-bottom: 4px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.account-hold { text-align: center; }
.account-hold p { font-size: 13px; line-height: 1.5; color: #c3cad3; margin: 0; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #9aa4af;
}
.login-card input {
  background: #14181d;
  border: 1px solid #3a4250;
  border-radius: 6px;
  color: #e6e9ec;
  padding: 8px 10px;
  font-size: 13px;
}
.login-footer {
  position: fixed;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: #6b7280;
}
.login-footer a { color: #7fd0ff; }

/* Pins the footer to the bottom of the Settings screen instead of it just
   trailing wherever the grid content happens to end - standard flex "sticky
   footer" pattern. Scoped to #settingsScreen specifically rather than the
   shared .screen class, since Accounts/Reports/Detail don't have a footer
   and don't need this. */
#settingsScreen { display: flex; flex-direction: column; }
.settings-footer {
  text-align: center;
  font-size: 11px;
  color: #6b7280;
  padding: 16px 0 8px;
  margin-top: auto;
}
.settings-footer a { color: #7fd0ff; }

/* Data tables (Accounts, Reports) */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
table th { text-align: left; color: #8b95a1; font-weight: 500; padding: 8px 6px; border-bottom: 1px solid #2a303a; }
table td { padding: 8px 6px; border-bottom: 1px solid #22262c; vertical-align: top; }
table tbody tr { cursor: pointer; }
table tbody tr:hover { background: #1c2128; }
table tbody tr.no-click { cursor: default; }
table tbody tr.no-click:hover { background: transparent; }

.site-checklist {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid #3a4250;
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.site-checklist label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e6e9ec;
}

.scroll-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #3a4250;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
}
/* Device readings is a short, bounded list (name/status/battery/dust/wind,
   at most ~8 rows) - grow with its content instead of an internal scrollbar,
   per River's preference. */
#detailReadingsList.scroll-list { max-height: none; overflow-y: visible; }
.scroll-list .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid #22262c;
}
.scroll-list .row:last-child { border-bottom: none; }
.scroll-list .muted { color: #8b95a1; }

.attached-site-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding: 5px 0;
  border-bottom: 1px solid #22262c;
}
.attached-site-row:last-child { border-bottom: none; }
.attached-site-row button {
  background: transparent;
  border: none;
  color: #ff8080;
  padding: 0 4px;
}

/* Narrow/phone viewports - the fleet gets checked in the field, so the topbar,
   modals, and data tables need to not clip or overflow at ~375-414px widths.
   Kept to a single row (scrolling horizontally instead of wrapping) since
   #loadingScreen/#grid/#mapContainer/.screen/#siteViewer all size themselves
   off --topbar-height (calc(100vh - var(--topbar-height))/inset(var(...))) -
   wrapping the topbar to multiple rows would silently break every one of those.
   A full mobile topbar redesign (overflow/hamburger menu) is tracked separately. */
@media (max-width: 700px) {
  #topbar {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  #topbar > * { flex-shrink: 0; }
  #summary {
    flex: 0 0 auto;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .modal-box, .modal-wide {
    width: calc(100vw - 24px);
    max-width: 460px;
  }
  .screen { overflow-x: auto; }
  table { min-width: 480px; }
}
.ticket-item {
  border-bottom: 1px solid #22262c;
  padding: 8px 0;
  font-size: 12px;
  cursor: pointer;
}
.ticket-item:last-child { border-bottom: none; }
.ticket-item:hover { background: #1a1f26; }
.ticket-item:focus-visible { outline: 2px solid #4a90e2; outline-offset: -2px; }
.ticket-reply-count { color: #7fd0ff; }
.ticket-item.resolved { opacity: 0.6; }
.ticket-item-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.ticket-title { font-weight: 600; }
.ticket-text { margin: 3px 0; }
.ticket-status {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #3a2a1a;
  color: #f5c542;
}
.ticket-status.resolved { background: #1c3a2a; color: #3fd97f; }
.ticket-visibility {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #2a303a;
  color: #9aa4af;
}
.ticket-visibility.customer-visible { background: #1c3a2a; color: #3fd97f; }
.ticket-meta {
  color: #8b95a1;
  font-size: 11px;
  margin-top: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ticket-actions { display: flex; gap: 6px; flex-shrink: 0; }
/* Resolve/Reopen/Delete match the same blue-background/white-text look as
   "Open ticket" (both use .primary) - just sized down to fit this dense row. */
.ticket-actions button.primary { padding: 3px 9px; font-size: 10px; }

.open-site-link {
  background: transparent;
  border: none;
  color: #7fd0ff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 0;
  text-decoration: underline;
}
.open-site-link:hover { background: transparent; color: #9fdcff; }

.ticket-compose-box {
  border: 1px solid #2a303a;
  border-radius: 8px;
  padding: 10px 12px;
  background: #171b20;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ticket-compose-box h4 { margin: 0; font-size: 12px; color: #9aa4af; }

.detail-box h4 { margin: 4px 0 0; font-size: 12px; color: #9aa4af; }
.detail-box h4:first-child { margin-top: 0; }

.ticket-resolved-section { border-top: 1px solid #22262c; padding-top: 8px; }
.ticket-resolved-section summary {
  cursor: pointer;
  font-size: 12px;
  color: #9aa4af;
  outline: none;
}
.ticket-resolved-section summary:hover { color: #e6e9ec; }
.ticket-resolved-section input[type="text"] {
  width: 100%;
  margin: 8px 0;
  background: #14181d;
  border: 1px solid #3a4250;
  border-radius: 6px;
  color: #e6e9ec;
  padding: 6px 9px;
  font-size: 12px;
  font-family: inherit;
}

.ticket-thread {
  margin: 6px 0 2px 0;
  padding: 6px 8px;
  background: #14181d;
  border-radius: 6px;
}
.ticket-reply { padding: 4px 0; border-bottom: 1px solid #22262c; }
.ticket-reply:last-of-type { border-bottom: none; }
.ticket-reply-text { font-size: 12px; }
.ticket-reply-meta { font-size: 10px; color: #8b95a1; margin-top: 1px; }
.ticket-reply-compose { display: flex; gap: 6px; margin-top: 6px; align-items: flex-end; }
.ticket-reply-compose textarea {
  flex: 1;
  background: #1c2128;
  border: 1px solid #3a4250;
  border-radius: 6px;
  color: #e6e9ec;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
}
.ticket-reply-send { flex-shrink: 0; }

.ticket-count-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: #3a2a1a;
  color: #f5c542;
  margin-left: 6px;
}
