/**
 * Component Library - IllTellYou Platform
 *
 * Reusable UI components with consistent styling.
 * Import design tokens first.
 */

@import url('./design-tokens.css');

/* ============================================
   LAYOUT SYSTEM
   ============================================ */

/**
 * PC Layout: Logo left (fixed width), Content right (flexible)
 * Mobile Layout: Logo top, Content bottom (stacked vertically)
 */

body {
  font-family: var(--font-family);
  background-color: var(--color-bg-primary);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Desktop Layout: 50/50 split - Logo left half, Content right half */
@media (min-width: 769px) {
  body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: 100vh;
  }

  .header {
    width: 50%;
    flex-shrink: 0;
    background: var(--color-bg-secondary);
    border-right: 2px solid var(--color-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    box-sizing: border-box;
  }

  .container {
    width: 50%;
    flex-shrink: 0;
    overflow-y: auto;
    padding: var(--space-2xl);
    box-sizing: border-box;
  }

  .logo {
    width: 80%;
    max-width: 500px;
    height: auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    margin-bottom: var(--space-xl);
  }

  .page-title {
    font-size: var(--font-size-2xl);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-semibold);
    text-align: center;
    margin: 0;
  }
}

/* Mobile Layout: Vertical stack (like current teacher service) */
@media (max-width: 768px) {
  body {
    display: flex;
    flex-direction: column;
  }

  .header {
    width: 100%;
    background: var(--color-bg-secondary);
    border-bottom: 2px solid var(--color-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-lg) var(--space-md);
    box-sizing: border-box;
  }

  .container {
    flex: 1;
    padding: var(--space-md);
    box-sizing: border-box;
  }

  .logo {
    width: var(--logo-size-mobile);
    height: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-sm);
  }

  .page-title {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-semibold);
    text-align: center;
    margin: 0;
    margin-top: var(--space-sm);
  }
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  padding: var(--space-md) var(--space-lg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
  min-width: 200px;
  box-sizing: border-box;
  font-family: var(--font-family);
  text-align: center;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
  transition: transform 0.1s ease;
}

.btn:disabled {
  background: var(--color-disabled) !important;
  color: #909090 !important;
  cursor: not-allowed;
  border-color: var(--color-border) !important;
  box-shadow: none !important;
  transform: none !important;
}

.btn-primary,
.btn-success,
.action-btn,
.ask-text-btn,
.ask-voice-btn,
.generate-text-btn,
.generate-audio-btn {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary-dark);
}

.btn-primary:hover:not(:disabled),
.btn-success:hover:not(:disabled),
.action-btn:hover:not(:disabled),
.ask-text-btn:hover:not(:disabled),
.ask-voice-btn:hover:not(:disabled),
.generate-text-btn:hover:not(:disabled),
.generate-audio-btn:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Responsive button sizing */
@media (max-width: 480px) {
  .btn {
    min-width: auto;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
  }
}

@media (max-width: 375px) {
  .btn {
    padding: var(--space-sm);
  }
}

/* ============================================
   SECTIONS
   ============================================ */

.section,
.author-selection,
.input-section,
.teacher-section,
.content-sources-section,
.upload-section,
.voice-section,
.response-section {
  margin-bottom: var(--space-lg);
  padding: var(--space-xl);
  background: var(--color-section-bg);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-section-border);
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .section,
  .author-selection,
  .input-section,
  .teacher-section,
  .content-sources-section,
  .upload-section,
  .voice-section,
  .response-section {
    padding: var(--space-lg);
  }
}

.section-title,
.section h3 {
  display: block;
  margin-bottom: var(--space-md);
  color: var(--color-text-secondary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

.form-input,
input[type="text"],
textarea,
select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  box-sizing: border-box;
  margin-bottom: var(--space-sm);
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast);
}

