/* Reset et base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Dark Fantasy Theme - 7th Citadel */
  --bg-dark: #0d0d14;
  --bg-card: #151520;
  --bg-input: #1a1a28;
  --text-primary: #d4d4dc;
  --text-secondary: #7a7a8c;
  --accent: #c9a227;
  --accent-hover: #e6b82d;
  --accent-glow: rgba(201, 162, 39, 0.4);
  --torch-orange: #ff6b35;
  --torch-glow: rgba(255, 107, 53, 0.3);
  --success: #3d9970;
  --border: #2a2a3a;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  --rune-color: #4a4a6a;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at top, rgba(201, 162, 39, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(255, 107, 53, 0.02) 0%, transparent 50%);
  color: var(--text-primary);
  line-height: 1.5;
}

/* App container - centré et stacké sans scroll global */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0;
  position: relative;
}

/* Header */
.app-header {
  text-align: center;
  padding: 1.25rem 1rem;
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-dark) 100%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.app-header::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  letter-spacing: 1px;
}

.app-header .subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 0.25rem;
}

/* Navigation tabs */
.tabs {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 0.85rem 0.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tab:hover {
  color: var(--text-primary);
  background: rgba(201, 162, 39, 0.1);
}

.tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

/* Contenu principal - scroll interne uniquement */
.content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 1rem;
}

.tab-content.active {
  display: block;
}

/* Cards */
.card {
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(21, 21, 32, 0.8) 100%);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rune-color), transparent);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* Listes */
.list {
  margin-bottom: 1rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.list-item-info {
  flex: 1;
}

.list-item-name {
  font-weight: 500;
}

.list-item-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.list-item-actions {
  display: flex;
  gap: 0.5rem;
}

/* Sous-liste pour les valeurs d'options */
.values-list {
  margin-top: 0.5rem;
  padding-left: 1rem;
}

.value-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: rgba(233, 69, 96, 0.2);
  border-radius: 12px;
  font-size: 0.8rem;
  margin: 0.25rem 0.25rem 0.25rem 0;
}

.value-delete {
  cursor: pointer;
  opacity: 0.6;
}

.value-delete:hover {
  opacity: 1;
}

