/* MarkItDown Website — 深色主題樣式
   色彩：
     背景      #1a1a2e
     表面      #16213e
     強調      #0f3460
     亮點      #e94560
     文字      #eaeaea
     次要文字  #a0a0b0
*/

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

:root {
  --color-bg:        #1a1a2e;
  --color-surface:   #16213e;
  --color-accent:    #0f3460;
  --color-highlight: #e94560;
  --color-text:      #eaeaea;
  --color-muted:     #a0a0b0;
  --color-border:    #2a2a4a;
  --color-success:   #4caf7d;
  --color-error:     #e94560;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── 頁首 ──────────────────────────────────────────────────────────────── */

.site-header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-highlight);
  letter-spacing: -0.02em;
}

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

/* 引擎狀態指示器 */
.engine-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-muted);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  background-color: var(--color-accent);
  transition: background-color 0.3s, color 0.3s;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-muted);
  transition: background-color 0.3s;
  flex-shrink: 0;
}

.engine-status--loading .status-dot {
  background-color: #f0a500;
  animation: pulse 1.5s ease-in-out infinite;
}

.engine-status--ready .status-dot {
  background-color: var(--color-success);
  animation: none;
}

.engine-status--ready {
  color: var(--color-success);
}

.engine-status--error .status-dot {
  background-color: var(--color-error);
  animation: none;
}

.engine-status--error {
  color: var(--color-error);
}

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

/* ── 主要內容 ──────────────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  padding: 3rem 2rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

/* 狀態區塊：預設隱藏 */
.state-section {
  display: none;
}

.state-section--active {
  display: block;
}

/* ── 拖放上傳區域 ──────────────────────────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 4rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, transform 0.1s, opacity 0.4s ease;
  background-color: var(--color-surface);
  position: relative;
  user-select: none;
}

.drop-zone:hover,
.drop-zone:focus {
  border-color: var(--color-highlight);
  background-color: var(--color-accent);
  outline: none;
}

.drop-zone--dragging {
  border-color: var(--color-highlight);
  background-color: var(--color-accent);
  transform: scale(1.01);
  box-shadow: 0 0 0 4px rgba(233, 69, 96, 0.2);
}

.drop-zone--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.drop-zone__icon {
  color: var(--color-highlight);
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: center;
}

.drop-zone__title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.drop-zone__subtitle {
  font-size: 0.9rem;
  color: var(--color-muted);
}

.drop-zone__hint {
  font-size: 0.78rem;
  color: var(--color-muted);
  opacity: 0.7;
  margin-top: 0.5rem;
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

/* 上傳區載入中提示 */
.upload-engine-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.upload-engine-status[hidden] {
  display: none;
}

/* 引擎載入進度條 */
.engine-progress__track {
  width: 280px;
  max-width: 100%;
  height: 4px;
  background-color: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.engine-progress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c87800 0%, #f0a500 50%, #c87800 100%);
  background-size: 200% 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
  animation: engine-shimmer 1.5s linear infinite;
}

@keyframes engine-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

/* 支援格式標籤 */
.supported-formats {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.supported-formats__label {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-right: 0.25rem;
}

.format-badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  background-color: var(--color-accent);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

/* ── 按鈕 ──────────────────────────────────────────────────────────────── */

.btn {
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn--primary:hover {
  background-color: #d03850;
}

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

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

.btn--small {
  padding: 0.4rem 0.875rem;
  font-size: 0.8rem;
}

/* ── 錯誤提示 ──────────────────────────────────────────────────────────── */

.error-banner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background-color: rgba(0, 0, 0, 0.55);
  padding: 1rem;
}

.error-banner[hidden] {
  display: none;
}

.error-banner__inner {
  width: 100%;
  max-width: 560px;
  background-color: #3d1a20;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
}

.error-banner strong {
  color: var(--color-error);
  font-size: 1rem;
}

.error-banner p {
  font-size: 0.85rem;
  color: var(--color-text);
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

/* ── 離線提示 ──────────────────────────────────────────────────────────── */

.offline-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.5rem;
  background-color: #3a2e00;
  border-bottom: 1px solid #f0a500;
  color: #f0a500;
  font-size: 0.85rem;
}

.offline-banner[hidden] {
  display: none;
}

/* ── 頁尾 ──────────────────────────────────────────────────────────────── */

.site-footer {
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.site-footer a {
  color: var(--color-muted);
  text-decoration: underline;
}

.site-footer a:hover {
  color: var(--color-text);
}

/* ── 響應式 ────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .main-content {
    padding: 1.5rem 1rem;
  }

  .drop-zone {
    padding: 3rem 1.5rem;
  }

  .site-header {
    padding: 0.75rem 1rem;
  }

  .list-header {
    flex-wrap: wrap;
  }
}

/* ===== 清單狀態 ===== */
.list-container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 0;
}


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

.list-header__actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--color-border);
}

