/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Mobile tap highlight removal */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Safe area for iPhone notch */
html {
  scroll-behavior: smooth;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* Header */
.header {
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
}

.logo-img {
  height: 28px;
  width: auto;
  display: block;
}

.auth-logo {
  display: block;
  height: 36px;
  width: auto;
  margin: 0 auto 1rem;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.last-sync {
  font-size: 0.8125rem;
  color: #666;
}

.btn {
  padding: 0.625rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  min-height: 44px;
  min-width: 44px;
}

.btn-primary {
  background: #3b82f6;
  color: white;
}

.btn-primary:hover,
.btn-primary:active {
  background: #2563eb;
}

.btn-secondary {
  background: #10b981;
  color: white;
}

.btn-secondary:hover,
.btn-secondary:active {
  background: #059669;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Dashboard */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Metric Cards */
.metric-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.metric-card {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.metric-card h3 {
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.metric-card .value {
  font-size: 2rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
}

.metric-card .delta {
  font-size: 0.875rem;
  font-weight: 500;
}

.metric-card .delta.positive {
  color: #10b981;
}

.metric-card .delta.negative {
  color: #ef4444;
}

/* Charts */
.chart-section {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-section h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1rem;
}

.chart-container {
  height: 300px;
  position: relative;
}

/* Rows and columns */
.row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.col {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.col h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1rem;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 400px;
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.data-table th {
  background: #f9fafb;
  font-weight: 600;
  color: #666;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table tr:hover {
  background: #f9fafb;
}

/* Frequency lists */
.frequency-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.frequency-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.frequency-item .rank {
  font-weight: 600;
  color: #666;
  width: 2rem;
  font-size: 0.875rem;
}

.frequency-item .name {
  flex: 1;
  font-size: 0.875rem;
}

.frequency-item .bar-container {
  flex: 2;
  background: #e5e7eb;
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}

.frequency-item .bar {
  background: #3b82f6;
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.frequency-item .count {
  font-weight: 600;
  width: 3rem;
  text-align: right;
  font-size: 0.875rem;
}

/* Origin map */
.origin-map {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.origin-map h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1rem;
}

.cities-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.city-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f9fafb;
  border-radius: 8px;
}

.city-card .rank {
  font-weight: 600;
  color: #666;
  width: 2rem;
}

.city-card .city {
  flex: 1;
  font-size: 0.875rem;
}

.city-card .count {
  font-weight: 600;
  font-size: 0.875rem;
}

/* Footer */
.footer {
  background: white;
  border-top: 1px solid #eee;
  padding: 1.5rem 2rem;
  text-align: center;
  margin-top: 2rem;
}

.footer p {
  font-size: 0.875rem;
  color: #666;
}

/* ============================================
   FLASH MESSAGES
   ============================================ */
.flash {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 1000;
  animation: slideIn 0.3s ease, fadeOut 0.5s ease 4.5s forwards;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

.flash-notice {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.flash-alert {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ============================================
   USER NAVIGATION
   ============================================ */
.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  font-size: 0.875rem;
  color: #666;
  font-weight: 500;
}

.btn-logout {
  background: #ef4444;
  color: white;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.2s;
}

.btn-logout:hover {
  background: #dc2626;
}

/* Responsive */
@media (max-width: 1024px) {
  .metric-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .row {
    grid-template-columns: 1fr;
  }

  .cities-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .header {
    padding: 0.625rem 0.875rem;
  }

  .header-content {
    gap: 0.75rem;
  }

  .header-nav {
    width: 100%;
    justify-content: space-between;
  }

  .sync-status {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .metric-cards {
    grid-template-columns: 1fr;
  }

  .metric-card .value {
    font-size: 1.5rem;
  }

  .chart-container {
    height: 240px;
  }

  .main {
    padding: 1rem 0.875rem;
  }

  .col {
    padding: 1rem;
  }

  .chart-section,
  .origin-map {
    padding: 1rem;
  }
}

@media (max-width: 640px) {
  .header-content {
    flex-direction: column;
    align-items: stretch;
  }

  .logo-img {
    height: 24px;
  }

  .header-nav {
    flex-direction: column;
    gap: 0.5rem;
  }

  .sync-status {
    flex-direction: column;
    align-items: stretch;
  }

  .sync-status .btn {
    width: 100%;
  }

  .metric-cards {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .metric-card {
    padding: 1rem;
  }

  .metric-card .value {
    font-size: 1.375rem;
  }

  .chart-container {
    height: 200px;
  }

  .cities-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .frequency-item {
    gap: 0.5rem;
  }

  .frequency-item .name {
    font-size: 0.8125rem;
  }

  .frequency-item .count {
    width: 2rem;
    font-size: 0.8125rem;
  }
}

/* ============================================
   MVP POLISH - Enhanced Visual Styles
   ============================================ */

/* Typography improvements */
h1, h2, h3 {
  letter-spacing: -0.025em;
}

/* Metric card enhancements */
.metric-card {
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

.metric-card:hover::before {
  opacity: 1;
}

.metric-card:nth-child(1)::before { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.metric-card:nth-child(2)::before { background: linear-gradient(90deg, #10b981, #34d399); }
.metric-card:nth-child(3)::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.metric-card:nth-child(4)::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

/* Section styling */
.chart-section,
.col,
.origin-map {
  transition: box-shadow 0.2s ease;
}

.chart-section:hover,
.col:hover,
.origin-map:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Badge for revenue */
.metric-card .value {
  background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Status badges */
.delta.positive {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.delta.positive::before {
  content: '▲';
  font-size: 0.625rem;
}

.delta.negative::before {
  content: '▼';
  font-size: 0.625rem;
}

/* Table improvements */
.data-table tbody tr {
  transition: background-color 0.15s ease;
}

/* Frequency bar animation */
.frequency-item .bar {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

/* City card enhancements */
.city-card {
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.city-card:hover {
  border-color: #e5e7eb;
  transform: translateX(4px);
}

/* Loading state for sync buttons */
.btn:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* Touch feedback for mobile */
.metric-card:active,
.chart-section:active,
.col:active,
.origin-map:active,
.city-card:active {
  transform: scale(0.99);
  transition: transform 0.1s;
}

/* Smooth scroll */
html {
  scroll-behavior: smooth;
}

/* Selection color */
::selection {
  background: #3b82f6;
  color: white;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a1a1a1;
}

/* Touch overflow scrolling */
.table-wrapper,
.chart-container,
.frequency-list {
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   AUTHENTICATION (Devise)
   ============================================ */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 80px);
  padding: 1rem;
}

.auth-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
}

@media (min-width: 641px) {
  .auth-container {
    padding: 2rem;
  }

  .auth-card {
    padding: 2.5rem;
  }
}

.auth-card h2 {
  font-size: 1.375rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
  text-align: center;
}

@media (min-width: 641px) {
  .auth-card h2 {
    font-size: 1.5rem;
  }
}

.auth-card .auth-subtitle {
  font-size: 0.875rem;
  color: #666;
  text-align: center;
  margin-bottom: 1.5rem;
}

@media (min-width: 641px) {
  .auth-card .auth-subtitle {
    margin-bottom: 2rem;
  }
}

.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.375rem;
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"] {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  box-sizing: border-box;
}

.field input[type="email"]:focus,
.field input[type="password"]:focus,
.field input[type="text"]:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.field em {
  font-size: 0.8125rem;
  color: #9ca3af;
  display: block;
  margin-top: 0.25rem;
}

.field .checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field .checkbox-wrapper label {
  margin-bottom: 0;
  font-weight: 400;
  font-size: 0.875rem;
  cursor: pointer;
}

.field input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: #3b82f6;
  cursor: pointer;
}

/* Password reveal toggle */
.password-wrapper {
  position: relative;
}

.password-wrapper input[type="password"],
.password-wrapper input[type="text"] {
  padding-right: 2.75rem;
}

.password-toggle {
  position: absolute;
  right: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: #9ca3af;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  line-height: 0;
}

.password-toggle:hover {
  color: #6b7280;
}

.actions {
  margin-top: 1.5rem;
}

.actions .btn-primary,
.actions input[type="submit"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.actions input[type="submit"]:hover {
  background: #2563eb;
}

.actions input[type="submit"]:active {
  transform: scale(0.98);
}

.auth-links {
  margin-top: 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-links p {
  margin: 0;
  font-size: 0.875rem;
}

.auth-links a {
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.auth-links a:hover {
  color: #2563eb;
  text-decoration: underline;
}

/* Auth error messages */
#error_explanation {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

#error_explanation h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #991b1b;
  margin-bottom: 0.5rem;
  text-align: left;
}

#error_explanation ul {
  margin: 0;
  padding-left: 1.25rem;
}

#error_explanation li {
  font-size: 0.8125rem;
  color: #b91c1c;
  margin-bottom: 0.25rem;
}

/* Cancel account section */
.cancel-account {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
  text-align: center;
}

.cancel-account h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #991b1b;
  margin-bottom: 0.5rem;
}

.cancel-account .btn-danger {
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.cancel-account .btn-danger:hover {
  background: #dc2626;
}

.back-link {
  display: block;
  text-align: center;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: #3b82f6;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}
