/* style.css — Smart Forage & Pasture Design Tokens + Component Styles */

/* =============================================
   FONTS
   ============================================= */
@import url('https://api.fontshare.com/v2/css?f[]=general-sans@400,500,600,700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&display=swap');

/* =============================================
   TYPE SCALE
   ============================================= */
:root {
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;

  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.9rem  + 0.5vw,  1.125rem);
  --text-lg:   clamp(1.125rem, 0.95rem + 0.85vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1rem    + 1.5vw,  2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);
  --text-3xl:  clamp(2.5rem,   1rem    + 4vw,    5rem);
  --text-hero: clamp(3rem,     0.5rem  + 7vw,    8rem);

  /* =============================================
     SPACING (4px base)
     ============================================= */
  --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-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* =============================================
     RADIUS
     ============================================= */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* =============================================
     TRANSITIONS
     ============================================= */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* =============================================
     CONTENT WIDTHS
     ============================================= */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;
}

/* =============================================
   LIGHT MODE — Smart Forage Palette
   ============================================= */
:root, [data-theme="light"] {
  /* Surfaces */
  --color-bg:               #f4f4f2;
  --color-surface:          #fafaf8;
  --color-surface-2:        #ffffff;
  --color-surface-offset:   #eeeee9;
  --color-surface-offset-2: #e6e6e0;
  --color-surface-dynamic:  #ddddd6;
  --color-divider:          #d4d4cb;
  --color-border:           #c8c8be;

  /* Text */
  --color-text:             #2a2a28;
  --color-text-muted:       #6b6b66;
  --color-text-faint:       #a3a39e;
  --color-text-inverse:     #ffffff;

  /* Primary Accent — Smart Forage Green #86bc25 */
  --color-primary:          #86bc25;
  --color-primary-hover:    #6fa01e;
  --color-primary-active:   #5a8518;
  --color-primary-highlight: #e8f2d3;
  --color-primary-text:     #1a2e05;

  /* Semantic Colors */
  --color-error:            #c5362a;
  --color-error-hover:      #a82c22;
  --color-error-active:     #8b2319;
  --color-error-highlight:  #f5dbd8;

  --color-success:          #2d8540;
  --color-success-hover:    #236b33;
  --color-success-active:   #1a5226;
  --color-success-highlight: #d4edda;

  --color-warning:          #cc7a00;
  --color-warning-hover:    #a86300;
  --color-warning-active:   #854e00;
  --color-warning-highlight: #fce8c4;

  /* Shadows (warm-toned) */
  --shadow-sm: 0 1px 2px oklch(0.25 0.01 100 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.25 0.01 100 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.25 0.01 100 / 0.12);
  --shadow-card: 0 1px 3px oklch(0.25 0.01 100 / 0.04), 0 8px 24px oklch(0.25 0.01 100 / 0.06);
}

/* =============================================
   DARK MODE — Smart Forage Palette
   ============================================= */
[data-theme="dark"] {
  --color-bg:               #141614;
  --color-surface:          #1a1c1a;
  --color-surface-2:        #1f211f;
  --color-surface-offset:   #1c1e1c;
  --color-surface-offset-2: #232523;
  --color-surface-dynamic:  #2c2e2c;
  --color-divider:          #272927;
  --color-border:           #383a38;

  --color-text:             #cdd0cb;
  --color-text-muted:       #7f827d;
  --color-text-faint:       #585a56;
  --color-text-inverse:     #1a1c1a;

  --color-primary:          #9acc3c;
  --color-primary-hover:    #86bc25;
  --color-primary-active:   #6fa01e;
  --color-primary-highlight: #2a3320;
  --color-primary-text:     #141614;

  --color-error:            #e06058;
  --color-error-hover:      #d04a42;
  --color-error-active:     #b83830;
  --color-error-highlight:  #3d2220;

  --color-success:          #5cb870;
  --color-success-hover:    #42a057;
  --color-success-active:   #2d8540;
  --color-success-highlight: #1f3225;

  --color-warning:          #e8a030;
  --color-warning-hover:    #d08d20;
  --color-warning-active:   #b57a10;
  --color-warning-highlight: #3a2e18;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
  --shadow-card: 0 1px 3px oklch(0 0 0 / 0.15), 0 8px 24px oklch(0 0 0 / 0.2);
}

/* System preference fallback */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:               #141614;
    --color-surface:          #1a1c1a;
    --color-surface-2:        #1f211f;
    --color-surface-offset:   #1c1e1c;
    --color-surface-offset-2: #232523;
    --color-surface-dynamic:  #2c2e2c;
    --color-divider:          #272927;
    --color-border:           #383a38;
    --color-text:             #cdd0cb;
    --color-text-muted:       #7f827d;
    --color-text-faint:       #585a56;
    --color-text-inverse:     #1a1c1a;
    --color-primary:          #9acc3c;
    --color-primary-hover:    #86bc25;
    --color-primary-active:   #6fa01e;
    --color-primary-highlight: #2a3320;
    --color-primary-text:     #141614;
    --color-error:            #e06058;
    --color-error-hover:      #d04a42;
    --color-error-active:     #b83830;
    --color-error-highlight:  #3d2220;
    --color-success:          #5cb870;
    --color-success-hover:    #42a057;
    --color-success-active:   #2d8540;
    --color-success-highlight: #1f3225;
    --color-warning:          #e8a030;
    --color-warning-hover:    #d08d20;
    --color-warning-active:   #b57a10;
    --color-warning-highlight: #3a2e18;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
    --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
    --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
    --shadow-card: 0 1px 3px oklch(0 0 0 / 0.15), 0 8px 24px oklch(0 0 0 / 0.2);
  }
}