.list-footer__actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

#list-progress-text-footer {
  font-size: 0.9rem;
  color: var(--color-muted);
}

#list-progress-text {
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* 檔案清單 */
.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-item {
  border-bottom: 1px solid var(--color-border);
}

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

.file-item__row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0;
  min-height: 3rem;
}

.file-item__icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-item--done .file-item__icon  { color: #27ae60; }
.file-item--error .file-item__icon { color: #e74c3c; }
.file-item--waiting .file-item__icon { color: var(--color-muted); }
.file-item--fetching .file-item__icon { color: var(--color-muted); }
.file-item--queued .file-item__icon { color: var(--color-muted); }

.file-item__name {
  flex: 1;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.file-item--error .file-item__name {
  color: var(--color-muted);
}

.file-item__meta {
  font-size: 0.8rem;
  color: var(--color-muted);
  flex-shrink: 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.file-item--error .file-item__meta {
  color: #e74c3c;
}

.file-item__btn-preview,
.file-item__btn-download {
  flex-shrink: 0;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  color: inherit;
  transition: background-color 0.15s;
}

.file-item__btn-preview:hover,
.file-item__btn-download:hover {
  background: var(--color-surface);
}

/* Markdown 預覽展開區 */
.file-item__preview {
  padding: 0.5rem 0 1rem calc(20px + 0.75rem);
}

.file-item__preview pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  padding: 1rem;
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.78rem;
  line-height: 1.5;
  margin: 0;
  white-space: pre;
  scrollbar-width: thin;
  scrollbar-color: var(--color-muted) transparent;
}

.file-item__preview pre::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.file-item__preview pre::-webkit-scrollbar-track {
  background: transparent;
}

.file-item__preview pre::-webkit-scrollbar-thumb {
  background: var(--color-muted);
  border-radius: 4px;
}

.file-item__preview pre::-webkit-scrollbar-thumb:hover {
  background: var(--color-text);
}

.file-item__preview pre::-webkit-scrollbar-corner {
  background: transparent;
}

/* 清單項目 converting 狀態小 spinner */
.spinner-small {
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-highlight);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* 抓取進度圓環 */
.progress-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.progress-ring svg {
  transform: rotate(-90deg);
}

.progress-ring__track {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 2.5;
}

.progress-ring__bar {
  fill: none;
  stroke: var(--color-highlight);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
}

.progress-ring__pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  color: var(--color-text);
}

/* 不定進度（無 Content-Length）：Google Material Design 風格 */
@keyframes progress-rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes progress-dash {
  0% {
    stroke-dasharray: 1, 68.115;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 52, 17.115;
    stroke-dashoffset: -20;
  }
  100% {
    stroke-dasharray: 1, 68.115;
    stroke-dashoffset: -69.115;
  }
}

.progress-ring--indeterminate svg {
  animation: progress-rotate 1.4s linear infinite;
}

.progress-ring--indeterminate .progress-ring__bar {
  animation: progress-dash 1.4s ease-in-out infinite;
}

/* ── URL 輸入區 ────────────────────────────────────────────────────────────── */

.url-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  color: #888;
  font-size: 0.9rem;
}

.url-divider::before,
.url-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #444;
}

.url-input-area {
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

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

.url-input {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem 1rem;
  background: #1e1e1e;
  border: 2px solid #444;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.url-input:focus {
  border-color: #6c9fff;
}

.url-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.url-input::placeholder {
  color: #666;
}

.url-input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.url-input__btn {
  white-space: nowrap;
  padding: 0.75rem 1.5rem;
}

.url-input__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.url-input-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-muted);
}

.url-input-hint--warning {
  margin: 0.5rem 0 0;
  color: #f0a500;
}

.url-input-hint[hidden] {
  display: none;
}

.url-limit-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-error);
}

.url-limit-error[hidden] {
  display: none;
}

