/* ============================================================
   FACELOOK – Facebook-like RSS Timeline
   ============================================================ */

:root {
  --fb-blue: #1877f2;
  --fb-blue-hover: #166fe5;
  --fb-bg: #f0f2f5;
  --fb-white: #ffffff;
  --fb-text: #1c1e21;
  --fb-text-secondary: #65676b;
  --fb-divider: #ced0d4;
  --fb-card-shadow: 0 1px 2px rgba(0,0,0,0.1);
  --fb-hover-bg: #f2f2f2;
  --fb-red: #e41e3f;
  --fb-green: #42b72a;
  --topnav-height: 56px;
  --sidebar-width: 280px;
  --content-max: 680px;
  --radius: 8px;
  --transition: 0.2s ease;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fb-bg);
  color: var(--fb-text);
  min-height: 100vh;
  padding-top: var(--topnav-height);
}

/* ============================================================
   TOP NAVIGATION
   ============================================================ */

.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topnav-height);
  background: var(--fb-white);
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.topnav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
}

.topnav-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--fb-text);
  font-weight: 700;
  font-size: 1.3rem;
}

.logo-text {
  display: none;
}

@media (min-width: 768px) {
  .logo-text { display: inline; }
}

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--fb-text);
  transition: background var(--transition);
}

.hamburger:hover {
  background: var(--fb-hover-bg);
}

@media (min-width: 1100px) {
  .hamburger { display: none; }
}

.topnav-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
}

.topnav-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex: 1;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--fb-text-secondary);
  transition: background var(--transition);
  position: relative;
}

.nav-icon:hover {
  background: var(--fb-hover-bg);
}

.nav-icon.active {
  color: var(--fb-blue);
  border-bottom: 3px solid var(--fb-blue);
  border-radius: 0;
}

.refresh-btn.refreshing svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: var(--topnav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--fb-white);
  z-index: 999;
  overflow-y: auto;
  padding: 8px;
  transform: translateX(-100%);
  transition: transform var(--transition);
}

.sidebar.open {
  transform: translateX(0);
}

@media (min-width: 1100px) {
  .sidebar {
    transform: translateX(0);
  }
  .sidebar-overlay { display: none; }
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--fb-divider);
  margin-bottom: 8px;
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--fb-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.sidebar-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.sidebar-sub {
  font-size: 0.8rem;
  color: var(--fb-text-secondary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--fb-text);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background var(--transition);
}

.sidebar-link:hover {
  background: var(--fb-hover-bg);
}

.sidebar-link.active {
  background: #e7f3ff;
  color: var(--fb-blue);
}

.sidebar-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e4e6eb;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--fb-text);
}

.sidebar-link.active .sidebar-icon {
  background: var(--fb-blue);
  color: white;
}

.sidebar-divider {
  height: 1px;
  background: var(--fb-divider);
  margin: 8px 12px;
}

.sidebar-category-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--fb-text-secondary);
  font-weight: 400;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

.main-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

@media (min-width: 1100px) {
  .main-content {
    margin-left: auto;
    margin-right: auto;
    transform: translateX(calc(var(--sidebar-width) / 2));
  }
}

/* ============================================================
   POST CARD (Facebook style)
   ============================================================ */

.post-card {
  background: var(--fb-white);
  border-radius: var(--radius);
  box-shadow: var(--fb-card-shadow);
  margin-bottom: 16px;
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.post-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.post-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--fb-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.post-avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
  display: inline-flex;
}

.post-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.post-avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.post-meta {
  flex: 1;
  min-width: 0;
}

.post-feed-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
}

.post-time {
  font-size: 0.78rem;
  color: var(--fb-text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.post-time svg {
  width: 12px;
  height: 12px;
}

.post-body {
  padding: 0 16px 12px;
}

.post-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--fb-text);
}

