/**
 * Base Patterns — Layer 2 of the four-layer CSS architecture.
 *
 * Every rule here targets a SINGLE class at specificity 0,1,0 (or bare
 * elements for form controls / tables). Feature CSS files override these
 * with a scoped selector like `.campaigns-list .card { ... }` at 0,2,0
 * — the cascade does the rest, no !important needed.
 *
 * What lives here:
 *   • Chrome primitives used across multiple pages: .button, .badge,
 *     .form-field, .admin-table, .message-box, .section-panel,
 *     .entity-cards-grid, .entity-card, .breadcrumbs, .detail-actions,
 *     .empty-state, .loading-state
 *   • Base form element defaults (input, textarea, select)
 *   • Base table defaults (table, th, td)
 *   • Mobile responsive overrides for all of the above
 *
 * What does NOT live here:
 *   • Design tokens (→ tokens.css, Layer 1)
 *   • Domain-specific widgets (→ components.css or per-feature CSS)
 *   • Per-feature overrides (→ campaigns.css, characters.css, etc.)
 *
 * See docs/design/architecture/static-site-adoption-plan.md §CSS sharing
 * strategy for the full four-layer model.
 */

/* =============================================================================
   Lucide SVG Icons — crisp inline rendering baseline
   ============================================================================= */

svg.lucide {
  display: inline-block;
  vertical-align: middle;
  shape-rendering: geometricPrecision;
  flex-shrink: 0;
  min-width: 0.5em;
  min-height: 0.5em;
}

/* =============================================================================
   Breadcrumbs
   ============================================================================= */

.breadcrumbs {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.5rem 0;
}

.breadcrumbs a {
  color: var(--accent-red);
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
  color: var(--accent-red-hover);
}

.breadcrumbs .separator {
  margin: 0 0.5rem;
  color: var(--border-emphasis);
}

.breadcrumbs .current {
  color: var(--text-primary);
  font-weight: 500;
}

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

.button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
  font-size: 1rem;
}

.button.primary {
  background: var(--accent-red);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--accent-red-hover);
  box-shadow: 0 4px 8px rgba(230, 57, 70, 0.4);
}

.button.secondary {
  background: transparent;
  color: var(--accent-red);
  border: 2px solid var(--accent-red);
}

.button.secondary:hover {
  background: var(--accent-red);
  color: #ffffff;
}

.button.danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}

.button.danger:hover {
  background: var(--error);
  color: #ffffff;
}

.button.success {
  background: transparent;
  color: var(--success);
  border: 1px solid var(--success);
}

.button.success:hover {
  background: var(--success);
  color: #000000;
}

