/* ==========================================================================
   Uptime & Backup Monitor — Mobile-First Dark Theme
   ========================================================================== */

:root {
  --bg-app: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-hover: #19243c;
  --bg-elevated: #1f2d4a;
  --border: #23314f;
  --border-light: #324468;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-green: #10b981;
  --accent-green-bg: rgba(16, 185, 129, 0.12);
  --accent-red: #ef4444;
  --accent-red-bg: rgba(239, 68, 68, 0.12);
  --accent-amber: #f59e0b;
  --accent-amber-bg: rgba(245, 158, 11, 0.12);
  --accent-blue: #3b82f6;
  --accent-blue-bg: rgba(59, 130, 246, 0.12);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* ==========================================================================
   1. PIN Lock Screen (Zero Virtual Keyboard on Mobile)
   ========================================================================== */
.lock-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, #17233f 0%, #080c14 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: calc(var(--safe-top) + 20px);
  padding-bottom: calc(var(--safe-bottom) + 20px);
  z-index: 9999;
}

.pin-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pin-header {
  text-align: center;
  margin-bottom: 24px;
}

.lock-icon-badge {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-blue);
  margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.pin-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.pin-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 4 Digit Display Dots */
.pin-display {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  background: transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pin-dot.filled {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
  transform: scale(1.15);
}

.pin-dot.error {
  background: var(--accent-red) !important;
  border-color: var(--accent-red) !important;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6) !important;
}

.pin-feedback {
  min-height: 22px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent-red);
  margin-bottom: 16px;
  text-align: center;
}

/* Keypad Grid (3x4) */
.pin-keypad {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.key-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  height: 64px;
  border-radius: 18px;
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.key-btn:active {
  background: var(--bg-elevated);
  transform: scale(0.95);
  border-color: var(--accent-blue);
}

.key-btn.action-key {
  font-size: 1.1rem;
  color: var(--text-muted);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.key-btn.action-key:active {
  background: rgba(255, 255, 255, 0.06);
}

.pin-footer {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Shake Animation */
.shake {
  animation: shakeAnim 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shakeAnim {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* ==========================================================================
   2. Main Dashboard Layout
   ========================================================================== */
.dashboard-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: calc(var(--safe-bottom) + 30px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  padding-top: calc(var(--safe-top) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-pulse {
  width: 10px;
  height: 10px;
  background: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-green);
  animation: pulseAnim 2s infinite;
}

@keyframes pulseAnim {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.brand-text {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:active {
  background: var(--bg-elevated);
  color: var(--text-main);
  transform: scale(0.96);
}

.spin-icon.spinning {
  animation: spinAnim 0.8s linear infinite;
}

@keyframes spinAnim {
  100% { transform: rotate(360deg); }
}

/* ==========================================================================
   3. Tabs Navigation
   ========================================================================== */
.tabs-nav {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-main);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   4. Content Area
   ========================================================================== */
.content-container {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.metric-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-amber { color: var(--accent-amber); }

/* Controls Row: Filters + Search */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
  min-width: 260px;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-chip.active {
  background: var(--accent-blue-bg);
  border-color: var(--accent-blue);
  color: var(--text-main);
}

/* Responsive Filter Labels */
.label-mobile {
  display: none;
}
.label-desktop {
  display: inline;
}

@media (max-width: 640px) {
  .label-desktop {
    display: none;
  }
  .label-mobile {
    display: inline;
  }

  .content-container {
    padding: 12px;
  }

  .filter-bar {
    gap: 4px;
    padding-bottom: 2px;
  }

  .filter-chip {
    padding: 6px 8px;
    font-size: 0.76rem;
  }
}

/* Search Box */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 220px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .search-box {
    width: 100%;
  }
}

.search-input {
  width: 100%;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 32px 0 34px;
  color: var(--text-main);
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-icon {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--text-dim);
  pointer-events: none;
}

.clear-search-btn {
  position: absolute;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.clear-search-btn:hover {
  background: var(--border-light);
  color: var(--text-main);
}

/* Cards List */
.cards-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 680px) {
  .cards-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .cards-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Monitor Card */
.service-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s ease, transform 0.1s ease;
}

.service-card:hover {
  border-color: var(--border-light);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.service-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.service-name:hover {
  color: var(--accent-blue);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.status-badge.ok {
  background: var(--accent-green-bg);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.down {
  background: var(--accent-red-bg);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.latency-tag {
  font-weight: 600;
  font-size: 0.75rem;
}

.latency-good { color: var(--accent-green); }
.latency-warn { color: var(--accent-amber); }
.latency-slow { color: var(--accent-red); }

.host-badge {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Backup Card Extra */
.backup-details {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 6px 0 10px 0;
  line-height: 1.4;
}

.backup-log-toggle {
  background: transparent;
  border: none;
  color: var(--accent-blue);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  margin-top: 4px;
}

.backup-log-box {
  display: none;
  background: #05070d;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-family: monospace;
  font-size: 0.7rem;
  color: #cbd5e1;
  max-height: 140px;
  overflow-y: auto;
  margin-top: 8px;
  white-space: pre-wrap;
}

.loading-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
