/**
 * Components CSS - Reusable UI components
 * Based on ADR-0007: Page Layout and Navigation System
 * Themed via CSS custom properties
 */

/* 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;
}

/* Forms - 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: 'Lato', sans-serif;
}

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

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

/* Nested editor sections in catalog cards (ranks, enhancements, etc.) */
.catalog-nested-editor {
  margin-top: 0.5rem;
}

.catalog-nested-editor > label {
  font-weight: bold;
  display: block;
  margin-bottom: 0.5rem;
}

/* Catalog page layout helpers */
.catalog-flex-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.catalog-spacer-top {
  margin-top: 1rem;
}

.catalog-subtitle {
  color: #808080;
  margin-bottom: 1.5rem;
}

/* 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);
}

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

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

/* 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);
}

/* Dice roller */
.dice-roller-controls {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

.dice-roller-controls .form-field {
  flex: 0 0 auto;
}

.dice-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding-bottom: 0.5rem;
}

.dice-result {
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
}

.dice-total {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.dice-breakdown {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.dice-group {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.die-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--bg-primary);
  border: 2px solid var(--border-primary);
  border-radius: 4px;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.die-face.wild {
  border-color: var(--warning);
  color: var(--warning);
}

.die-face.complication {
  border-color: var(--error);
  color: var(--error);
}

.dice-pips {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}

.dice-history {
  margin-top: 1.5rem;
}

/* Tags */
.tags-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.form-field .tags-inline {
  margin-top: 0.5rem;
}

.tags-active {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-primary);
}

.tag-removable {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.tag-removable .tag-remove {
  cursor: pointer;
  opacity: 0.6;
  font-size: 0.75em;
  line-height: 1;
}

.tag-removable .tag-remove:hover {
  opacity: 1;
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.tag-suggestion {
  cursor: pointer;
  opacity: 0.7;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
}

.tag-suggestion:hover {
  opacity: 1;
}

.tag-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.25rem;
}

.tag-input-row input {
  flex: 1;
  max-width: 250px;
}

/* 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 */
.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem;
}

/* Detail Actions — consistent 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;
}

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

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

/* Banner Image — overview page hero */
.banner-image-section {
  margin-bottom: 1.5rem;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-primary);
}

.banner-image {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

/* Overview Field Sections — public note, URLs, private notes */
.overview-field-section {
  margin-bottom: 1.25rem;
}

.overview-field-section h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.overview-field-text {
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0;
  white-space: pre-wrap;
}

.urls-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.urls-list li a {
  color: var(--accent-red);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.urls-list li a:hover {
  background: var(--bg-hover);
  border-color: var(--accent-red);
}

.private-notes-section {
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: rgba(96, 165, 250, 0.05);
  border: 1px solid rgba(96, 165, 250, 0.15);
  border-radius: 4px;
}

.private-notes-section h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.85rem;
  color: var(--info);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Overview Fields Edit Form */
.overview-fields-edit {
  margin-bottom: 1.5rem;
}

.overview-fields-edit h3 {
  margin: 0 0 1rem 0;
}

.url-entries {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.url-entry-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.url-entry-row input:first-child {
  flex: 1;
  max-width: 200px;
}

.url-entry-row input:nth-child(2) {
  flex: 2;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

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

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

/* Image Upload Components */
.image-file-input {
  display: none;
}

.image-preview {
  max-width: 300px;
  max-height: 200px;
  border-radius: 6px;
  border: 1px solid var(--border-primary);
  object-fit: cover;
}

.image-placeholder {
  width: 300px;
  height: 160px;
  border-radius: 6px;
  border: 2px dashed var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
}

.image-placeholder .placeholder-icon {
  font-size: 2rem;
  color: var(--text-muted);
}

.image-field {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
}

.image-field-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Banner-sized image variant */
.image-field.banner .image-preview,
.image-field.banner .image-placeholder {
  max-width: 100%;
  width: 100%;
  height: 200px;
}

.image-field.banner {
  max-width: 100%;
}

/* Small avatar variant */
.image-field.avatar .image-preview {
  width: 80px;
  height: 80px;
  max-width: 80px;
  max-height: 80px;
  border-radius: 50%;
}

.image-field.avatar .image-placeholder {
  width: 80px;
  height: 80px;
  border-radius: 50%;
}

.image-field.avatar {
  max-width: 120px;
  align-items: center;
}

/* Skill Groups (consolidated from characters.css) */
.skill-group {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
}

.skill-group-locked {
  opacity: 0.6;
}

.skill-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-primary);
}

.skill-group-attr-code {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Info Tip — inline contextual help icon with tooltip */
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 0.4rem;
  cursor: help;
}

.info-tip-icon {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.15s;
}

.info-tip:hover .info-tip-icon {
  color: var(--info);
}

.info-tip-content {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 0.5rem);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: normal;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.info-tip-content::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border-primary);
}

/* About This Page — collapsible help block */
.about-this-page {
  margin-top: 2rem;
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  background: var(--bg-primary);
}

.about-this-page-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: color 0.15s;
}

.about-this-page-header:hover {
  color: var(--text-secondary);
}

.about-this-page-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.about-this-page-title {
  flex: 1;
  font-weight: 500;
}

.about-this-page-toggle {
  font-size: 1rem;
  font-weight: 600;
}

.about-this-page-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border-primary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.about-this-page-body p {
  margin: 0.75rem 0 0;
}

/* Entity Import Wizard */
.entity-import-wizard textarea {
  width: 100%;
  font-family: monospace;
  font-size: 0.9rem;
}

.entity-import-review {
  max-height: 400px;
  overflow-y: auto;
}

.entity-import-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-primary);
}

.entity-import-item:last-child {
  border-bottom: none;
}

.entity-import-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* =============================================================================
   Mobile Responsive — Common 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: slightly smaller */
  .button {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }

  .button.small {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
  }

  /* 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;
  }

  /* Image fields: responsive */
  .image-placeholder,
  .image-field {
    max-width: 100%;
  }

  /* Info tip: narrower on mobile */
  .info-tip-content {
    max-width: 220px;
    font-size: 0.75rem;
  }

  /* Dice roller: stack controls */
  .dice-roller-controls {
    flex-wrap: wrap;
  }

  .dice-roller-controls .form-field {
    flex: 1 1 100%;
  }

  .dice-result {
    padding: 1rem;
  }
}

/* =============================================================================
   Tier Badges — subscription tier indicators on features
   ============================================================================= */

.tier-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.tier-badge-gm {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.tier-badge-designer {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.tier-badge-addon {
  background: rgba(96, 165, 250, 0.15);
  color: var(--info);
  border: 1px solid rgba(96, 165, 250, 0.3);
}

/* =============================================================================
   Account Deletion Section
   ============================================================================= */

.account-deletion-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-primary);
}

.account-deletion-section h3 {
  color: var(--error);
}

.deletion-details {
  margin-top: 1rem;
}

.deletion-summary {
  margin: 1rem 0;
}

.deletion-summary h4 {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.deletion-summary ul {
  list-style: disc;
  padding-left: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.deletion-summary li {
  margin-bottom: 0.25rem;
}

.deletion-confirm {
  margin-top: 1rem;
}

.deletion-confirm p {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.deletion-confirm input {
  max-width: 320px;
  margin-bottom: 0.75rem;
}