/* =============================================
   SHARED COMPONENTS
   ============================================= */

/* View system */
.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Logo */
.logo-smart {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-lg);
  color: var(--color-text);
  line-height: 1;
  letter-spacing: -0.01em;
}

.logo-forage {
  font-family: var(--font-body);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-text-muted);
  display: block;
  line-height: 1;
  margin-top: 1px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--transition-interactive);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-height: 44px;
  white-space: nowrap;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { background: var(--color-primary-active); }

.btn-secondary {
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
  background: transparent;
}
.btn-secondary:hover {
  background: var(--color-primary-highlight);
}

.btn-ghost {
  color: var(--color-text-muted);
  background: transparent;
  padding: var(--space-2) var(--space-3);
}
.btn-ghost:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.btn-sm {
  min-height: 36px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn-full {
  width: 100%;
}

.btn-loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-coming {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}

/* Section label */
.section-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}

/* Theme toggle */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
  flex-shrink: 0;
}
.theme-toggle-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

/* =============================================
   LOGIN VIEW
   ============================================= */
.login-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: var(--space-6);
}

/* Subtle agricultural CSS pattern background */
.login-bg-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.4;
  background-image:
    radial-gradient(circle at 20% 80%, oklch(from var(--color-primary) l c h / 0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, oklch(from var(--color-primary) l c h / 0.04) 0%, transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      oklch(from var(--color-primary) l c h / 0.03) 39px,
      oklch(from var(--color-primary) l c h / 0.03) 40px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 39px,
      oklch(from var(--color-primary) l c h / 0.03) 39px,
      oklch(from var(--color-primary) l c h / 0.03) 40px
    );
}

[data-theme="dark"] .login-bg-pattern {
  opacity: 0.2;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  box-shadow: var(--shadow-card);
}

@media (max-width: 480px) {
  .login-card {
    padding: var(--space-6);
    border-radius: var(--radius-lg);
  }
}

.login-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.login-logo svg {
  flex-shrink: 0;
}

.login-logo-text {
  display: flex;
  flex-direction: column;
}

.login-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.login-tagline {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-8);
}

/* Form */
.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-field input {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-sm);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
  min-height: 44px;
}

@media (max-width: 480px) {
  .form-field input {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
}

.form-field input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.15);
}

.form-field input::placeholder {
  color: var(--color-text-faint);
}

.form-field input.input-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px oklch(from var(--color-error) l c h / 0.1);
}

.field-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-1);
}

.login-footer-text {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-6);
}

.login-footer-text a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}
.login-footer-text a:hover {
  text-decoration: underline;
}

/* =============================================
   WELCOME / DASHBOARD VIEW
   ============================================= */

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-divider);
  backdrop-filter: blur(12px);
}

.app-header-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  gap: var(--space-4);
}

.header-left {
  display: flex;
  align-items: center;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-logo-text {
  display: flex;
  flex-direction: column;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-primary-highlight);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  flex-shrink: 0;
}

.user-email {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .user-email {
    display: none;
  }
  .app-header-inner {
    padding: var(--space-2) var(--space-4);
  }
  .header-right {
    gap: var(--space-2);
  }
  .header-logo .logo-forage {
    font-size: 0.5rem;
    letter-spacing: 0.1em;
  }
}

/* Welcome Hero */
.welcome-hero {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  padding: clamp(var(--space-10), 5vw, var(--space-16)) var(--space-6);
}

.welcome-hero-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
}

.welcome-heading {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.welcome-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Dashboard content */
.dashboard-content {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  flex: 1;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-6);
}

.dash-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  transition: box-shadow var(--transition-interactive), border-color var(--transition-interactive);
}

.dash-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.dash-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text);
}

.dash-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
  flex: 1;
}

.dash-card-footer {
  padding-top: var(--space-2);
}

/* Footer */
.app-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
  padding: var(--space-6);
}

.app-footer-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.app-footer-inner a {
  color: var(--color-text-faint);
  text-decoration: none;
  transition: color var(--transition-interactive);
}

.app-footer-inner a:hover {
  color: var(--color-text-muted);
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.login-card {
  animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

.dash-card {
  animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1);
  animation-fill-mode: backwards;
}

.dash-card:nth-child(1) { animation-delay: 80ms; }
.dash-card:nth-child(2) { animation-delay: 140ms; }
.dash-card:nth-child(3) { animation-delay: 200ms; }

@media (prefers-reduced-motion: reduce) {
  .login-card,
  .dash-card {
    animation: none;
  }
}