/* Formulaires */
.form-inline {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-row {
  display: flex;
  gap: 0.5rem;
}

.form-row input,
.form-row select {
  flex: 1;
}

input, select {
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

input::placeholder {
  color: var(--text-secondary);
}

/* Boutons */
.btn {
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
  background: var(--bg-input);
  color: var(--text-primary);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #a88520);
  border: none;
  color: #0d0d14;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), var(--accent));
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.4rem;
}

.btn-icon:hover {
  color: var(--torch-orange);
}

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

/* Statut */
.status {
  text-align: center;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.status.ok {
  background: rgba(78, 204, 163, 0.2);
  color: var(--success);
}

.status.error {
  background: rgba(233, 69, 96, 0.2);
  color: var(--accent);
}

/* Hints */
.hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.hint.ok {
  color: var(--success);
}

.hint.error {
  color: var(--torch-orange);
}

/* Placeholder */
.placeholder-text {
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem;
  font-style: italic;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.modal-content h3 {
  margin-bottom: 1rem;
  color: var(--accent);
}

.modal-content input {
  width: 100%;
  margin-bottom: 0.75rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Type badge */
.type-badge {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  background: rgba(233, 69, 96, 0.3);
  border-radius: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  margin-left: 0.5rem;
}

/* Vide */
.empty-message {
  color: var(--text-secondary);
  text-align: center;
  padding: 1rem;
  font-size: 0.9rem;
}

/* === SCANNER === */

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

.card-header h2 {
  margin: 0;
  padding: 0;
  border: none;
}

.header-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-upload {
  background: var(--bg-input);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.4rem 0.75rem;
  line-height: 1;
}

.btn-upload:hover {
  background: var(--accent);
  color: var(--bg-dark);
}

.input-large {
  font-size: 1.1rem;
  padding: 0.75rem;
}

/* Quick options */
.quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.quick-option {
  flex: 1;
  min-width: 120px;
}

.quick-option label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.quick-option select,
.quick-option input[type="text"] {
  width: 100%;
}

.quick-option input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.quick-option input[type="checkbox"] {
  width: auto;
  margin-right: 0.5rem;
}

.slider-value {
  color: var(--accent);
  font-weight: 600;
}

/* Pages list */
.pages-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.page-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--bg-input);
  border-radius: 4px;
}

.page-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.page-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.page-label {
  font-weight: 500;
}

.page-status {
  font-size: 0.75rem;
}

.status-pending { color: var(--text-secondary); }
.status-processing { color: #f0a500; }
.status-done { color: var(--success); }
.status-error { color: var(--accent); }

.page-actions {
  display: flex;
  gap: 0.25rem;
}

/* Progress bar */
.progress-bar {
  margin-bottom: 1rem;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  height: 24px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width 0.3s;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 500;
}

/* OCR textarea */
#ocr-text {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

#ocr-text:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-full {
  width: 100%;
}

.btn-flex {
  flex: 1;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.btn-secondary {
  background: linear-gradient(135deg, #4a4a6a, #3a3a5a);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #5a5a7a, #4a4a6a);
  box-shadow: 0 0 10px var(--accent-glow);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.analyze-result {
  background: rgba(201, 162, 39, 0.1);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.analyze-result .suggestion-title {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.analyze-result .suggestion-details {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Bouton Scanner spécial - visible mais compact */
.btn-scanner {
  background: linear-gradient(135deg, var(--torch-orange), #cc4a1a);
  border: none;
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow:
    0 0 15px var(--torch-glow),
    0 3px 8px rgba(0, 0, 0, 0.4);
  animation: torch-pulse 2s ease-in-out infinite;
}

.btn-scanner:hover {
  background: linear-gradient(135deg, #ff7b45, var(--torch-orange));
  box-shadow:
    0 0 25px var(--torch-glow),
    0 4px 12px rgba(0, 0, 0, 0.5);
  transform: translateY(-1px);
}

@keyframes torch-pulse {
  0%, 100% { box-shadow: 0 0 20px var(--torch-glow), 0 4px 12px rgba(0, 0, 0, 0.4); }
  50% { box-shadow: 0 0 30px var(--torch-glow), 0 4px 12px rgba(0, 0, 0, 0.4); }
}

/* === CROP MODAL === */

.modal-crop-content {
  background: var(--bg-dark);
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.crop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.crop-header span {
  font-weight: 500;
  color: var(--accent);
}

.crop-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1rem;
  background: #000;
}

.crop-wrapper {
  position: relative;
  display: inline-block;
}

#crop-canvas {
  display: block;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(233, 69, 96, 0.15);
  cursor: move;
  touch-action: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
}

.crop-handle-nw { top: -10px; left: -10px; cursor: nwse-resize; }
.crop-handle-ne { top: -10px; right: -10px; cursor: nesw-resize; }
.crop-handle-sw { bottom: -10px; left: -10px; cursor: nesw-resize; }
.crop-handle-se { bottom: -10px; right: -10px; cursor: nwse-resize; }

.crop-actions {
  padding: 1rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

/* === RESULT === */

.result-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.result-summary {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: 0.5rem;
  background: rgba(233, 69, 96, 0.1);
  border-radius: 4px;
}

.result-text {
  background: var(--bg-input);
  padding: 1rem;
  border-radius: 4px;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.result-audio {
  padding-top: 0.5rem;
}

.result-audio audio {
  width: 100%;
  height: 48px;
}

/* === HISTORY === */

.search-input {
  width: 150px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 60vh;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-input);
  border-radius: 6px;
  padding: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.history-item:hover {
  background: rgba(233, 69, 96, 0.15);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-item-number {
  font-weight: 600;
  color: var(--accent);
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.history-item-archetype {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.history-item-preview {
  font-size: 0.85rem;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item-audio {
  margin-top: 0.5rem;
}

.history-item-audio audio {
  width: 100%;
  height: 36px;
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 400px) {
  .form-inline {
    flex-direction: column;
  }

  .form-inline input,
  .form-inline .btn {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
  }

  .quick-options {
    flex-direction: column;
  }

  .quick-option {
    min-width: 100%;
  }
}
