/* YouTube Downloader Web — light theme */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e2e5ef;
  --text: #1a1d26;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

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

.hidden {
  display: none !important;
}

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

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

/* Screens */
.screen {
  min-height: 100vh;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.5rem;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  font-size: 1.25rem;
}

.brand-icon-sm {
  width: 32px;
  height: 32px;
  font-size: 0.875rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  font-size: 1.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  background: var(--success-light);
  color: var(--success);
  border-radius: 999px;
  font-weight: 500;
}

.sse-status {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
}

.sse-status-ok {
  color: var(--success);
  background: var(--success-light);
}

.sse-status-reconnect {
  color: var(--warning);
  background: var(--warning-light);
  animation: pulse 1.5s ease-in-out infinite;
}

.sse-status-off {
  color: var(--text-muted);
  background: var(--bg);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled,
.btn.loading {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled):not(.loading) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled):not(.loading) {
  background: var(--bg);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled):not(.loading) {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0.375rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
}

/* Forms */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
}

.form-success {
  color: var(--success);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.login-form .btn {
  margin-top: 0.75rem;
}

/* Add section */
.add-section {
  padding: 1.25rem;
}

.add-section h2,
.preview-section h2,
.ready-section h2,
.queue-section h2,
.history-section h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
}

.add-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.hint {
  font-size: 0.8125rem;
}

/* Preview cards */
.preview-section h2 {
  margin-bottom: 0.75rem;
}

.preview-card {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.preview-card-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.preview-thumb {
  width: 160px;
  height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg);
  flex-shrink: 0;
}

.preview-meta {
  flex: 1;
  min-width: 0;
}

.preview-meta h3 {
  margin: 0 0 0.375rem;
  font-size: 1rem;
  line-height: 1.35;
  word-break: break-word;
}

.preview-meta p {
  margin: 0.125rem 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.preview-error {
  padding: 0.75rem 1rem;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.format-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.format-tab {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
}

.format-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.format-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.format-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 220px;
  overflow-y: auto;
}

.format-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.format-option:hover:not(.disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.format-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.format-option.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.format-option input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.format-label {
  font-size: 0.875rem;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.format-main-line {
  display: block;
  font-weight: 600;
}

.format-sub-line {
  display: block;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.format-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--success);
  background: var(--success-light);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.format-option.recommended:not(.disabled) {
  border-color: var(--success);
}

.ffmpeg-hint {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--warning);
  background: var(--warning-light);
  border-radius: var(--radius-sm);
}

.format-label small {
  display: block;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.preview-actions {
  margin-top: 0.5rem;
}

/* Section headers */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.section-header h2 {
  margin: 0;
}

.section-subtitle {
  font-size: 0.8125rem;
}

.ready-section,
.queue-section,
.history-section {
  padding: 1.25rem;
}

.ready-section {
  border-left: 4px solid var(--success);
}

.queue-section {
  border-left: 4px solid var(--primary);
}

.history-section {
  border-left: 4px solid var(--border);
}

/* Task items */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.task-item {
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.task-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.375rem;
}

.task-title {
  font-weight: 500;
  font-size: 0.9375rem;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.task-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.task-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.task-error {
  margin-top: 0.5rem;
  padding: 0.5rem 0.625rem;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-queued { background: #e0e7ff; color: #3730a3; }
.badge-downloading { background: #dbeafe; color: #1e40af; }
.badge-ready { background: var(--success-light); color: var(--success); }
.badge-failed { background: var(--danger-light); color: var(--danger); }
.badge-expired { background: #f3f4f6; color: #6b7280; }
.badge-downloaded { background: #ecfdf5; color: #047857; }
.badge-missing { background: #fef3c7; color: #92400e; }
.badge-interrupted { background: #fce7f3; color: #9d174d; }

/* Progress bar */
.progress-wrap {
  margin-top: 0.625rem;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ttl-countdown {
  font-size: 0.8125rem;
  color: var(--warning);
  font-weight: 500;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
}

.empty-state-sm {
  padding: 1rem;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  margin: 0.25rem 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

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

.settings-group {
  border: none;
  padding: 0;
  margin: 0;
}

.settings-group legend {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.75rem;
  padding: 0;
}

.form-row {
  margin-bottom: 0.875rem;
}

.password-form {
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

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

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.25s ease;
}

.toast-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.toast-info {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-right {
    justify-content: flex-start;
  }

  .preview-card-header {
    flex-direction: column;
  }

  .preview-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .task-item-header {
    flex-direction: column;
  }

  .task-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .format-tabs {
    flex-wrap: wrap;
  }
}
