:root {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-2: #1b2742;
  --border: #253456;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; margin: 0.25rem 0 0.6rem; }
.flex-1 { flex: 1; }
.row-gap { display: flex; gap: 0.6rem; align-items: center; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-sm { padding: 0.48rem 0.78rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.link-btn {
  background: none;
  border: none;
  color: #60a5fa;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.68rem 0.85rem;
  font-size: 0.96rem;
  font-family: inherit;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.auth-logo { font-size: 2.6rem; margin-bottom: 0.4rem; }
.auth-card h1 { margin: 0 0 0.4rem; font-size: 1.45rem; }
.auth-card form { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 1.2rem; }
.error-text { color: #fca5a5; font-size: 0.88rem; margin-top: 0.75rem; }

/* App Shell */
.app-shell {
  max-width: 780px;
  margin: 0 auto;
  padding-bottom: 4rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar-left { display: flex; align-items: center; gap: 0.65rem; }
.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}
.brand-title { margin: 0; font-size: 1.08rem; line-height: 1.2; }
.sync-status { font-size: 0.74rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 0.45rem; }

.main-content { padding: 0.9rem 1rem 2rem; }

/* Search & Filter */
.controls-bar { display: flex; flex-direction: column; gap: 0.65rem; margin-bottom: 1.15rem; }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 0.8rem; font-size: 0.9rem; pointer-events: none; }
.search-wrap input { padding-left: 2.3rem; padding-right: 2.2rem; background: var(--surface); }
.clear-btn {
  position: absolute;
  right: 0.55rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.3rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: center;
}

.chip-group {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chip-group::-webkit-scrollbar { display: none; }

.chip {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.36rem 0.78rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: rgba(59, 130, 246, 0.22);
  border-color: var(--primary);
  color: #bfdbfe;
}

/* Sections */
.section-block { margin-bottom: 1.35rem; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}
.section-header h2 { margin: 0; font-size: 1rem; color: #e2e8f0; }
.count-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.18rem 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Category Grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}
@media (min-width: 600px) {
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.78rem 0.85rem;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cat-card.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
}
.cat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cat-icon { font-size: 1.35rem; }
.cat-count {
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: #cbd5e1;
  padding: 0.14rem 0.52rem;
  border-radius: 999px;
}
.cat-name { font-size: 0.92rem; font-weight: 600; line-height: 1.3; }
.cat-unread { font-size: 0.74rem; color: #60a5fa; }

/* Article Cards */
.article-list { display: flex; flex-direction: column; gap: 0.75rem; }

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.article-card[data-platform="threads"] { border-left-color: #f8fafc; }
.article-card[data-platform="instagram"] { border-left-color: #ec4899; }
.article-card[data-platform="facebook"] { border-left-color: #3b82f6; }
.article-card[data-platform="web"] { border-left-color: #14b8a6; }
.article-card.is-read { opacity: 0.74; }

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.75rem;
}

.platform-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.14rem 0.48rem;
  border-radius: 6px;
  text-transform: uppercase;
}
.platform-threads { background: #1e293b; color: #f8fafc; border: 1px solid #475569; }
.platform-instagram { background: rgba(236, 72, 153, 0.2); color: #f9a8d4; }
.platform-facebook { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }
.platform-web { background: rgba(20, 184, 166, 0.2); color: #5eead4; }

.cat-badge {
  background: var(--surface-2);
  color: #cbd5e1;
  padding: 0.14rem 0.5rem;
  border-radius: 6px;
}

.ai-badge {
  font-size: 0.72rem;
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
}

.card-title-link {
  color: #f8fafc;
  text-decoration: none;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.4;
}
.card-title-link:hover { color: #93c5fd; text-decoration: underline; }

.card-summary { margin: 0; font-size: 0.87rem; color: #cbd5e1; }
.card-note {
  margin: 0;
  font-size: 0.82rem;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
}

.tag-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
  font-size: 0.75rem;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.12);
  padding: 0.12rem 0.48rem;
  border-radius: 6px;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.25rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(37, 52, 86, 0.7);
}
.card-action-group { display: flex; gap: 0.35rem; }
.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: #cbd5e1;
  border-radius: 8px;
  padding: 0.32rem 0.58rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.mini-btn.active { border-color: var(--warning); color: #fde68a; background: rgba(245, 158, 11, 0.16); }
.mini-btn.read-on { border-color: var(--success); color: #6ee7b7; background: rgba(16, 185, 129, 0.16); }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.2rem;
  text-align: center;
  color: var(--muted);
}

/* Modal Bottom Sheet */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) {
  .modal { align-items: center; padding: 1rem; }
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 1rem 1.1rem 1.4rem;
  box-shadow: var(--shadow);
}
@media (min-width: 600px) {
  .modal-sheet { border-radius: 20px; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}
.modal-header h3 { margin: 0; font-size: 1.08rem; }

.field { margin-bottom: 0.85rem; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 0.35rem;
}

.input-with-btn { display: flex; gap: 0.4rem; }
.input-with-btn input { flex: 1; min-width: 0; }

.meta-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.banner {
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-size: 0.86rem;
  margin-bottom: 0.8rem;
}
.banner.info { background: rgba(59, 130, 246, 0.16); border: 1px solid rgba(59, 130, 246, 0.4); color: #bfdbfe; }
.banner.warn { background: rgba(245, 158, 11, 0.16); border: 1px solid rgba(245, 158, 11, 0.4); color: #fde68a; }
.banner.error { background: rgba(239, 68, 68, 0.16); border: 1px solid rgba(239, 68, 68, 0.45); color: #fca5a5; }
.banner.success { background: rgba(16, 185, 129, 0.16); border: 1px solid rgba(16, 185, 129, 0.45); color: #6ee7b7; }

.assist-box {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.85rem;
}
.assist-title { font-weight: 700; font-size: 0.88rem; color: #fde68a; }
.assist-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.4rem; }

.cat-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.cat-pick-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 0.36rem 0.72rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.cat-pick-btn.selected {
  background: rgba(59, 130, 246, 0.25);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

.modal-footer { margin-top: 1rem; }

/* Settings */
.settings-group {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.settings-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-group h4 { margin: 0 0 0.5rem; font-size: 0.94rem; }

.add-cat-form { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; }
.icon-input { width: 52px !important; text-align: center; padding-left: 0.3rem !important; padding-right: 0.3rem !important; }
.manage-cat-list { display: flex; flex-direction: column; gap: 0.4rem; }
.manage-cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.48rem 0.7rem;
  font-size: 0.88rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  z-index: 80;
  background: #1e293b;
  border: 1px solid #475569;
  color: #f8fafc;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}
