/* MyMicroApp Shared Base Stylesheet
 * Professional design token system for all PWAs
 * Usage: <link rel="stylesheet" href="https://www.mymicroapp.com/shared/base.css">
 */

/* Design Tokens - Blue Sky Theme */
:root {
  /* HSL values without hsl() wrapper for flexibility */
  /* Base Colors */
  --background: 210 20% 98%;
  --foreground: 222 47% 11%;

  /* Surface Colors */
  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;
  --surface: 210 20% 96%;
  --surface-foreground: 222 47% 11%;

  /* Primary Action Color (Blue) */
  --primary: 217 91% 60%;
  --primary-foreground: 0 0% 100%;

  /* Secondary/Muted Colors */
  --secondary: 210 20% 96%;
  --secondary-foreground: 222 47% 11%;
  --muted: 210 20% 96%;
  --muted-foreground: 215 16% 47%;
  --accent: 217 91% 60%;
  --accent-foreground: 0 0% 100%;

  /* Semantic Colors */
  --destructive: 0 84% 60%;
  --destructive-foreground: 0 0% 100%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 100%;

  /* UI Element Colors */
  --border: 214 32% 91%;
  --input: 214 32% 91%;
  --ring: 217 91% 60%;

  /* Layout & Typography */
  --radius: 0.5rem;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Consolas, 'Liberation Mono', monospace;

  /* Spacing Scale */
  --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;

  /* Typography Scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;

  /* Shadows */
  --shadow: 0 1px 3px hsl(222 47% 11% / 0.1);
  --shadow-lg: 0 10px 25px hsl(222 47% 11% / 0.1);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --background: 222 47% 11%;
    --foreground: 210 40% 98%;

    --card: 222 47% 15%;
    --card-foreground: 210 40% 98%;
    --surface: 217 33% 17%;
    --surface-foreground: 210 40% 98%;

    --primary: 217 91% 60%;
    --primary-foreground: 222 47% 11%;

    --secondary: 217 33% 17%;
    --secondary-foreground: 210 40% 98%;
    --muted: 217 33% 17%;
    --muted-foreground: 215 20% 65%;
    --accent: 217 91% 60%;
    --accent-foreground: 222 47% 11%;

    --destructive: 0 63% 31%;
    --destructive-foreground: 210 40% 98%;
    --success: 142 71% 45%;
    --success-foreground: 210 40% 98%;
    --warning: 38 92% 50%;
    --warning-foreground: 0 0% 0%;

    --border: 217 33% 24%;
    --input: 217 33% 24%;
    --ring: 217 91% 60%;

    --shadow: 0 1px 3px hsl(0 0% 0% / 0.3);
    --shadow-lg: 0 10px 25px hsl(0 0% 0% / 0.4);
  }
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.6;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* App Header */
.app-header {
  background: hsl(var(--surface));
  border-bottom: 1px solid hsl(var(--border));
  padding: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  text-align: center;
  color: hsl(var(--foreground));
}

.pro-badge {
  background: linear-gradient(135deg, hsl(var(--warning)), hsl(38 92% 40%));
  color: hsl(var(--warning-foreground));
  padding: var(--space-1) var(--space-2);
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: 700;
  margin-left: var(--space-2);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: hsl(var(--surface));
  border-top: 1px solid hsl(var(--border));
  display: flex;
  justify-content: space-around;
  padding: var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  background: none;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: hsl(var(--background));
}

.nav-btn.active {
  color: hsl(var(--primary));
  background: hsl(var(--background));
}

.nav-icon {
  font-size: var(--text-2xl);
}

.nav-label {
  font-size: var(--text-xs);
  font-weight: 600;
}

.add-btn {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 2rem;
  margin-top: -1.5rem;
  box-shadow: var(--shadow-lg);
}

.add-btn:hover {
  background: hsl(var(--primary) / 0.9);
}

/* Screen Container */
#screen-container {
  padding: var(--space-4);
  padding-bottom: 5rem;
  max-width: 800px;
  margin: 0 auto;
}

.screen-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-4);
  color: hsl(var(--foreground));
}

/* Cards */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: hsl(var(--card-foreground));
}

.card p {
  color: hsl(var(--muted-foreground));
  margin-bottom: var(--space-2);
  line-height: 1.6;
}

/* Project Cards */
.project-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.project-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-4);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
}

.project-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: hsl(var(--primary));
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-2);
}

.project-name {
  font-weight: 600;
  font-size: var(--text-lg);
  color: hsl(var(--foreground));
}

.project-address {
  color: hsl(var(--muted-foreground));
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.project-meta {
  display: flex;
  gap: var(--space-4);
  color: hsl(var(--muted-foreground));
  font-size: var(--text-sm);
}

/* Forms */
.field-label {
  display: block;
  font-weight: 600;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
  color: hsl(var(--foreground));
}

.field-input,
.field-textarea,
.field-select {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: var(--text-base);
  font-family: var(--font-sans);
  margin-bottom: var(--space-4);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-textarea {
  min-height: 100px;
  resize: vertical;
}

.field-input:focus,
.field-textarea:focus,
.field-select:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring) / 0.2);
}

.field-input::placeholder,
.field-textarea::placeholder {
  color: hsl(var(--muted-foreground));
}

