:root {
  /*
   * ============================================================================
   * COLOR PALETTE
   *
   * An elegant, minimalist, and matte color scheme.
   * Background is a soft off-white to reduce eye strain.
   * Text is a dark grey (not pure black) for a softer feel.
   * Accent color is a muted, sophisticated blue.
   * ============================================================================
   */
  --color-background: #fdfdfd; /* Soft, slightly warm off-white */
  --color-background-dark: #2a2a2a; /* Dark, matte, metallic-tending background */
  --color-text-primary: #1a1a1a; /* Very dark grey for primary text */
  --color-text-secondary: #555555; /* Lighter grey for labels, subheadings */
  --color-accent: #64748b; /* A sophisticated slate blue-gray */
  --color-accent-hover: #475569; /* The darker hover version */
  --color-border: #e0e0e0; /* A light, subtle grey for borders and dividers */

  /*
   * ============================================================================
   * TYPOGRAPHY
   *
   * Using a clean, modern sans-serif font stack.
   * ============================================================================
   */
  --font-sans:
    "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Segoe UI Symbol";
  /* For elegant headings */
  --font-serif-display: "Playfair Display", Georgia, serif;
  /* For readable body text */
  --font-serif-text: "Lora", Georgia, serif;

  /*
   * ============================================================================
   * SIZING & SPACING
   *
   * A consistent scale for spacing, padding, and layout.
   * ============================================================================
   */
  --border-radius: 4px; /* A subtle radius for a soft, modern look */
  --border-width-thick: 2px;
  --space-xs: 0.25rem; /* 4px */
  --space-sm: 0.5rem; /* 8px */
  --space-md: 1rem; /* 16px */
  --space-lg: 1.5rem; /* 24px */
  --space-xl: 2rem; /* 32px */
  --space-xxl: 3rem; /* 48px */
  --max-width-screen: 1600px;

  /*
   * ============================================================================
   * UI FEEDBACK COLORS
   *
   * Colors for success and error messages, adapted for the light theme.
   * ============================================================================
   */
  --color-success-text: #155724;
  --color-success-bg: #d4edda;
  --color-success-border: #c3e6cb;
  --color-error-text: #721c24;
  --color-error-bg: #f8d7da;
  --color-error-border: #f5c6cb;
}

/*
* ============================================================================
* Global Styles (nothing custom)
* ============================================================================
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 100%; /* Base font size */
}

/* Adjust font size on smaller screens for better readability */
@media (max-width: 768px) {
  html {
    font-size: 93.75%; /* 15px */
  }
}