.button.small {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.button:disabled, .button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button groups */
.button-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Icon buttons */
.icon-button {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.2rem;
  transition: opacity 0.2s;
}

.icon-button:hover {
  opacity: 0.7;
}

/* Button row — horizontal flex container for inline button groups */
.button-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Button actions — save/cancel row for edit forms */
.button-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

/* =============================================================================
   Form Elements — dark theme inputs
   ============================================================================= */

input, textarea, select {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  padding: 0.5rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px var(--accent-red-bg);
}

input::placeholder, textarea::placeholder {
  color: var(--text-disabled);
}

/* Prose textarea: auto-grow (height set imperatively by JS). Hide the native
   scrollbar so it reads as a continuous page; the parent container scrolls. */
textarea.prose-textarea {
  resize: vertical;
  overflow-y: hidden;
  line-height: 1.55;
  min-height: 6rem;
}

/* Wrapper positions the focus-mode trigger at the top-right corner. */
.prose-textarea-wrapper {
  position: relative;
}

.prose-textarea-wrapper textarea.prose-textarea {
  width: 100%;
  padding-right: 2.25rem;
}

.prose-focus-trigger {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.prose-textarea-wrapper:hover .prose-focus-trigger,
.prose-textarea-wrapper:focus-within .prose-focus-trigger,
.prose-focus-trigger:focus {
  opacity: 1;
}

.prose-focus-trigger:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================================
   Prose focus-mode overlay
   ============================================================ */

.prose-focus-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 2.5rem 1rem;
  overflow-y: auto;
}

.prose-focus-shell {
  width: min(70ch, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.prose-focus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.prose-focus-label {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

textarea.prose-focus-textarea {
  width: 100%;
  min-height: 50vh;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 0;
  font-family: var(--font-body, inherit);
  font-size: 1.0625rem;
  line-height: 1.7;
  resize: none;
  overflow-y: hidden;
}

textarea.prose-focus-textarea:focus {
  outline: none;
  box-shadow: none;
  border-color: transparent;
}

.prose-focus-footer {
  display: flex;
  justify-content: flex-end;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

@media (max-width: 640px) {
  .prose-focus-overlay {
    padding: 0;
  }
  .prose-focus-shell {
    width: 100%;
    border-radius: 0;
    border: none;
    min-height: 100vh;
    padding: 1rem 1rem;
    box-shadow: none;
  }
  textarea.prose-focus-textarea {
    min-height: 70vh;
  }
}

/* .form-field: standard label-above-input layout */
.form-field {
  margin-bottom: 0.75rem;
}

.form-field label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  box-sizing: border-box;
}

/* =============================================================================
   Tables — dark theme
   ============================================================================= */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
  color: var(--text-primary);
}

th {
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: left;
  padding: 0.75rem;
  border-bottom: 2px solid var(--border-primary);
  font-weight: 600;
}

td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-primary);
}

tr:hover {
  background: var(--bg-hover);
}

/* Form inputs inside admin-table cells: full-width by default */
.admin-table td input,
.admin-table td textarea,
.admin-table td select {
  width: 100%;
  box-sizing: border-box;
}

/* Narrow number inputs inside tables (e.g., rank, cost columns) */
.admin-table td input.input-narrow {
  width: 5em;
}

/* =============================================================================
   Status Badges
   ============================================================================= */

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

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

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

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

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

/* Inline badge spacing (badge immediately following inline text) */
.badge-inline {
  margin-left: 0.5rem;
}

/* List section divider headers (e.g., "My Systems" / "All Systems (Admin)") */
.list-section-header {
  margin-top: 2rem;
}

/* =============================================================================
   Alert Messages — legacy pattern; prefer .message-box
   ============================================================================= */

.alert {
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

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

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

/* =============================================================================
   Message Box
   ============================================================================= */

.message-box {
  margin: 0.75rem 0;
  padding: 0.75rem;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

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

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

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

.message-box .close-button {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.2em;
  padding: 0 0.25rem;
}

.message-box.success .close-button {
  color: var(--success);
}

.message-box.error .close-button {
  color: var(--error);
}

/* =============================================================================
   Toast Notifications
   ============================================================================= */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(400px, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  border: 1px solid;
  font-size: 0.9rem;
  animation: toast-slide-in 0.25s ease-out;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.toast-error {
  background: var(--error-bg);
  border-color: var(--error);
  color: var(--error);
}

.toast-success {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.toast-warning {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning);
}

.toast-info {
  background: var(--info-bg);
  border-color: var(--info);
  color: var(--info);
}

.toast-message {
  flex: 1;
  margin-right: 0.75rem;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  opacity: 0.7;
}

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

@keyframes toast-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* =============================================================================
   Section Panel
   ============================================================================= */

.section-panel {
  padding: 1rem;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  margin-bottom: 1rem;
  background: var(--bg-primary);
}

.section-panel h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--accent-red);
  padding-bottom: 0.5rem;
  color: var(--text-primary);
}

/* =============================================================================
   Empty State / Loading State
   ============================================================================= */

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem;
}

.loading-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem;
}

/* =============================================================================
   Detail Actions — bottom-of-page action bar for detail pages
   ============================================================================= */

.detail-actions {
  margin-top: 2rem;
  margin-bottom: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-primary);
  display: flex;
  gap: 0.5rem;
}

/* Detail actions inline — smaller action bar within content */
.detail-actions-inline {
  margin-top: 1rem;
}

/* Action row — inline action container with bottom spacing */
.action-row {
  margin-bottom: 1rem;
}

/* =============================================================================
   Entity Cards Grid — the shared list layout for all domain pages
   ============================================================================= */

.entity-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.75rem;
}

/* =============================================================================
   Entity Card — the shared card component for all entity list pages
   ============================================================================= */

.entity-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  transition: border-color 0.15s, background 0.15s;
}

.entity-card:hover {
  background: var(--bg-hover);
}

a.entity-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

a.entity-card:hover {
  text-decoration: none;
}

.entity-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.entity-card-header h4 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.entity-card-header h4 a {
  color: var(--text-primary);
  text-decoration: none;
}

.entity-card-header h4 a:hover {
  color: var(--info);
}

.entity-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex-shrink: 0;
}

.entity-card-description,
.entity-card-body {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  line-height: 1.4;
}