/* Checkboxes */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.checkbox-field:hover {
  background: hsl(var(--muted));
}

.checkbox-field input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.checkbox-field label {
  flex: 1;
  cursor: pointer;
  font-size: var(--text-base);
  color: hsl(var(--foreground));
}

/* Buttons */
.btn,
.save-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  white-space: nowrap;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid transparent;
  height: 2.5rem;
  padding: var(--space-2) var(--space-4);
  min-width: 5rem;
  width: 100%;
}

.btn:focus-visible,
.save-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
}

.btn:disabled,
.save-btn:disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* Primary variant */
.btn-primary,
.save-btn {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

.btn-primary:hover,
.save-btn:hover {
  background-color: hsl(var(--primary) / 0.9);
}

/* Secondary variant */
.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--secondary));
  width: 100%;
  margin-bottom: var(--space-2);
}

.btn-secondary:hover {
  background-color: hsl(var(--secondary) / 0.8);
}

/* Outline variant */
.btn-outline {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  border-color: hsl(var(--input));
}

.btn-outline:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

/* Ghost variant */
.btn-ghost {
  background-color: transparent;
  color: hsl(var(--foreground));
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: hsl(var(--accent) / 0.1);
  color: hsl(var(--accent));
}

/* Destructive/Danger variant */
.btn-danger,
.btn-destructive,
.delete-btn {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  border-color: hsl(var(--destructive));
  width: 100%;
  padding: var(--space-3);
  font-size: var(--text-sm);
}

.btn-danger:hover,
.btn-destructive:hover,
.delete-btn:hover {
  background-color: hsl(var(--destructive) / 0.9);
}

/* Success variant */
.btn-success {
  background-color: hsl(var(--success));
  color: hsl(var(--success-foreground));
  border-color: hsl(var(--success));
}

.btn-success:hover {
  background-color: hsl(var(--success) / 0.9);
}

/* Size variants */
.btn-sm {
  height: 2.25rem;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  min-width: auto;
}

.btn-lg {
  height: 2.75rem;
  padding: var(--space-2) var(--space-8);
  font-size: var(--text-base);
}

.btn-icon {
  height: 2.5rem;
  width: 2.5rem;
  padding: 0;
  min-width: auto;
}

.btn-icon.btn-sm {
  height: 2rem;
  width: 2rem;
}

/* Checklist */
.checklist {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  transition: background-color 0.15s ease;
}

.checklist-item:hover {
  background: hsl(var(--muted));
}

.checklist-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.checklist-item label {
  flex: 1;
  cursor: pointer;
  color: hsl(var(--foreground));
}

.checklist-item.checked label {
  text-decoration: line-through;
  opacity: 0.6;
  color: hsl(var(--muted-foreground));
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-4);
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: hsl(var(--primary));
  margin-bottom: var(--space-1);
}

.stat-label {
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
}

/* Premium Gate */
.premium-gate-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: hsl(0 0% 0% / 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}

.premium-gate-content {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-8);
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.premium-gate-badge {
  display: inline-block;
  background: linear-gradient(135deg, hsl(var(--warning)), hsl(38 92% 40%));
  color: hsl(var(--warning-foreground));
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.premium-buy-btn {
  width: 100%;
  padding: var(--space-4);
  background: linear-gradient(135deg, hsl(var(--warning)), hsl(38 92% 40%));
  color: hsl(var(--warning-foreground));
  border: none;
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--space-4);
  transition: opacity 0.15s ease;
}

.premium-buy-btn:hover {
  opacity: 0.9;
}

.premium-restore-link {
  display: block;
  margin-top: var(--space-4);
  color: hsl(var(--muted-foreground));
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  font-size: var(--text-sm);
}

.premium-restore-link:hover {
  color: hsl(var(--foreground));
}

/* Loading & Empty States */
.loading {
  text-align: center;
  padding: var(--space-8);
  color: hsl(var(--muted-foreground));
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  margin-left: var(--space-2);
  border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: hsl(var(--muted-foreground));
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state p {
  color: hsl(var(--muted-foreground));
  line-height: 1.6;
}

/* Tabs */
.tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid hsl(var(--border));
}

.tab-btn {
  flex: 1;
  padding: var(--space-3);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  margin-bottom: -2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: hsl(var(--foreground));
}

.tab-btn.active {
  color: hsl(var(--primary));
  border-bottom-color: hsl(var(--primary));
}

/* Theme Picker */
.theme-picker {
  margin-bottom: var(--space-4);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-3);
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: hsl(var(--card));
  border: 2px solid hsl(var(--border));
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.theme-option:hover {
  border-color: hsl(var(--primary));
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.theme-option.active {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.1);
}

.theme-option.locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.theme-option.locked:hover {
  transform: none;
  border-color: hsl(var(--border));
}

.theme-icon {
  font-size: var(--text-2xl);
}

.theme-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: hsl(var(--foreground));
}

.theme-lock {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  font-size: var(--text-sm);
}

.theme-check {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  color: hsl(var(--primary));
  font-size: var(--text-lg);
  font-weight: 700;
}

/* Responsive */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  #screen-container {
    padding: var(--space-3);
  }

  .card {
    padding: var(--space-4);
  }

  .theme-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
