/* Reset & Root Variables */
:root {
  --bg-main: #080b11;
  --bg-card: rgba(18, 25, 41, 0.7);
  --bg-card-solid: #121929;
  --border-color: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(255, 255, 255, 0.2);
  --text-main: #f3f4f6;
  --text-muted: #7e8b9f;
  --text-dim: #4b5565;
  
  /* Active Counter Default Theme (will be overridden by JS) */
  --accent: #00f2fe;
  --accent-glow: rgba(0, 242, 254, 0.3);
  --accent-dark: #0072ff;
  
  /* Fonts */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  /* Heights & Durations */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* App Container */
.app-container {
  position: relative;
  width: 100%;
  max-width: 480px; /* Mobile width cap on desktops */
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-main);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* ==========================================================================
   1. MAIN SCREEN (Logging & Immediate Info)
   ========================================================================== */

.main-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 24px calc(24px + var(--safe-bottom)) 24px;
  position: relative;
  z-index: 1;
}

/* Top Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.active-counter-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.active-counter-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  transition: var(--transition-fast);
}

.icon-button {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: var(--transition-fast);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.icon-button:hover {
  color: var(--text-main);
  border-color: var(--border-focus);
  transform: rotate(30deg);
}

.icon-button:active {
  transform: scale(0.92) rotate(30deg);
}

.feather-icon {
  width: 20px;
  height: 20px;
}

/* Logging Splash Area */
.log-splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: -30px;
}

/* Large Logging Animation Circle */
.log-indicator-container {
  position: relative;
  width: 160px;
  height: 160px;
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.log-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-card-solid) 0%, #0d121f 100%);
  border: 4px solid var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px var(--accent-glow), inset 0 0 20px rgba(0, 0, 0, 0.6);
  z-index: 2;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.log-circle:active {
  transform: scale(0.93);
  box-shadow: 0 0 40px var(--accent), inset 0 0 30px rgba(0, 0, 0, 0.8);
}

.log-status-icon {
  font-size: 3rem;
  color: var(--accent);
  font-weight: 900;
  text-shadow: 0 0 15px var(--accent-glow);
  transform: scale(0);
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards 0.2s;
}

.log-text {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 4px;
  color: var(--text-muted);
}

/* Pulse Rings */
.pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 140px;
  height: 140px;
  margin-top: -70px;
  margin-left: -70px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.ring-1 {
  animation: pulseOut 2s cubic-bezier(0.1, 0.8, 0.3, 1) infinite;
}

.ring-2 {
  animation: pulseOut 2s cubic-bezier(0.1, 0.8, 0.3, 1) infinite 0.8s;
}

@keyframes pulseOut {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

@keyframes popIn {
  0% {
    transform: scale(0) rotate(-45deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

/* Headings */
.splash-heading {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.splash-subheading {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* Stats bubbles */
.recent-stats-container {
  display: flex;
  gap: 16px;
  width: 100%;
  max-width: 320px;
  justify-content: center;
}

.stat-bubble {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 14px 10px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: var(--transition-fast);
}

.stat-bubble:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
}

.stat-bubble .label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-bubble .value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

/* GPS Status in Footer */
.quick-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ==========================================================================
   2. SETTINGS & ANALYTICS DRAWER
   ========================================================================== */

.drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(4, 6, 10, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 85%;
  background-color: #0b101c;
  border-top: 1px solid var(--border-color);
  border-radius: 24px 24px 0 0;
  z-index: 100;
  transform: translateY(100%);
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
}

.settings-drawer.open {
  transform: translateY(0);
}

/* Drawer handle */
.drawer-handle-bar {
  width: 100%;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.drawer-handle-bar .handle {
  width: 40px;
  height: 4px;
  background-color: var(--text-dim);
  border-radius: 99px;
  transition: var(--transition-fast);
}

.drawer-handle-bar:hover .handle {
  background-color: var(--text-muted);
}

/* Drawer Header */
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px 16px 24px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.drawer-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.close-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: var(--transition-fast);
}

.close-button:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
}

/* Drawer Scroll Content */
.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px calc(24px + var(--safe-bottom)) 24px;
}

.drawer-section {
  margin-bottom: 36px;
}

.drawer-section:last-child {
  margin-bottom: 12px;
}

.drawer-section h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Counter Selector Grid */
.counter-selector-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.counter-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--transition-fast);
}

.counter-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-focus);
}