.post-summary {
  font-size: 0.9rem;
  color: var(--fb-text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-summary img {
  display: none !important;
}

.post-image {
  width: 100%;
  max-height: 600px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  border-top: 1px solid var(--fb-divider);
  border-bottom: 1px solid var(--fb-divider);
}

.post-actions {
  display: flex;
  align-items: center;
  padding: 4px 16px;
}

.post-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  padding: 8px;
  border: none;
  background: none;
  color: var(--fb-text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: background var(--transition);
}

.post-action-btn:hover {
  background: var(--fb-hover-bg);
}

.post-action-btn.liked {
  color: var(--fb-red);
}

.post-action-btn.liked svg {
  fill: var(--fb-red);
}

.post-action-btn.saved {
  color: var(--fb-blue);
}

.post-action-btn.saved svg {
  fill: var(--fb-blue);
}

.post-action-btn svg {
  width: 18px;
  height: 18px;
}

.post-divider {
  height: 1px;
  background: var(--fb-divider);
  margin: 0 16px;
}

/* ============================================================
   POST DETAIL MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--fb-white);
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition);
}

.modal-overlay.open .modal-content {
  transform: scale(1);
}

.modal-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--fb-divider);
  position: sticky;
  top: 0;
  background: var(--fb-white);
  z-index: 10;
  border-radius: 12px 12px 0 0;
}

.modal-detail-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #e4e6eb;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background var(--transition);
}

.modal-detail-close:hover {
  background: #d8dadf;
}

.modal-detail-meta {
  font-size: 0.85rem;
  color: var(--fb-text-secondary);
}

.modal-detail-body {
  padding: 16px 20px 24px;
}

.modal-detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.3;
}

.modal-detail-feed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--fb-blue);
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-detail-image {
  width: 100%;
  max-height: 500px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 16px;
  background: #f0f2f5;
}

.modal-detail-content {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--fb-text);
}

.modal-detail-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 12px 0;
  display: block;
}

.modal-detail-content figure {
  margin: 16px 0;
  text-align: center;
}

.modal-detail-content figure img {
  margin-bottom: 6px;
}

.modal-detail-content figcaption {
  font-size: 0.85rem;
  color: var(--fb-text-secondary);
  font-style: italic;
  line-height: 1.4;
  padding: 0 8px;
}

.modal-detail-content p {
  margin-bottom: 0.8em;
}

.modal-detail-content a {
  color: var(--fb-blue);
  word-break: break-all;
}

.modal-detail-content pre,
.modal-detail-content code {
  background: #f0f2f5;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.9em;
  overflow-x: auto;
}

.modal-detail-content blockquote {
  border-left: 3px solid var(--fb-blue);
  padding-left: 12px;
  margin: 12px 0;
  color: var(--fb-text-secondary);
}

.modal-detail-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--fb-divider);
}

.modal-detail-actions .post-action-btn {
  flex: 0;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--fb-divider);
}

.modal-detail-link {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--fb-divider);
  border-radius: 8px;
  text-decoration: none;
  color: var(--fb-text);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background var(--transition);
}

.modal-detail-link:hover {
  background: var(--fb-hover-bg);
}

/* ============================================================
   TTS (Read Aloud)
   ============================================================ */

.tts-bar {
  padding: 8px 20px 12px;
  border-top: 1px solid var(--fb-divider);
}

.tts-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--fb-divider);
  border-radius: 8px;
  background: var(--fb-white);
  color: var(--fb-text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  width: 100%;
  justify-content: center;
}

.tts-action-btn:hover {
  background: var(--fb-hover-bg);
}

.tts-action-btn:active {
  background: #e7f3ff;
  color: var(--fb-blue);
  border-color: var(--fb-blue);
}

/* Floating TTS player bar (bottom of screen) */
.tts-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--fb-white);
  border-top: 1px solid var(--fb-divider);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  z-index: 3000;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.tts-player-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--fb-blue);
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.tts-player-btn:hover {
  background: var(--fb-hover-bg);
}

.tts-stop-btn {
  color: var(--fb-text-secondary);
}

.tts-player-title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ============================================================
   AUTH MODAL
   ============================================================ */

.auth-modal-content {
  max-width: 400px;
  padding: 0;
  overflow: hidden;
}

.auth-modal-header {
  text-align: center;
  padding: 32px 24px 20px;
}

.auth-modal-logo {
  margin-bottom: 12px;
}

.auth-modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--fb-text);
}

.auth-modal-header p {
  font-size: 0.85rem;
  color: var(--fb-text-secondary);
  line-height: 1.4;
}

.auth-modal-form {
  padding: 0 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-modal-form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--fb-text);
}