@media (max-width: 480px) {
  html {
    font-size: 87.5%; /* 14px */
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Global Link Styling */
a {
  text-decoration: none;
  color: var(--color-accent);
  font-weight: 500;
  transition: color 0.2s ease-in-out;
}

a:hover {
  color: var(--color-accent-hover);
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: var(--space-lg) 0 var(--space-md) 0;
  color: var(--color-text-primary);
  font-weight: 600;
  line-height: 1.2;
}

/*
* ============================================================================
* Main Content Typography Override
* ============================================================================
*/

.main-content {
  font-family: var(--font-serif-text);
}

.main-content h1,
.main-content h2,
.main-content h3,
.main-content h4,
.main-content h5,
.main-content h6 {
  font-family: var(--font-serif-display);
}

.text-display {
  font-family: var(--font-serif-display);
}

/*
* ============================================================================
* Containers
* ============================================================================
*/

/* The header that sticks to the top of the page. */
.app-header {
  background-color: var(--color-background);
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
}

/* The main content area where page-specific content is rendered. */
.main-content {
  width: 100%;
  max-width: var(--max-width-screen);
  margin: 0 auto;
  padding: var(--space-lg);
}

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

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

.form-label {
  font-weight: 550;
  font-size: 1.1rem;
  color: var(--color-text-primary);
}

.form-input {
  width: 100%;
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background-color: #fff; /* A slightly different background for inputs */
  font-family: var(--font-sans); /* Use sans-serif for inputs for clarity */
  font-size: 1rem;
  line-height: 1.5; /* Ensure consistent height */
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.form-textarea {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background-color: #fff; /* A slightly different background for inputs */
  font-family: inherit;
  font-size: 1rem;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.resizable-vertical {
  resize: vertical;
}

.form-input-file {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

/* Checkbox specific styling */
.form-group-checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.form-group-checkbox label {
  color: var(--color-text-secondary);
  cursor: pointer;
}

.form-group-checkbox input[type="checkbox"] {
  cursor: pointer;
}

/* Style the "Choose"  button */
.form-input-file::file-selector-button {
  border: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--border-radius);
  background-color: #fff;
  color: var(--color-text-primary);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.form-input-file::file-selector-button:hover {
  background-color: var(--color-background);
}

/* A new set of rules to create a styled, button-like file input */
.form-input-file-styled {
  font-family: var(--font-serif-text);
  font-size: 1rem;
  color: var(--color-text-secondary);
}

.form-input-file-styled::file-selector-button {
  /* ----- Start: Copy styles from .btn ----- */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  /* ----- End: Copy styles from .btn ----- */

  /* ----- Start: Copy styles from .btn-outline ----- */
  background-color: transparent;
  color: var(--color-text-primary);
  box-shadow: 0 0 8px transparent;
  /* ----- End: Copy styles from .btn-outline ----- */

  /* ----- Start: Copy styles from .btn-pill ----- */
  border-radius: 9999px;
  /* ----- End: Copy styles from .btn-pill ----- */
}

/* The hover effect for our new styled button */
/* .form-input-file-styled::file-selector-button:hover { */
/*   box-shadow: 0 0 8px var(--color-accent); */
/* } */

/* --- Select Inputs --- */
select.form-input {
  font: var(--font-serif-text);
  color: var(--color-text-secondary);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-lg);
  border: 1px solid transparent;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--color-accent);
  color: #fff;
}

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

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--color-text-primary);
  color: var(--color-text-primary);
  box-shadow: 0 0 8px transparent;
}

.btn-outline:hover {
  box-shadow: 0 0 8px var(--color-accent);
}

.btn-pill {
  border-radius: 9999px;
}

.btn-thick-border {
  border-width: var(--border-width-thick);
}

/* Logout button */
.logout-button {
  color: var(--color-text-primary);
  padding: var(--space-sm);
  cursor: pointer;
}

.logout-button:hover {
  color: var(--color-accent-hover);
  background-color: transparent; /* Override default nav-item hover */
}

/* Icon button */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  color: var(--color-text-primary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  transition: all 0.2s ease;
}

.btn-icon i {
  font-size: 1.1rem;
}

.btn-icon:hover {
  color: var(--color-accent-hover);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

/*
* ============================================================================
* Animations
* ============================================================================
*/

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

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 1s linear infinite;
}

/* Hide the spinner by default */
.spinner-container {
  display: none;
  margin-left: var(--space-md);
}

/* Show the spinner when HTMX adds the htmx-request class */
.htmx-request .spinner-container {
  display: block;
}

.htmx-request .generate-button span {
  display: block; /* Adjust as needed, could be 'none' to hide text */
}

/*
* ============================================================================
* Pages
* ============================================================================
*/

/* --- A generic two-column page layout --- */
.page-layout--two-column {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xl);
  /* align-items: flex-start; */
}

.page-sidebar {
  flex: 1;
  min-width: 250px;
  position: sticky;
  top: 90px;
}

.page-main-content {
  flex: 4;
  min-width: 320px;
  border-left: 2px solid var(--color-text-secondary);
  padding-left: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* --- Generic page components --- */
.page-header {
  /* background-color: var(--color-background-dark); */
  /* padding: var(--space-xs) var(--space-xxl); */
  margin-bottom: var(--space-xl);
}

.page-title {
  font-size: 2rem;
  /* color: #fff; */
  margin-bottom: var(--space-xs);
}

.page-subtitle {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  /* color: #a0a0a0; */
  max-width: 70ch; /* Limits line length for readability */
}

/*
* ============================================================================
* Modal
* ============================================================================
*/

.modal {
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  padding: 0; /* Remove default padding */
  width: clamp(300px, 90vw, 500px);
}

.modal::backdrop {
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(3px);
}

.modal-content {
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.modal-title {
  margin: 0;
  font-size: 1.5rem;
  font-family: var(--font-serif-display);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

/*
* ============================================================================
* Images
* ============================================================================
*/

/* --- A generic responsive image grid --- */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-lg);
  align-items: strech;
  flex-grow: 1;
}

/* --- A generic container for an image and its caption --- */
.image-card {
  width: 100%;
  min-height: 300px;
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-sm);
  background-color: #fcfcfc;
}

.image-card figcaption {
  font-family: var(--font-serif-text);
  font-weight: 400;
  color: var(--color-text-secondary);
  text-align: center;
}

.image-card img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius);
  margin: 0 auto;
}

/*
* ============================================================================
* Components
* ============================================================================
*/

/* --- A generic bar for action buttons --- */
.action-bar {
  display: flex;
  justify-content: flex-end;
  min-height: 50px;
  gap: var(--space-md);
}