.counter-item.active {
  border-color: var(--counter-color, var(--accent));
  background: radial-gradient(circle at top right, rgba(var(--counter-rgb, 0, 242, 254), 0.08) 0%, rgba(0, 0, 0, 0) 70%), rgba(255, 255, 255, 0.03);
}

.counter-item .c-dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--counter-color, var(--accent));
  box-shadow: 0 0 8px var(--counter-color, var(--accent));
  opacity: 0.3;
}

.counter-item.active .c-dot {
  opacity: 1;
}

.counter-item .c-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counter-item .c-count-bubble {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.counter-item .c-count {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
}

.counter-item .c-count-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Delete tiny button on counter item */
.counter-delete-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: var(--transition-fast);
}

.counter-item:hover .counter-delete-btn {
  opacity: 1;
}

.counter-delete-btn:hover {
  color: #ff4e50;
  background: rgba(255, 78, 80, 0.1);
}

/* Forms */
.new-counter-form {
  display: flex;
  gap: 12px;
  width: 100%;
}

.new-counter-form input {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition-fast);
}

.new-counter-form input:focus {
  border-color: rgba(255, 255, 255, 0.3);
  background-color: rgba(255, 255, 255, 0.05);
}

/* Buttons */
.primary-button {
  background-color: var(--text-main);
  color: var(--bg-main);
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-weight: 600;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

.primary-button:active {
  transform: scale(0.97);
}

.secondary-button {
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 500;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-fast);
}

.secondary-button:hover {
  background-color: rgba(255, 255, 255, 0.07);
  border-color: var(--border-focus);
}

.secondary-button:active {
  transform: scale(0.97);
}

.danger-button {
  background-color: rgba(255, 78, 80, 0.06);
  border: 1px solid rgba(255, 78, 80, 0.2);
  color: #ff4e50;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 500;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-fast);
}

.danger-button:hover {
  background-color: rgba(255, 78, 80, 0.12);
  border-color: #ff4e50;
}

.danger-button:active {
  transform: scale(0.97);
}

.btn-icon {
  width: 16px;
  height: 16px;
}

/* Stats Cards Grid Detailed */
.stats-grid-detailed {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card .card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-card .card-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Charts Containers */
.chart-container {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
  height: 220px;
  width: 100%;
}

/* Map Containers */
#map-container {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
  margin-bottom: 16px;
}

#map {
  height: 240px;
  width: 100%;
  background-color: #0b0f19;
}

/* Leaflet Map overrides to match dark mode theme */
.leaflet-container {
  font-family: var(--font-sans) !important;
}
.leaflet-bar {
  border: 1px solid var(--border-color) !important;
  box-shadow: none !important;
  border-radius: 8px !important;
  overflow: hidden;
}
.leaflet-bar a {
  background-color: var(--bg-card-solid) !important;
  color: var(--text-main) !important;
  border-bottom: 1px solid var(--border-color) !important;
  transition: var(--transition-fast);
}
.leaflet-bar a:hover {
  background-color: rgba(255, 255, 255, 0.05) !important;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-card-solid) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-color);
  border-radius: 12px !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4) !important;
}
.leaflet-popup-content {
  font-size: 0.85rem !important;
  font-weight: 500;
  margin: 12px 16px !important;
}

/* History List */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  transition: var(--transition-fast);
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-focus);
}

.history-item .h-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item .h-time {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.history-item .h-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-item .h-gps-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--accent);
}

.history-item .h-gps-icon {
  width: 10px;
  height: 10px;
  fill: currentColor;
}

.history-item .history-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.history-item .history-delete-btn:hover {
  color: #ff4e50;
  background: rgba(255, 78, 80, 0.1);
}

.history-item .history-delete-btn svg {
  width: 16px;
  height: 16px;
}

/* Action Buttons Group (CSV/PDF/Reset) */
.action-buttons-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.action-buttons-group button:last-child {
  grid-column: span 2;
}

/* Print/PDF Export styling adjustment helper */
@media print {
  body {
    background: white;
    color: black;
  }
  .settings-drawer {
    position: static;
    transform: none;
    height: auto;
    overflow: visible;
  }
  .drawer-overlay, .drawer-handle-bar, .drawer-header, .top-bar, .log-splash, .quick-footer, .new-counter-form, .action-buttons-group, .history-delete-btn {
    display: none !important;
  }
}
