/* === CUSTOM PROPERTIES === */
:root {
  --color-bg: #ffffff;
  --color-text: #1a1a1a;
  --color-primary: #0055a5;
  --color-primary-hover: #003d7a;
  --color-primary-text: #ffffff;
  --color-error: #c41e1e;
  --color-error-bg: #fef2f2;
  --color-success: #15713a;
  --color-border: #5a5a5a;
  --color-border-light: #cccccc;
  --color-focus: #0055a5;
  --color-disabled-bg: #e0e0e0;
  --color-disabled-text: #4a4a4a;
  --color-backdrop: rgba(0, 0, 0, 0.6);
  --color-surface: #f5f5f5;
}

/* === RESET & BASE === */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
}

/* === SKIP LINK === */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: 0.75rem 1.5rem;
  background: var(--color-primary);
  color: var(--color-primary-text);
  text-decoration: none;
  font-weight: 600;
  z-index: 2000;
}

.skip-link:focus {
  top: 0;
}

/* === FOCUS STYLES === */
*:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

/* === VISUALLY HIDDEN (screen-reader only) === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === HEADER === */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-border-light);
  margin-bottom: 1.5rem;
}

header h1 {
  margin: 0;
  font-size: 1.75rem;
}

/* === BUTTONS === */
button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px; /* D03 */
  background: var(--color-primary);
  color: var(--color-primary-text);
  cursor: pointer;
  transition: background-color 0.15s ease; /* D06 */
}

button:hover {
  background: var(--color-primary-hover);
}

button:disabled {
  background: var(--color-disabled-bg);
  color: var(--color-disabled-text);
  cursor: not-allowed;
}

/* === FORM ELEMENTS === */
label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--color-border);
  border-radius: 8px; /* D03 */
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}

textarea {
  resize: vertical;
}

input[type="file"] {
  padding: 0.5rem;
  border-style: dashed;
}

[aria-invalid="true"] {
  border-color: var(--color-error);
}

.form-group {
  margin-bottom: 1.5rem;
}

.help-text {
  font-size: 0.875rem;
  color: var(--color-border);
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.error-message {
  color: var(--color-error);
  font-weight: 600;
  margin-top: 0.25rem;
}

/* === UPLOADED IMAGES LIST === */
#uploaded-images-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

#uploaded-images-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--color-border-light);
}

#uploaded-images-list li:last-child {
  border-bottom: none;
}

#uploaded-images-list .remove-btn {
  min-height: 44px; /* A01: iguala el mínimo de 44 px del resto de botones */
  padding: 0.25rem 0.625rem;
  font-size: 0.875rem;
  background: var(--color-error);
  flex-shrink: 0;
}

#uploaded-images-list .remove-btn:hover {
  background: #a01919;
}

#uploaded-images-list .file-name {
  flex: 1;
  word-break: break-all;
}

/* === STORYTELLING === */
#story-section {
  margin-bottom: 1.5rem;
}

#story-section p {
  margin: 0 0 0.75rem;
}

#story-section p:last-child {
  margin-bottom: 0;
}

/* === HOW IT WORKS (details/summary) === */
#how-it-works {
  margin-bottom: 2rem;
  border: 2px solid var(--color-border-light);
  border-radius: 12px; /* D03 */
  overflow: hidden;
}

#how-it-works summary {
  padding: 0.875rem 1.25rem;
  font-weight: 600;
  font-size: 1.125rem;
  cursor: pointer;
  background: var(--color-surface);
  list-style: revert;
  min-height: 44px;
  display: list-item;
}

#how-it-works summary:hover {
  background: var(--color-border-light);
}

.details-content {
  padding: 1rem 1.25rem 1.25rem;
}

.details-content h3 {
  margin: 1.25rem 0 0.375rem;
  font-size: 1rem;
}

.details-content h3:first-child {
  margin-top: 0;
}

.details-content p {
  margin: 0 0 0.5rem;
}

/* === RESULTS SECTION === */
#results-section {
  background: var(--color-surface);
  border: 2px solid var(--color-border-light);
  border-radius: 12px; /* D03 */
  padding: 1.5rem;
  margin-bottom: 2rem;
}

#results-section h2 {
  margin-top: 1.5rem;
}

#results-section h2:first-child {
  margin-top: 0;
}

#generated-image {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--color-border-light);
  border-radius: 4px;
  margin: 0.5rem 0;
}

#alt-text-display {
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: 4px;
  padding: 0.75rem;
  font-style: italic;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
}

/* === LOADING INDICATOR === */
#loading-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--color-surface);
  border-radius: 4px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* === DIALOG === */
/* D04: starts invisible; .is-open triggers the entrance animation */
[role="dialog"] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  background: var(--color-bg);
  padding: 2rem;
  border-radius: 16px; /* D03 */
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  z-index: 1001;
  max-width: 500px;
  width: 90%;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease; /* D04 */
}

[role="dialog"].is-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

[role="dialog"] h2 {
  margin-top: 0;
}

.dialog-body {
  margin-bottom: 1.5rem;
}

.dialog-actions {
  display: flex;
  gap: 0.75rem;
}

.dialog-actions button:last-child {
  background: transparent;
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.dialog-actions button:last-child:hover {
  background: var(--color-surface);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-backdrop);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease; /* D04 */
}

.backdrop.is-open {
  opacity: 1;
}

/* === ERROR DISPLAY IN RESULTS === */
.error-container {
  background: var(--color-error-bg);
  border: 2px solid var(--color-error);
  border-radius: 12px; /* D03 */
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.error-container h2 {
  margin-top: 0;
}

#error-debug {
  margin-top: 1rem;
  border-top: 1px solid var(--color-error);
  padding-top: 0.75rem;
}

#error-debug summary {
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--color-error);
}

#error-debug-content {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--color-text);
}

/* === FOOTER === */
footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--color-border-light);
  text-align: center;
}

footer p {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
}

.social-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
}

.social-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--color-text);
  border-radius: 50%;
  transition: color 0.2s;
}

.social-links a:hover {
  color: var(--color-primary);
}

/* === RESPONSIVE === */
@media (max-width: 480px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-actions {
    flex-direction: column;
  }

  .dialog-actions {
    flex-direction: column;
  }

  [role="dialog"] {
    width: 95%;
    padding: 1.25rem;
  }
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--color-primary);
    opacity: 0.7;
  }

  /* D04: desactivar animaciones del diálogo para usuarios con preferencia de movimiento reducido */
  [role="dialog"],
  .backdrop {
    transition: none;
  }
}
