/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2333;
  --bg-modal: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --accent: #58a6ff;
  --accent-dim: rgba(88,166,255,0.15);
  --morning: #f0883e;
  --afternoon: #d2a038;
  --night: #8b5cf6;
  --red: #f85149;
  --green: #3fb950;
  --purple: #bc8cff;
  --youtube: #ff4444;
  --reddit: #ff6b35;
  --podcast: #bc8cff;
  --rss: #58a6ff;

  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* ===== Header ===== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

#app-header h1 {
  font-size: 20px;
  font-weight: 700;
}

.header-right {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--accent-dim);
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
}

/* ===== Banner ===== */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(248,81,73,0.15);
  color: var(--red);
  font-size: 14px;
  flex-shrink: 0;
}

.banner button {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* Fetch progress banner */
.fetch-banner {
  background: rgba(88,166,255,0.1);
  color: var(--accent);
  gap: 10px;
  justify-content: flex-start;
}

.fetch-banner .spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
  flex-shrink: 0;
}

.hidden { display: none !important; }

/* ===== Tab Bar ===== */
#tab-bar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  z-index: 10;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 4px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.15s;
}

.tab.active {
  color: var(--accent);
}

.tab svg { width: 22px; height: 22px; }

/* ===== Content Area ===== */
#content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page {
  display: none;
  padding: 12px 16px 24px;
}

.page.active { display: block; }

/* ===== Date Picker ===== */
.date-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.date-picker-row input[type="date"] {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color-scheme: dark;
}

.chip-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

.chip-btn:active { background: var(--bg-card-hover); }

/* ===== Digest Sections ===== */
.digest-section {
  margin-bottom: 20px;
}

.digest-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
}

.digest-icon {
  font-size: 18px;
}

.digest-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.digest-count {
  font-size: 12px;
  background: var(--border);
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text-secondary);
}

.digest-new {
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
}

.digest-chevron {
  color: var(--text-tertiary);
  font-size: 12px;
  transition: transform 0.2s;
}

.digest-section.collapsed .digest-chevron {
  transform: rotate(-90deg);
}

.digest-section.collapsed .digest-items {
  display: none;
}

/* ===== Feed Item Cards ===== */
.feed-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.feed-card:active {
  background: var(--bg-card-hover);
}

.feed-card.read {
  opacity: 0.6;
}

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.card-icon.rss, .card-icon.atom { background: rgba(88,166,255,0.15); color: var(--rss); }
.card-icon.podcast { background: rgba(188,140,255,0.15); color: var(--podcast); }
.card-icon.youtube { background: rgba(255,68,68,0.15); color: var(--youtube); }
.card-icon.reddit, .card-icon.hackernews { background: rgba(255,107,53,0.15); color: var(--reddit); }

.card-body { flex: 1; min-width: 0; }

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.card-source {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.card-time {
  font-size: 11px;
  color: var(--text-tertiary);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-badges {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  align-items: center;
}

.badge {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.badge.podcast { color: var(--podcast); }
.badge.youtube { color: var(--youtube); }
.badge.bookmark { color: var(--morning); }
.badge.ai { color: var(--purple); }

.card-thumb {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.empty-sub { font-size: 14px; color: var(--text-secondary); }

/* ===== Sources Page ===== */
.page-actions {
  margin-bottom: 16px;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.primary-btn:active { opacity: 0.85; }

.secondary-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

.danger-btn {
  background: rgba(248,81,73,0.15);
  color: var(--red);
  border: 1px solid rgba(248,81,73,0.3);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.source-info { flex: 1; min-width: 0; }

.source-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.source-url {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.source-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.source-status.active { background: var(--green); }
.source-status.inactive { background: var(--text-tertiary); }

.source-delete {
  background: none;
  border: none;
  color: var(--red);
  font-size: 18px;
  padding: 8px;
  cursor: pointer;
  opacity: 0.6;
}

.source-delete:active { opacity: 1; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.modal-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  flex: 1;
  font-size: 17px;
}

.modal-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

#modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.modal-body-form {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* ===== Detail View ===== */
.detail-source {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.detail-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 8px;
}

.detail-author {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.detail-image {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.detail-summary {
  background: rgba(188,140,255,0.1);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.detail-summary-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--purple);
  margin-bottom: 8px;
}

.detail-summary-text {
  font-size: 15px;
  line-height: 1.5;
}

.detail-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}

.detail-content p {
  margin-bottom: 12px;
}

.detail-media {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-media a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

/* ===== Settings ===== */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.meta-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.settings-btn-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.settings-btn-row .secondary-btn {
  flex: 1;
}

/* ===== Quick Add ===== */
.quick-add-section {
  margin-top: 20px;
}

.quick-add-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.quick-add-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 8px;
  text-align: left;
}

.quick-add-btn:active { background: var(--bg-card-hover); }

.qa-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.qa-icon.hn { background: #ff6600; color: #fff; }
.qa-icon.reddit { background: var(--reddit); color: #fff; }
.qa-icon.yt { background: var(--youtube); color: #fff; }

/* ===== Loading Spinner ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Responsive tweaks for larger screens ===== */
@media (min-width: 768px) {
  #content {
    max-width: 700px;
    margin: 0 auto;
  }

  #tab-bar {
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
  }
}
