/* ===== CSS Variables ===== */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f8f9fa;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-width: 300px;
  --header-height: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

/* ===== Reset ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== App Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== Header ===== */
.header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 24px;
}

.title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

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

/* ===== Language Switcher ===== */
.lang-switcher {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.lang-btn {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  padding: 8px 16px;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-icon {
  padding: 8px;
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--border-light);
  color: var(--text);
}

.btn-sm {
  padding: 5px;
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-light);
}

/* ===== Main Layout ===== */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-header-actions {
  display: flex;
  gap: 4px;
}

.add-form-container {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 12px;
}

.add-form-container[hidden] {
  display: none;
}

.add-feed-form {
  padding: 0 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.add-feed-form .btn-primary {
  width: 100%;
  padding: 9px;
}

/* ===== Preset Feeds ===== */
.preset-feeds {
  padding: 0 20px 12px;
}

.preset-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  font-weight: 600;
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.preset-chip:hover {
  background: var(--primary);
  color: #fff;
}

.preset-chip.added {
  opacity: 0.4;
  cursor: default;
}

.preset-chip.added:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* ===== Feed List ===== */
.feed-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
  list-style: none;
}

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.feed-item:hover {
  background: var(--surface-hover);
}

.feed-item.active {
  background: var(--primary-light);
}

.feed-item.active .feed-name {
  color: var(--primary);
}

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

.feed-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.feed-icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
}

.feed-icon-img {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}

.feed-icon-fallback {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
}

.feed-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  flex-shrink: 0;
  margin-left: 8px;
}

.feed-item:hover .feed-actions {
  opacity: 1;
}

.feed-item.all-feeds {
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
  padding-bottom: 8px;
}

/* Edit form */
.feed-item.editing {
  flex-direction: column;
  align-items: stretch;
  padding: 10px 12px;
  background: var(--primary-light);
}

.feed-edit-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feed-edit-form .input {
  font-size: 12px;
  padding: 6px 10px;
}

.feed-edit-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.feed-edit-buttons .btn-primary {
  font-size: 12px;
  padding: 5px 14px;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
}

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

/* ===== Content Area ===== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.content-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border-light);
}

.content-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-toggle {
  display: none;
}

/* Show the open-sidebar button whenever sidebar is collapsed (any screen size) */
.sidebar.collapsed + .content .sidebar-toggle {
  display: inline-flex;
}

.article-count {
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--surface);
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ===== Article List ===== */
.article-list {
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  display: flex;
  gap: 16px;
}

.article-card.has-image {
  padding: 14px 16px;
}

.article-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.article-card.loading-trans {
  opacity: 0.7;
}

.article-image {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}

.article-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.article-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-tertiary);
}

.article-source {
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
}

.article-dot {
  color: var(--border);
}

.article-date {
  color: var(--text-tertiary);
}

.article-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 8px;
}

.article-title a {
  color: inherit;
  text-decoration: none;
}

.article-title a:hover {
  color: var(--primary);
}

.article-desc {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 10px;
}

.article-translated-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--success);
  font-weight: 500;
}

.article-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.article-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.article-link:hover {
  text-decoration: underline;
}

.translate-btn {
  font-size: 12px;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  font-family: var(--font);
}

.translate-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.translate-btn.translating {
  color: var(--warning);
  pointer-events: none;
}

.translate-btn.done {
  color: var(--success);
}

/* ===== Empty & Loading States ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 13px !important;
  font-weight: 400 !important;
  color: var(--text-tertiary) !important;
  margin-top: 4px;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 0.3s ease;
  pointer-events: none;
  max-width: 90%;
}

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

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .article-list {
    padding: 12px 16px;
  }

  .article-image {
    width: 80px;
    height: 80px;
  }

  .article-title {
    font-size: 15px;
  }

  .article-desc {
    font-size: 14px;
  }

  .content-header {
    padding: 12px 16px;
  }

  .title {
    font-size: 16px;
  }

  .lang-btn {
    padding: 5px 10px;
    font-size: 12px;
  }
}
