/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Color System - 5 colors total */
  --primary: #2563eb; /* Blue - primary brand */
  --primary-light: #3b82f6;
  --success: #10b981; /* Green - accent */
  --danger: #ef4444; /* Red - accent */
  --gray-50: #f9fafb; /* Light neutral */
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937; /* Dark neutral */
  --gray-900: #111827;
  --white: #ffffff; /* White neutral */
  --black: #000000; /* Black neutral */

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Layout */
  --border-radius: 0.5rem;
  --border-radius-lg: 0.75rem;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Z-index */
  --z-toast: 1000;
  --z-modal: 900;
  --z-nav: 100;
}

/* RTL Support */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .app-header {
  flex-direction: row-reverse;
}

/* Base Typography */
body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--gray-900);
  background-color: var(--gray-50);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: var(--space-2);
}

h1 {
  font-size: var(--font-size-2xl);
}
h2 {
  font-size: var(--font-size-xl);
}
h3 {
  font-size: var(--font-size-lg);
}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
  margin: 0 auto;
  background-color: var(--white);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-2);
  background-color: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
}

.app-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.header-actions {
  display: flex;
  gap: var(--space-2);
}

/* Tab Content */
.tab-content {
  flex: 1;
  padding-bottom: 80px; /* Space for bottom nav */
}

.tab-panel {
  display: none;
  padding: var(--space-4);
  animation: fadeIn 0.2s ease-in-out;
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-card.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: var(--white);
  border: none;
}

.stat-icon {
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-2);
}

.stat-value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.stat-label {
  font-size: var(--font-size-sm);
  opacity: 0.8;
  font-weight: 500;
}

/* Goal Section */
.goal-section {
  text-align: center;
  margin-bottom: var(--space-8);
}

.goal-ring-container {
  position: relative;
  display: inline-block;
  margin-bottom: var(--space-4);
}

.goal-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.goal-percentage {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--primary);
}

.goal-label {
  font-size: var(--font-size-sm);
  color: var(--gray-600);
}

.streak-info {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--gray-600);
}

/* Session Controls */
.session-controls {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow);
}

.session-info {
  text-align: center;
  margin-bottom: var(--space-4);
}

.session-time {
  font-size: var(--font-size-4xl);
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.session-status {
  font-size: var(--font-size-sm);
  color: var(--gray-600);
  margin-top: var(--space-1);
}

.control-buttons {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.session-options {
  display: flex;
  justify-content: center;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-destructive {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--border-radius);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-height: 44px; /* Touch target */
}

.btn-primary {
  background-color: var(--primary);
  color: var(--white);
}

.btn-primary:hover {
  background-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background-color: var(--gray-200);
}

.btn-destructive {
  background-color: var(--danger);
  color: var(--white);
}

.btn-destructive:hover {
  background-color: #dc2626;
}

.btn-primary.large,
.btn-secondary.large,
.btn-destructive.large {
  flex: 1;
  padding: var(--space-4) var(--space-6);
  font-size: var(--font-size-lg);
}

.btn-secondary.small {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--border-radius);
  background-color: var(--gray-100);
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background-color: var(--gray-200);
  color: var(--gray-700);
}

/* Toggle Switch */
.toggle-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.toggle-option input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: var(--gray-300);
  border-radius: 12px;
  transition: background-color 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background-color: var(--white);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-option input[type="checkbox"]:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-option input[type="checkbox"]:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: var(--font-size-sm);
  color: var(--gray-700);
}

/* History */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.history-item {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.history-date {
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: var(--space-2);
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--space-3);
}

.history-stat {
  text-align: center;
}

.history-stat-value {
  font-weight: 600;
  color: var(--primary);
}

.history-stat-label {
  font-size: var(--font-size-xs);
  color: var(--gray-600);
}

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--gray-500);
}

.empty-icon {
  font-size: var(--font-size-4xl);
  margin-bottom: var(--space-4);
}

.empty-subtitle {
  font-size: var(--font-size-sm);
  margin-top: var(--space-2);
}

/* Analytics */
.analytics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.period-selector {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  padding: var(--space-1);
}

.period-btn {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  border-radius: calc(var(--border-radius) - 2px);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.period-btn.active {
  background: var(--white);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.charts-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.chart-section {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.chart-section h3 {
  margin-bottom: var(--space-4);
  color: var(--gray-700);
}

.chart-section canvas {
  width: 100%;
  height: auto;
}

/* Profile Form */
.profile-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.form-section {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.form-section h3 {
  margin-bottom: var(--space-4);
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: var(--space-2);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-group label {
  display: block;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-2);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: var(--font-size-base);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.permission-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius);
  margin-bottom: var(--space-3);
}

.permission-info strong {
  display: block;
  color: var(--gray-900);
  margin-bottom: var(--space-1);
}

.permission-info p {
  font-size: var(--font-size-sm);
  color: var(--gray-600);
  margin: 0;
}

.data-actions {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  padding: var(--space-2) 0;
  z-index: var(--z-nav);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  border: none;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  transition: color 0.2s ease;
  min-height: 60px;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item span {
  font-size: var(--font-size-xs);
  font-weight: 500;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  max-width: 300px;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

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

/* Install Prompt */
.install-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
}

.install-content {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  padding: var(--space-6);
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.install-content h3 {
  margin-bottom: var(--space-2);
  color: var(--gray-900);
}

.install-content p {
  color: var(--gray-600);
  margin-bottom: var(--space-4);
}

.install-actions {
  display: flex;
  gap: var(--space-3);
}

/* Offline Indicator */
.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: var(--white);
  text-align: center;
  padding: var(--space-2);
  font-size: var(--font-size-sm);
  z-index: var(--z-toast);
}

/* Utility Classes */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Responsive Design */
@media (min-width: 768px) {
  .app-container {
    max-width: 768px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .charts-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .bottom-nav {
    position: relative;
    border-top: none;
    border-bottom: 1px solid var(--gray-200);
    order: -1;
  }

  .tab-content {
    padding-bottom: var(--space-4);
  }

  .nav-item {
    flex-direction: row;
    justify-content: center;
    min-height: 50px;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
    --white: #1f2937;
    --black: #f9fafb;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --gray-300: #000000;
    --gray-600: #ffffff;
  }

  .btn-primary {
    border: 2px solid var(--black);
  }

  .btn-secondary {
    border: 2px solid var(--black);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
