/* ==========================================================================
   Design System Tokens
   ========================================================================== */
:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: 'Playfair Display', Georgia, Cambria, 'Times New Roman', Times, serif;
  
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;

  /* Spacing */
  --spacing-1: 0.25rem;
  --spacing-2: 0.5rem;
  --spacing-3: 0.75rem;
  --spacing-4: 1rem;
  --spacing-6: 1.5rem;
  --spacing-8: 2rem;
  --spacing-12: 3rem;
  --spacing-16: 4rem;
  --spacing-24: 6rem;
  --spacing-32: 8rem;

  /* Colors - Light Theme (Default) */
  --bg-primary: #FAFAFA;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F4F4F5;
  
  --text-primary: #18181B;
  --text-secondary: #52525B;
  --text-tertiary: #A1A1AA;
  
  --border-color: #E4E4E7;
  --accent-color: #27272A;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Colors - Dark Theme */
[data-theme="dark"] {
  --bg-primary: #09090B;
  --bg-secondary: #18181B;
  --bg-tertiary: #27272A;
  
  --text-primary: #FAFAFA;
  --text-secondary: #A1A1AA;
  --text-tertiary: #71717A;
  
  --border-color: #27272A;
  --accent-color: #E4E4E7;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

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

html {
  font-family: var(--font-sans);
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.2;
  margin-bottom: var(--spacing-4);
  color: var(--text-primary);
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }

p {
  margin-bottom: var(--spacing-4);
  color: var(--text-secondary);
}

.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-serif { font-family: var(--font-serif); }

/* ==========================================================================
   Layout & Utilities
   ========================================================================== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-4);
}

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: var(--spacing-2); }
.gap-4 { gap: var(--spacing-4); }
.gap-6 { gap: var(--spacing-6); }
.gap-8 { gap: var(--spacing-8); }

.mt-4 { margin-top: var(--spacing-4); }
.mt-8 { margin-top: var(--spacing-8); }
.mt-16 { margin-top: var(--spacing-16); }
.mb-4 { margin-bottom: var(--spacing-4); }
.mb-8 { margin-bottom: var(--spacing-8); }

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

/* ==========================================================================
   Components
   ========================================================================== */
/* Header */
.header {
  padding: var(--spacing-6) 0;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 400;
  letter-spacing: -0.02em;
}

/* Nav & Toggles */
.nav-links {
  display: flex;
  gap: var(--spacing-6);
}

.nav-link {
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-tertiary);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.icon-button:hover {
  background-color: var(--border-color);
  transform: scale(1.05);
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
  html, body {
    background-color: white !important;
    color: black !important;
  }
  
  [data-theme="dark"] {
    --bg-primary: white;
    --bg-secondary: white;
    --bg-tertiary: #f4f4f5;
    --text-primary: black;
    --text-secondary: #333;
    --text-tertiary: #666;
    --border-color: #ddd;
  }

  .header, .footer, .filters, .sorters, #theme-toggle, .nav-links {
    display: none !important;
  }

  .gallery-grid {
    column-count: 2 !important;
    column-gap: 20px;
  }

  .painting-card {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    margin-bottom: 20px !important;
  }
  
  .exhibition-section {
    page-break-inside: avoid;
    break-inside: avoid;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-8);
  }
  .exhibition-section img {
    break-inside: avoid;
  }
}

.gallery-grid {
  column-count: 3;
  column-gap: var(--spacing-8);
  padding: var(--spacing-8) 0;
}

@media (max-width: 1024px) {
  .gallery-grid { column-count: 2; }
}

@media (max-width: 640px) {
  .gallery-grid { column-count: 1; }
}

/* Cards */
.painting-card {
  background-color: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  border: 1px solid var(--border-color);
  break-inside: avoid; /* Crucial for masonry: stops cards splitting across columns */
  margin-bottom: var(--spacing-8); /* Adds vertical space between cards in the masonry flow */
  cursor: pointer;
  display: block; /* Ensures natural height calculation */
}

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

.painting-card-image-wrapper {
  position: relative;
  width: 100%;
  background-color: var(--bg-tertiary);
  /* The padding-top trick for aspect ratio will be applied via inline style generated by Jinja */
}

.painting-card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.painting-card-content {
  padding: var(--spacing-4);
}

.painting-title {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  margin-bottom: var(--spacing-1);
  color: var(--text-primary);
}

.painting-meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--spacing-3);
}

/* Tags */
.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-2);
}

.tag {
  font-size: var(--text-xs);
  padding: 2px 8px;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

/* Color Swatches */
.color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1);
  display: inline-block;
}
