/* ============================================================================
   Grocapitus Unified Design System
   All 13 applications use this system for consistent styling
   ============================================================================ */

/* Color Palette */
:root {
  --gradient-primary: linear-gradient(135deg, #042C53 0%, #185FA5 100%);  /* Grocapitus brand gradient */
  --color-heading: #1e293b;
  /* Primary Colors */
  --color-primary: #185FA5;           /* Grocapitus blue (light anchor) */
  --color-primary-light: #3b82f6;     /* Bright blue */
  --color-primary-dark: #042C53;      /* Grocapitus blue (dark anchor) */

  /* Semantic Colors */
  --color-success: #10b981;           /* Green */
  --color-warning: #f59e0b;           /* Amber */
  --color-error: #ef4444;             /* Red */
  --color-info: #0ea5e9;              /* Sky blue */

  /* Neutral Colors */
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;

  /* DESIGN.md palette tokens (not covered by the gray/semantic scales above) */
  --color-text-secondary: #5b6b7f;   /* DESIGN.md "Secondary Text (Body)" — was #64748b, darkened Oct 2026 to pass 4.5:1 on the page background */
  --color-text-tertiary: #5e7186;    /* DESIGN.md "Tertiary Text (Labels, Meta)" — was #94a3b8 (2.6:1), darkened Oct 2026 to pass 4.5:1 */
  --color-border-light: #e2e8f0;     /* DESIGN.md "Light Border" */
  --color-bg-page: #f0f4f8;          /* DESIGN.md page background */
  --color-disabled: #cbd5e1;         /* DESIGN.md "Disabled/Placeholder" */
  --color-border-medium: #cbd5e1;    /* DESIGN.md "Medium Border" — same hex as
                                         --color-disabled but a distinct concept
                                         (active input/control borders, hover
                                         dividers) so consuming apps don't have
                                         to borrow the "disabled" token name for
                                         a control that isn't disabled. */
  --color-success-text: #15803d;     /* DESIGN.md success alert text */
  --color-success-bg: #f0fdf4;       /* DESIGN.md success alert background */
  --color-success-border: #86efac;   /* DESIGN.md success alert border */
  --color-error-text: #c53030;       /* DESIGN.md error alert text */
  --color-error-bg: #fef2f2;         /* DESIGN.md error alert background */
  --color-error-border: #fecaca;     /* DESIGN.md error alert border */
  --color-warning-text: #b45309;     /* DESIGN.md warning alert text — was #d97706 (3.2:1), darkened Oct 2026 to pass 4.5:1 */
  --color-warning-bg: #fffbeb;       /* DESIGN.md warning alert background */
  --color-warning-border: #fcd34d;   /* DESIGN.md warning alert border */
  --color-badge-warning-text: #92400e; /* Darker amber for text sitting on the
                                           pastel #fef3c7 badge/chip fill below —
                                           --color-warning-text (#b45309) is tuned
                                           for text on a white/page background and
                                           falls short of 4.5:1 on that lighter
                                           chip fill. */
  --color-info-text: #1e40af;        /* DESIGN.md info alert text */
  --color-info-bg: #f0f9ff;          /* DESIGN.md info alert background */
  --color-info-border: #bfdbfe;      /* DESIGN.md info alert border */

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;

  --font-size-xs: 0.75rem;      /* 12px */
  --font-size-sm: 0.875rem;     /* 14px */
  --font-size-base: 1rem;       /* 16px */
  --font-size-lg: 1.125rem;     /* 18px */
  --font-size-xl: 1.25rem;      /* 20px */
  --font-size-2xl: 1.5rem;      /* 24px */
  --font-size-3xl: 1.875rem;    /* 30px */
  --font-size-4xl: 2.25rem;     /* 36px */

  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Spacing (8px grid) */
  --space-1: 0.5rem;    /* 8px */
  --space-2: 1rem;      /* 16px */
  --space-3: 1.5rem;    /* 24px */
  --space-4: 2rem;      /* 32px */
  --space-6: 3rem;      /* 48px */
  --space-8: 4rem;      /* 64px */

  /* Header (1 inch = 96px minimum) */
  --header-height: 96px;
  --header-padding: var(--space-2) var(--space-4);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* Border Radius */
  --radius-sm: 0.25rem;     /* 4px */
  --radius-md: 0.375rem;    /* 6px */
  --radius-lg: 0.5rem;      /* 8px */
  --radius-xl: 0.75rem;     /* 12px */
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 300ms ease-in-out;
  --transition-slow: 500ms ease-in-out;
}

/* Global Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-gray-800);
  background-color: var(--color-gray-50);
}

/* ============================================================================
   Header Component (1 inch / 96px minimum height)
   ============================================================================ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: var(--header-padding);
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  color: white;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 100;
}

.app-header__title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
}

.app-header__subtitle {
  font-size: var(--font-size-sm);
  opacity: 0.9;
  margin-left: var(--space-2);
}

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

/* ============================================================================
   Typography
   ============================================================================ */

h1 {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-3);
}

h2 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-2);
}

h3 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-2);
}

h4 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-1);
}

