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

:root {
  --bg: #FAF6F1;
  --surface: #FFFFFF;
  --accent: #C4763B;
  --accent-hover: #A85F2D;
  --text: #3D3929;
  --muted: rgba(61, 57, 41, 0.5);
  --border: rgba(61, 57, 41, 0.1);
  --unread: #C4763B;
  --star: #E5A84B;
  --danger: #D4645A;
  --radius: 12px;
  --header-h: 56px;
  --sidebar-w: 280px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* === Auth === */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

/* === Sidebar === */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 149;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-section {
  padding: 8px 16px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.sidebar-list {
  list-style: none;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item:hover {
  background: var(--border);
}

.sidebar-item.active {
  background: rgba(196, 118, 59, 0.1);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-item-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--border);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.sidebar-item-count.has-unread {
  background: var(--accent);
  color: white;
}

/* Sidebar folders */
.sidebar-folder {
  margin-bottom: 4px;
}

.sidebar-folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s;
}

.sidebar-folder-header:hover {
  background: var(--border);
}

.sidebar-folder-header svg {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.sidebar-folder-header.collapsed svg {
  transform: rotate(-90deg);
}

.sidebar-folder-items {
  padding-left: 20px;
}

.sidebar-folder-items.collapsed {
  display: none;
}

.sidebar-fav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-fav-item:hover {
  background: var(--border);
}

.sidebar-fav-item .btn-delete-small {
  display: none;
}

.sidebar-fav-item:hover .btn-delete-small {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar saved items */
.sidebar-saved-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-saved-item:hover {
  background: var(--border);
}

.sidebar-saved-item span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-saved-item .btn-delete-small {
  display: none;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
}

.sidebar-saved-item:hover .btn-delete-small {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar bottom */
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  position: relative;
}

.btn-add-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-menu:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.add-menu {
  position: absolute;
  bottom: 100%;
  left: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  display: none;
  overflow: hidden;
  margin-bottom: 4px;
}

.add-menu.open {
  display: block;
}

.add-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.add-menu-item:hover {
  background: var(--border);
}

.add-menu-item + .add-menu-item {
  border-top: 1px solid var(--border);
}

/* === Main Content === */
.main-content {
  transition: margin-left 0.3s ease;
}

/* === Header === */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: 1;
  justify-content: flex-end;
}

.search-wrapper {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  flex-shrink: 0;
}

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

/* === Filter Bar === */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.filter-bar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-bar-left::-webkit-scrollbar { display: none; }

.filter-btn {
  white-space: nowrap;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.filter-btn:hover {
  border-color: var(--accent);
}

.filter-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.filter-btn .count {
  display: inline-block;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.25);
}

.filter-btn:not(.active) .count {
  background: var(--border);
}

/* Filter dropdown */
.filter-dropdown-wrap {
  position: relative;
}

.filter-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  display: none;
  z-index: 120;
  overflow: hidden;
}

.filter-dropdown.open {
  display: block;
}

.filter-dropdown-section {
  padding: 6px 0;
}

.filter-dropdown-section + .filter-dropdown-section {
  border-top: 1px solid var(--border);
}

.filter-dropdown-label {
  padding: 4px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.filter-dropdown-item {
  display: block;
  width: 100%;
  padding: 7px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.filter-dropdown-item:hover {
  background: var(--border);
}

.filter-dropdown-item.active {
  color: var(--accent);
  font-weight: 600;
}

/* Compact toggle */
.btn-compact-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-compact-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-compact-toggle.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* === Articles === */
.articles {
  padding: 0 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.article-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
  cursor: pointer;
}

.article-card:hover {
  border-color: rgba(61, 57, 41, 0.2);
  box-shadow: 0 2px 8px rgba(61, 57, 41, 0.06);
}

.article-card.read {
  opacity: 0.55;
}

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

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--unread);
  flex-shrink: 0;
}

.article-card.read .unread-dot {
  visibility: hidden;
}

.article-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.article-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(196, 118, 59, 0.1);
  color: var(--accent);
  font-weight: 500;
}

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

.article-snippet {
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.article-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.article-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  font-size: 16px;
  color: var(--muted);
  transition: all 0.2s;
}

.article-actions button:hover {
  background: var(--border);
}

.article-actions .btn-fav.active {
  color: var(--star);
}

.article-actions .btn-read.active {
  color: var(--accent);
}

.article-actions .btn-delete-saved {
  color: var(--danger);
}

.article-actions .btn-delete-saved:hover {
  background: rgba(212, 100, 90, 0.1);
}

/* === Compact View === */
.articles.compact .article-card {
  padding: 8px 14px;
}

.articles.compact .article-snippet {
  display: none;
}

.articles.compact .article-title {
  -webkit-line-clamp: 1;
  margin-bottom: 0;
  font-size: 14px;
}

.articles.compact .article-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.articles.compact .article-card {
  position: relative;
  padding-right: 80px;
}

.articles.compact .article-meta {
  margin-bottom: 2px;
}

/* === Loading === */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 0;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  font-size: 14px;
}