.auth-modal-form input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--fb-divider);
  border-radius: 8px;
  background: var(--fb-white);
  color: var(--fb-text);
  outline: none;
  transition: border-color var(--transition);
}

.auth-modal-form input[type="password"]:focus {
  border-color: var(--fb-blue);
  box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
}

.auth-error {
  display: none;
  font-size: 0.83rem;
  color: var(--fb-red);
  margin: 0;
}

.auth-submit-btn {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--fb-blue);
  color: white;
  cursor: pointer;
  transition: background var(--transition);
}

.auth-submit-btn:hover {
  background: var(--fb-blue-hover);
}

.auth-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Article extraction badge */
.article-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e7f3ff;
  color: var(--fb-blue);
  margin-left: 8px;
  vertical-align: middle;
}

/* Article skeleton loader */
.article-loading {
  padding: 8px 0;
}

.article-skeleton {
  height: 14px;
  background: linear-gradient(90deg, #f0f2f5 25%, #e4e6eb 50%, #f0f2f5 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 12px;
}

.article-skeleton-title {
  height: 20px;
  width: 60%;
}

.article-skeleton-line {
  width: 100%;
}

.article-skeleton-line.w60 { width: 60%; }
.article-skeleton-line.w80 { width: 80%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   FEEDS MANAGEMENT
   ============================================================ */

.feeds-page {
  max-width: 600px;
  margin: 0 auto;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.add-feed-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--fb-white);
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--fb-card-shadow);
}

.add-feed-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--fb-divider);
  border-radius: 20px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.add-feed-form input:focus {
  border-color: var(--fb-blue);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), opacity var(--transition);
}

.btn-primary {
  background: var(--fb-blue);
  color: white;
}

.btn-primary:hover {
  background: var(--fb-blue-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-danger {
  background: none;
  color: var(--fb-red);
  padding: 6px 12px;
}

.btn-danger:hover {
  background: #fce4e4;
}

.btn-secondary {
  background: #e4e6eb;
  color: var(--fb-text);
  padding: 6px 12px;
}

.btn-secondary:hover {
  background: #d8dadf;
}

.feed-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--fb-white);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--fb-card-shadow);
}

.feed-item-info {
  flex: 1;
  min-width: 0;
}

.feed-item-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.feed-item-url {
  font-size: 0.78rem;
  color: var(--fb-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-item-count {
  font-size: 0.78rem;
  color: var(--fb-text-secondary);
}

.feed-item-cat {
  font-size: 0.78rem;
  color: var(--fb-text-secondary);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.feed-cat-select,
.feed-category-select {
  font-size: 0.8rem;
  padding: 4px 8px;
  border: 1px solid var(--fb-divider);
  border-radius: 6px;
  background: var(--fb-white);
  color: var(--fb-text);
  cursor: pointer;
  max-width: 160px;
}

.feed-category-select {
  max-width: 180px;
  flex-shrink: 0;
}

/* ============================================================
   LOADING & EMPTY STATES
   ============================================================ */

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--fb-text-secondary);
  gap: 10px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--fb-divider);
  border-top-color: var(--fb-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--fb-text-secondary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--fb-text);
}

.empty-state p {
  font-size: 0.9rem;
}

.load-more {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.load-more-btn {
  padding: 10px 28px;
  border: 1px solid var(--fb-divider);
  border-radius: 20px;
  background: var(--fb-white);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--fb-text);
  transition: background var(--transition);
}

.load-more-btn:hover {
  background: var(--fb-hover-bg);
}

.load-more-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1c1e21;
  color: white;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 3000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */

@media (max-width: 767px) {
  :root {
    --topnav-height: 52px;
  }

  .main-content {
    padding: 10px;
  }

  .post-card {
    border-radius: 0;
    margin-left: -10px;
    margin-right: -10px;
    margin-bottom: 10px;
  }

  .post-image {
    max-height: 250px;
  }

  .modal-content {
    border-radius: 0;
    max-height: 100vh;
    height: 100vh;
  }

  .modal-detail-header {
    border-radius: 0;
  }

  .modal-detail-title {
    font-size: 1.2rem;
  }

  .add-feed-form {
    flex-direction: column;
  }

  .topnav-center {
    gap: 0;
  }

  .nav-icon {
    width: 42px;
    height: 42px;
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bcc0c4; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a4a8; }
