/* ==========================================================================
   Thread Collector - Sleek Mobile Web App Styles
   ========================================================================== */

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-main: #0b0e14;
  --bg-card: #151921;
  --bg-card-sub: #1c222e;
  --border-color: #272f3e;
  --text-main: #f0f4f8;
  --text-muted: #8b99a8;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  --input-bg: #0f131a;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-main: #f3f5f8;
  --bg-card: #ffffff;
  --bg-card-sub: #f8fafc;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-glow: rgba(5, 150, 105, 0.15);
  --accent: #4f46e5;
  --accent-glow: rgba(79, 70, 229, 0.15);
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
  --input-bg: #f1f5f9;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
}

.brand-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.5px;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 2px 0 0;
  font-weight: 500;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ── Card Styles ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.3s ease, background-color 0.3s ease;
}

/* ── Input Card ── */
.input-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  height: 52px;
  background: var(--input-bg);
  border: 1.5px solid var(--border-color);
  border-radius: 14px;
  padding: 0 110px 0 16px;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.inline-btn {
  position: absolute;
  right: 8px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.inline-btn:active {
  transform: scale(0.95);
  background: var(--primary-glow);
  color: var(--primary);
}

.options-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.toggle-label input {
  display: none;
}

.custom-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background: var(--input-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.toggle-label input:checked + .custom-checkbox {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-label input:checked + .custom-checkbox::after {
  content: "✓";
  color: white;
  font-size: 0.8rem;
  font-weight: 800;
}

.max-pages-input {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.max-pages-input input {
  width: 48px;
  height: 32px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  text-align: center;
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.9rem;
  outline: none;
}

.submit-btn {
  width: 100%;
  height: 52px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border: none;
  border-radius: 14px;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px var(--primary-glow);
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.submit-btn:active {
  transform: scale(0.98);
}

/* Spinner */
.btn-spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

.is-loading .btn-spinner {
  display: block;
}

.is-loading .submit-btn {
  opacity: 0.8;
  pointer-events: none;
}

/* ── Status Banner ── */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 0.82rem;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.is-loading .status-dot {
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
  animation: pulse 1s infinite;
}

.status-success .status-dot {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}

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

.metrics {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.metrics strong {
  color: var(--primary);
  margin-right: 2px;
}

.dot-divider {
  opacity: 0.4;
}

/* ── Tabs Navigation ── */
.app-tabs {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  height: 42px;
  background: transparent;
  border: none;
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-card-sub);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ── Tab Content Areas ── */
.tab-pane {
  display: none;
}

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

/* ── Result Card & Editor ── */
.result-card {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.text-size-ctrl {
  display: flex;
  gap: 4px;
}

.size-btn {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.action-buttons {
  display: flex;
  gap: 6px;
}

.action-btn {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn.icon-only {
  padding: 6px 10px;
}

.action-btn:active {
  transform: scale(0.95);
  background: var(--primary-glow);
}

.editor-wrapper {
  position: relative;
  min-height: 420px;
}

#articleOutput {
  width: 100%;
  height: 480px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.65;
  resize: vertical;
  outline: none;
  transition: font-size 0.2s ease;
}

#articleOutput:focus {
  border-color: var(--primary);
}

/* ── Source & History Lists ── */
.source-list,
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-item,
.history-item {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.2s ease;
}

.source-item-title,
.history-item-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.source-item-url,
.history-item-url {
  font-size: 0.78rem;
  color: var(--text-muted);
  word-break: break-all;
}

.history-item {
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--primary);
}

.history-title-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.history-title-button:hover {
  color: var(--primary);
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-head h3 {
  margin: 0;
  font-size: 1rem;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
  opacity: 0.5;
}

/* ── Toast Notification ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-main);
  color: var(--bg-main);
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Settings Drawer Modal ── */
.header-actions {
  display: flex;
  gap: 8px;
}

.settings-drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.2s ease;
}

.settings-drawer.hidden {
  display: none;
}

.drawer-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.drawer-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.icon-btn-sm {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

.field-label input {
  height: 46px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0 14px;
  color: var(--text-main);
  outline: none;
  font-family: inherit;
}

.field-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.primary-btn {
  height: 46px;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}