p {
  margin-bottom: var(--space-2);
  line-height: var(--line-height-relaxed);
}

small {
  font-size: var(--font-size-sm);
  color: var(--color-gray-600);
}

code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-gray-100);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--color-gray-300);
}

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

.btn-success:hover:not(:disabled) {
  filter: brightness(0.9);
}

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

.btn-danger:hover:not(:disabled) {
  filter: brightness(0.9);
}

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

/* WCAG 2.5.5 / Apple HIG touch target — enforced by tests/ultra_helpers.py
   assert_mobile_responsive() at the 375px and 768px viewports. Scoped to
   small screens so desktop toolbars keep their compact density. */
@media (max-width: 820px) {
  .btn-small { min-height: 44px; }
}

/* ============================================================================
   Cards
   ============================================================================ */

.card {
  background: white;
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card__header {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-gray-200);
}

.card__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
}

.card__body {
  margin-bottom: var(--space-3);
}

.card__footer {
  display: flex;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-gray-200);
}

/* ============================================================================
   Forms
   ============================================================================ */

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

label {
  display: block;
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-1);
  color: var(--color-gray-700);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: var(--space-2);
  font-size: var(--font-size-base);
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-lg);
  font-family: var(--font-sans);
  transition: var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

/* ============================================================================
   Tables
   ============================================================================ */

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

th {
  background: var(--color-gray-100);
  padding: var(--space-2);
  text-align: left;
  font-weight: var(--font-weight-semibold);
  border-bottom: 2px solid var(--color-gray-200);
}

td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-gray-200);
}

tbody tr:hover {
  background: var(--color-gray-50);
}

/* ============================================================================
   Alerts & Status Badges
   ============================================================================ */

.alert {
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success);
  border-left: 4px solid var(--color-success);
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-error);
  border-left: 4px solid var(--color-error);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning);
  border-left: 4px solid var(--color-warning);
}

.alert-info {
  background: rgba(14, 165, 233, 0.1);
  color: var(--color-info);
  border-left: 4px solid var(--color-info);
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-full);
}

/* Opaque pastel + a darkened accent text, not a translucent accent-on-accent
   blend: badges render on both white cards and the dark header gradient
   (personal-memory's "Owner only"), and the old rgba(accent, 0.2) fill only
   ever met 4.5:1 against a light page background. On the dark header it read
   at ~2.6:1 — a real WCAG failure, not just a light-bg nitpick — because the
   text blended almost into its own low-alpha chip. An opaque fill plus a
   ~700-shade text color keeps >=4.5:1 regardless of what's behind it. */
.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-error {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-warning {
  background: #fef3c7;
  color: var(--color-badge-warning-text);
}

/* ============================================================================
   Toasts (shared showToast() in /shared-fetch.js)
   ============================================================================ */

.toast-region {
  position: fixed;
  bottom: var(--space-2);
  right: var(--space-2);
  left: var(--space-2);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
  z-index: 9000;
  pointer-events: none;
}

.toast {
  display: none;
  pointer-events: auto;
  position: fixed;
  right: var(--space-2);
  bottom: var(--space-2);
  z-index: 9000;
  max-width: 380px;
  width: max-content;
  align-items: flex-start;
  gap: var(--space-1);
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  background: var(--color-gray-900);
  color: white;
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

/* Apps that toggle visibility with a `.show` class (most of them). */
.toast.show {
  display: flex;
}

/* Toasts created by the shared showToast() widget live inside .toast-region,
   stacked by its flexbox instead of each one being independently fixed —
   shown as soon as they're added, no `.show` class needed. */
.toast-region .toast {
  display: flex;
  position: static;
  max-width: 360px;
  width: 100%;
  animation: toast-in 0.15s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-message { flex: 1; }

.toast-dismiss {
  background: transparent;
  border: none;
  padding: 0;
  min-width: 20px;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
}

.toast-dismiss:hover { opacity: 1; }

.toast-success {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  color: var(--color-success-text);
}

.toast-error {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  color: var(--color-error-text);
}

.toast-warning {
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
}

.toast-info {
  background: var(--color-info-bg);
  border: 1px solid var(--color-info-border);
  color: var(--color-info-text);
}

/* ============================================================================
   Spinner
   ============================================================================ */

.spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border: 4px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* ============================================================================
   Utility Classes
   ============================================================================ */

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

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

.text-right {
  text-align: right;
}

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }

.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }

.text-gray-600 { color: var(--color-gray-600); }
.text-gray-700 { color: var(--color-gray-700); }

.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-lg { font-size: var(--font-size-lg); }

.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

.hidden { display: none; }

.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;
}

.w-full { width: 100%; }
.h-full { height: 100%; }

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    height: auto;
    padding: var(--space-3) var(--space-2);
  }

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

  .app-header__actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .toast-region {
    left: var(--space-1);
    right: var(--space-1);
    bottom: var(--space-1);
    align-items: stretch;
  }

  .container {
    padding: 0 var(--space-2);
  }
}

/* ============================================================================
   Print Styles
   ============================================================================ */

@media print {
  .app-header,
  .no-print {
    display: none;
  }

  body {
    background: white;
  }
}