.entity-card-gm-notes {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0 0 0.5rem;
  font-style: italic;
  line-height: 1.3;
}

.entity-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

a.entity-card .entity-card-meta {
  margin-top: auto;
}

.entity-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.entity-card-thumbnail {
  max-width: 120px;
  max-height: 80px;
  border-radius: 4px;
  border: 1px solid var(--border-primary);
  margin-bottom: 0.5rem;
}

.entity-card-stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.entity-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

/* =============================================================================
   Mobile Responsive — Base Components
   ============================================================================= */

@media (max-width: 480px) {
  /* Tables: constrain to viewport */
  .admin-table {
    table-layout: fixed;
    width: 100%;
  }

  .hide-mobile {
    display: none;
  }

  /* First column: name wraps; second column: status fits */
  .admin-table td:first-child,
  .admin-table th:first-child {
    width: 70%;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .admin-table td:nth-child(2),
  .admin-table th:nth-child(2) {
    width: 30%;
    white-space: nowrap;
  }

  /* Forms: full-width inputs */
  .form-field input,
  .form-field select,
  .form-field textarea {
    width: 100%;
    max-width: 100%;
  }

  /* Buttons: ensure touch-friendly minimum height */
  .button {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    min-height: 44px;
  }

  .button.small {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    min-height: 36px;
  }

  /* Inputs & selects: touch-friendly height */
  input, textarea, select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  /* Button row: wrap on phone */
  .button-row {
    flex-wrap: wrap;
  }

  /* Button group: wrap on phone */
  .button-group {
    flex-wrap: wrap;
  }

  /* Button actions (save/cancel): full width */
  .button-actions {
    flex-direction: column;
  }
  .button-actions .button {
    width: 100%;
    text-align: center;
  }

  /* Detail actions: stack vertically */
  .detail-actions .button {
    flex: 1;
    min-width: 0;
    text-align: center;
  }

  /* Breadcrumbs: wrap */
  .breadcrumbs {
    flex-wrap: wrap;
    font-size: 0.85rem;
  }

  /* Detail actions: wrap buttons */
  .detail-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Section panels: tighter padding */
  .section-panel {
    padding: 0.75rem;
  }

  /* Badges: smaller */
  .badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
  }
}

@media (max-width: 680px) {
  .entity-cards-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .entity-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

/* =============================================================================
   .prose — read-time rendered prose (paired with web-util/markdown).
   Wraps the Hiccup output of render-markdown. Inherits typography + tokens
   from the global stack so rendered prose feels native to the design system.
   See docs/operations/prose-textareas.md (Phase 3a) and
   docs/design/architecture/free-form-content.md (Stage 1).
   ============================================================================= */

.prose {
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.55;
}

.prose .prose-render > * + * {
  margin-top: 0.75rem;
}

.prose p {
  margin: 0;
  white-space: pre-wrap; /* preserve intentional line breaks within a paragraph */
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  font-family: var(--font-display);
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
}

.prose h1 { font-size: 1.6rem; }
.prose h2 { font-size: 1.35rem; }
.prose h3 { font-size: 1.15rem; }
.prose h4 { font-size: 1.0rem;  }
.prose h5 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.prose h6 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }

.prose ul,
.prose ol {
  margin: 0;
  padding-left: 1.5rem;
}

.prose li {
  margin: 0.15rem 0;
}

.prose li > p {
  margin: 0;
}

.prose blockquote {
  margin: 0;
  padding: 0.4rem 0.9rem;
  border-left: 3px solid var(--border-emphasis, var(--accent-red));
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-style: italic;
  white-space: pre-wrap;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-secondary);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  color: var(--text-primary);
}

.prose strong {
  color: var(--text-primary);
  font-weight: 700;
}

.prose em {
  font-style: italic;
}

.prose a {
  color: var(--accent-red);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

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

/* Empty-state fallback (rendered when prose-display is given an empty
   value but a non-blank :empty-text). */
.prose-empty .prose-empty-text {
  color: var(--text-muted);
  font-style: italic;
  margin: 0;
}

/* .prose-compact — tight variant for admin-table cells and other dense
   contexts where the default .prose paragraph rhythm looks chunky. */
.prose.prose-compact {
  line-height: 1.4;
}

.prose.prose-compact .prose-render > * + * {
  margin-top: 0.35rem;
}

.prose.prose-compact ul,
.prose.prose-compact ol {
  padding-left: 1.2rem;
}

.prose.prose-compact li {
  margin: 0.05rem 0;
}