.form-input:focus,
input[type="text"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

/* Prevent iOS zoom on input focus */
@media (max-width: 768px) {
  input[type="text"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

label {
  display: block;
  margin-bottom: var(--space-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
}

/* ============================================
   STATUS MESSAGES
   ============================================ */

.status-message {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  margin: var(--space-xs) 0;
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.status-message:empty {
  display: none;
}

/* Accessibility: Icons AND text for status */
.status-message::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.status-success {
  background: rgba(40, 167, 69, 0.15);
  color: var(--color-success-dark);
  border: 1px solid rgba(40, 167, 69, 0.4);
}

.status-success::before {
  content: '✓';
  font-weight: bold;
  color: var(--color-success);
}

.status-error {
  background: rgba(220, 53, 69, 0.15);
  color: var(--color-error-dark);
  border: 1px solid rgba(220, 53, 69, 0.4);
}

.status-error::before {
  content: '✗';
  font-weight: bold;
  color: var(--color-error);
}

.status-processing,
.status-info {
  background: rgba(0, 123, 255, 0.15);
  color: var(--color-info-dark);
  border: 1px solid rgba(0, 123, 255, 0.4);
}

.status-processing::before {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}

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

/* ============================================
   PROGRESS INDICATORS
   ============================================ */

.progress-bar {
  width: 100%;
  height: 30px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 2px solid var(--color-border);
  overflow: hidden;
  margin-bottom: var(--space-sm);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-success) 0%, #20c997 100%);
  border-radius: calc(var(--radius-lg) - 2px);
  transition: width var(--transition-slow);
  width: 0%;
}

.progress-text {
  text-align: center;
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

/* ============================================
   FILE INPUT STYLING
   ============================================ */

.file-input {
  display: none;
}

.file-input-wrapper {
  position: relative;
  margin-bottom: var(--space-md);
}

.file-input-button {
  display: inline-block;
  padding: var(--space-md) var(--space-lg);
  background: linear-gradient(145deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  border: 2px solid var(--color-primary-dark);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.file-input-button:hover {
  background: linear-gradient(145deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.file-name {
  display: block;
  margin-top: var(--space-xs);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

/* ============================================
   BUTTON CONTAINERS
   ============================================ */

.button-container,
.choice-buttons {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

/* Stack buttons on mobile */
@media (max-width: 480px) {
  .button-container,
  .choice-buttons {
    flex-direction: column;
    gap: var(--space-sm);
  }
}

/* ============================================
   AUTHOR INFO
   ============================================ */

.author-info {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
  line-height: 1.6;
}

/* ============================================
   CONTENT CARDS (Teacher service)
   ============================================ */

.content-card {
  background: var(--color-bg-secondary);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  transition: all var(--transition-base);
}

.content-card:hover {
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.content-card-title {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-xs);
}

.content-card-meta {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

/* ============================================
   OUTPUT SECTIONS
   ============================================ */

.output-choice-section,
.audio-section {
  background: var(--color-bg-secondary);
  border: 2px solid var(--color-border);
  padding: var(--space-xl);
  border-radius: var(--radius-md);
  margin-top: var(--space-lg);
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.choice-header,
.audio-header {
  margin-bottom: var(--space-lg);
}

.choice-header h3,
.audio-header h3 {
  color: var(--color-text-primary);
  font-size: var(--font-size-xl);
  margin: 0;
}

.speaker-name {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

.audio-player {
  width: 100%;
  margin-top: var(--space-md);
}

/* ============================================
   ACCESSIBILITY HELPERS
   ============================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.focus-visible:focus {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}

/* Ensure minimum touch target size (44x44px) */
@media (max-width: 768px) {
  button,
  .btn,
  .file-input-button,
  select {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ============================================
   STATS SECTION (Teacher)
   ============================================ */

.stats-section {
  background: var(--color-bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--color-success);
  margin-top: var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* ============================================
   UTILITIES
   ============================================ */

.is-mobile .choice-buttons {
  flex-direction: column;
}

.is-small-screen .button-container button {
  padding: var(--space-sm);
  font-size: var(--font-size-sm);
}

.is-small-screen .section-heading {
  font-size: var(--font-size-base);
}