/* === Folder Picker Popup === */
.folder-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.folder-popup-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.folder-popup {
  background: var(--surface);
  border-radius: 14px;
  width: 280px;
  max-height: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.folder-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.folder-popup-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.folder-popup-body {
  padding: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.folder-popup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.15s;
}

.folder-popup-item:hover {
  background: var(--border);
}

.folder-popup-item svg {
  flex-shrink: 0;
  color: var(--muted);
}

.folder-popup-item.create-new {
  color: var(--accent);
  font-weight: 500;
  border-top: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  margin-top: 4px;
}

.folder-popup-item.create-new svg {
  color: var(--accent);
}

/* Inline folder create form in popup */
.folder-popup-create {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.folder-popup-create input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.folder-popup-create input:focus {
  border-color: var(--accent);
}

.folder-popup-create button {
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* Sidebar folder delete */
.sidebar-folder-header {
  position: relative;
}

.sidebar-folder-delete {
  display: none;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  margin-left: auto;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.sidebar-folder-header:hover .sidebar-folder-delete {
  display: flex;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.dialog-small {
  max-width: 380px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  padding: 16px 20px 32px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Feed list */
.feed-list {
  list-style: none;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

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

.feed-item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-item-url {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-item-tags {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.feed-item-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(196, 118, 59, 0.1);
  color: var(--accent);
}

.btn-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  border-radius: 6px;
  font-size: 16px;
  flex-shrink: 0;
}

.btn-delete:hover {
  background: rgba(212, 100, 90, 0.1);
}

/* Tags management */
.tags-manage {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 16px;
  background: rgba(196, 118, 59, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.tag-chip button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

/* Add tag form */
.add-tag-form {
  display: flex;
  gap: 6px;
}

.add-tag-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.add-tag-form input:focus {
  border-color: var(--accent);
}

.add-tag-form button {
  padding: 8px 14px;
}

/* Add feed form */
.add-feed-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-feed-form input[type="url"],
.add-feed-form input[type="text"],
.add-feed-form select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

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

/* Dialog form (sidebar add) */
.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dialog-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.dialog-form input:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-secondary {
  padding: 10px 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-full {
  width: 100%;
  margin-bottom: 8px;
}

/* === Desktop (>768px) === */
@media (min-width: 769px) {
  .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
  }

  #btn-close-sidebar {
    display: none;
  }

  .main-content {
    margin-left: var(--sidebar-w);
  }

  #btn-hamburger {
    display: none;
  }

  .header {
    padding: 0 24px;
  }

  .filter-bar {
    padding: 10px 24px;
  }

  .articles {
    padding: 0 24px 32px;
    max-width: 720px;
  }

  .modal {
    border-radius: 16px;
    margin: auto;
    max-height: 75dvh;
  }

  .modal-overlay {
    align-items: center;
  }
}

/* === Mobile === */
@media (max-width: 768px) {
  .header-title {
    display: none;
  }
}
