/* Base */
* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #f0f2f5;
  color: #333;
}

.hidden { display: none; }

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6em 1.2em;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}
.app-title {
  margin: 0;
  font-size: 1.1em;
  font-weight: 700;
  color: #007acc;
  letter-spacing: -0.02em;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.8em;
}
.header-link {
  font-size: 0.8em;
  color: #007acc;
  cursor: pointer;
  text-decoration: none;
  padding: 0.3em 0.6em;
  border-radius: 4px;
  transition: background 0.2s;
}
.header-link:hover {
  background: #f0f7ff;
}
.icon-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.3em 0.6em;
  font-size: 1em;
  cursor: pointer;
  color: #555;
  transition: all 0.2s;
}
.icon-btn:hover {
  background: #f0f7ff;
  border-color: #007acc;
  color: #007acc;
}

/* Tab Bar */
.tab-bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #fff;
  padding: 0.4em 1.2em;
  border-bottom: 1px solid #e0e0e0;
  overflow-x: auto;
}
.tab-buttons {
  display: flex;
  gap: 0.3em;
  flex-wrap: nowrap;
}
.tab-buttons button {
  padding: 0.4em 0.9em;
  border-radius: 6px;
  border: 1px solid transparent;
  background: none;
  color: #555;
  font-size: 0.85em;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.tab-buttons button:hover {
  background: #f0f2f5;
  color: #333;
}
.tab-buttons button.active-tab {
  background: #007acc;
  color: #fff;
  border-color: #007acc;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.4em 1.2em;
  background: #fafbfc;
  border-bottom: 1px solid #e8e8e8;
}
.search-bar {
  flex: 0 1 220px;
  padding: 0.35em 0.7em;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.85em;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar:focus {
  border-color: #007acc;
  box-shadow: 0 0 0 2px rgba(0,122,204,0.1);
}
.toolbar-actions {
  display: flex;
  gap: 0.3em;
  flex-wrap: wrap;
}
.toolbar-btn {
  padding: 0.3em 0.7em;
  border: 1px solid #ddd;
  border-radius: 5px;
  background: #fff;
  color: #555;
  font-size: 0.8em;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.toolbar-btn:hover {
  background: #f0f7ff;
  border-color: #007acc;
  color: #007acc;
}
.btn-group {
  display: flex;
  gap: 0.2em;
}
.btn-group .toolbar-btn:first-child {
  border-radius: 5px 0 0 5px;
}
.btn-group .toolbar-btn:last-child {
  border-radius: 0 5px 5px 0;
}
.btn-group .toolbar-btn:not(:first-child):not(:last-child) {
  border-radius: 0;
}
.btn-group .toolbar-btn:only-child {
  border-radius: 5px;
}
.btn-group .toolbar-btn + .toolbar-btn {
  margin-left: -1px;
}
.toolbar-sep {
  width: 1px;
  height: 1.4em;
  background: #ddd;
  align-self: center;
  margin: 0 0.3em;
}

/* Feed Grid */
.feeds-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 0.8em;
  max-width: 1600px;
  padding: 1em 1.2em;
}

/* Loading Skeleton */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton-line {
  height: 0.75em;
  margin: 0.5em 0;
  border-radius: 4px;
  background: linear-gradient(90deg, #e8e8e8 25%, #f5f5f5 50%, #e8e8e8 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite ease-in-out;
}
.skeleton-title {
  height: 1em;
  width: 50% !important;
  margin-bottom: 0.8em;
}
.skeleton-tile {
  min-height: 100px;
}
body.dark .skeleton-line {
  background: linear-gradient(90deg, #1e2d3d 25%, #253545 50%, #1e2d3d 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite ease-in-out;
}

/* Feed Tiles */
.feed-tile {
  background: #fff;
  border-radius: 8px;
  padding: 0.8em 1em;
  border: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.15s;
}
.feed-tile:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}
.feed-tile h3 {
  margin: 0 0 0.4em;
  font-size: 0.95em;
  font-weight: 600;
  color: #333;
}
.items {
  max-height: 12em;
  overflow-y: auto;
}
.items::-webkit-scrollbar {
  width: 4px;
}
.items::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

/* Feed Items */
.feed-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15em 0.4em;
  padding: 0.25em 0;
  border-bottom: 1px solid #f5f5f5;
}
.feed-item:last-child {
  border-bottom: none;
}
.items a {
  font-size: 0.85em;
  color: #007acc;
  text-decoration: none;
  transition: color 0.15s;
  line-height: 1.4;
}
.items a:hover {
  color: #005999;
  text-decoration: underline;
}
.items a.read-link {
  color: #aaa;
}
.items a.read-link:hover {
  color: #888;
}
.item-date {
  font-size: 0.7em;
  color: #aaa;
  white-space: nowrap;
  flex-shrink: 0;
}
.item-snippet {
  width: 100%;
  margin: 0.1em 0 0;
  font-size: 0.75em;
  color: #777;
  line-height: 1.35;
}

/* Unread Badge */
.unread-badge {
  font-size: 0.7em;
  color: #007acc;
  font-weight: 600;
  margin-left: auto;
  margin-right: 0.5em;
  white-space: nowrap;
}

/* Collapsible feeds */
.collapse-btn {
  font-size: 0.75em;
  color: #aaa;
  margin-right: 0.2em;
}

/* Bookmark button */
.bookmark-btn {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 0.95em;
  padding: 0 0.15em;
  flex-shrink: 0;
  transition: color 0.15s;
}
.bookmark-btn:hover {
  color: #f5a623;
}

/* Feed status */
.feed-status {
  font-size: 0.65em;
  color: #aaa;
  margin-top: 0.4em;
  padding-top: 0.3em;
  border-top: 1px solid #f0f0f0;
}

/* Drag and drop */
.dragging { opacity: 0.4; }
.drag-over {
  outline: 2px dashed #007acc;
  outline-offset: 2px;
}

/* Keyboard navigation */
.kb-focused {
  outline: 2px solid #007acc;
  outline-offset: 1px;
  border-radius: 4px;
}

/* Timeline view */
.timeline-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25em 0.6em;
  padding: 0.5em 0.8em;
  margin-bottom: 0.3em;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
  transition: box-shadow 0.15s;
}
.timeline-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.timeline-source {
  font-size: 0.65em;
  font-weight: 600;
  color: #fff;
  background: #007acc;
  padding: 0.15em 0.5em;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Compact view */
body.compact .feed-tile {
  padding: 0.4em 0.7em;
}
body.compact .feed-tile h3 {
  font-size: 0.85em;
  margin-bottom: 0.2em;
}
body.compact .items { max-height: 15em; }
body.compact .feed-item {
  margin: 0.05em 0;
  padding-bottom: 0.05em;
  gap: 0.1em 0.3em;
}
body.compact .item-snippet,
body.compact .item-date,
body.compact .feed-status { display: none; }
body.compact .items a { font-size: 0.8em; }
body.compact .bookmark-btn { font-size: 0.8em; }
body.compact .timeline-item {
  padding: 0.25em 0.5em;
  margin-bottom: 0.15em;
  gap: 0.15em 0.4em;
}
body.compact .timeline-item .item-snippet,
body.compact .timeline-item .item-date { display: none; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: #fff;
  padding: 1.5em;
  border-radius: 10px;
  max-width: 450px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.15);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1em;
}
.modal-header h3 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  color: inherit;
  padding: 0.2em;
  border-radius: 4px;
  transition: background 0.15s;
}
.modal-close:hover {
  background: #f0f0f0;
}

/* Form elements */
.form-group {
  margin-bottom: 0.8em;
}
.form-group label {
  display: block;
  font-size: 0.85em;
  font-weight: 500;
  margin-bottom: 0.3em;
  color: #555;
}
.form-input {
  width: 100%;
  padding: 0.5em 0.6em;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9em;
  transition: border-color 0.2s;
}
.form-input:focus {
  outline: none;
  border-color: #007acc;
  box-shadow: 0 0 0 2px rgba(0,122,204,0.1);
}
.input-with-btn {
  display: flex;
  gap: 0.4em;
}
.input-with-btn .form-input {
  flex: 1;
}
.input-with-btn .btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.discover-results {
  margin-top: 0.4em;
  font-size: 0.85em;
}
.discover-results .discover-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4em 0.5em;
  margin: 0.2em 0;
  background: #f5f8fa;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s;
}
.discover-results .discover-item:hover {
  background: #e8f4ff;
  border-color: #007acc;
}
.discover-results .discover-item .discover-url {
  font-size: 0.8em;
  color: #666;
  word-break: break-all;
}
.discover-msg {
  color: #999;
  font-size: 0.85em;
  padding: 0.3em 0;
}
body.dark .discover-results .discover-item {
  background: #15202b;
  border-color: #2a3a4a;
}
body.dark .discover-results .discover-item:hover {
  background: #223344;
  border-color: #4fc3f7;
}
body.dark .discover-results .discover-item .discover-url {
  color: #889;
}

.form-actions {
  display: flex;
  gap: 0.6em;
  justify-content: flex-end;
  margin-top: 1em;
}
.btn {
  padding: 0.5em 1em;
  border-radius: 6px;
  font-size: 0.85em;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: #007acc;
  color: #fff;
  border: 1px solid #007acc;
}
.btn-primary:hover {
  background: #005999;
  border-color: #005999;
}
.btn-secondary {
  background: #f5f5f5;
  color: #555;
  border: 1px solid #ddd;
}
.btn-secondary:hover {
  background: #e8e8e8;
}

/* Settings */
.settings-section {
  margin-bottom: 1.2em;
}
.settings-section h4 {
  margin: 0 0 0.5em;
  font-size: 0.75em;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 0.4em;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4em 0;
  font-size: 0.9em;
}
.settings-row select {
  padding: 0.3em 0.5em;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 0.85em;
}
.settings-btn {
  padding: 0.3em 0.8em;
  border: 1px solid #ddd;
  border-radius: 5px;
  background: #f5f5f5;
  cursor: pointer;
  font-size: 0.8em;
  transition: all 0.15s;
}
.settings-btn:hover { background: #e8e8e8; }
.settings-btn-danger {
  border-color: #e44;
  color: #e44;
}
.settings-btn-danger:hover {
  background: #fef0f0;
}

/* ========== DARK MODE ========== */
body.dark {
  background: #0f1923;
  color: #d4d4d4;
}
body.dark .app-header {
  background: #1a2733;
  border-bottom-color: #2a3a4a;
}
body.dark .app-title { color: #4fc3f7; }
body.dark .header-link {
  color: #4fc3f7;
}
body.dark .header-link:hover {
  background: rgba(79,195,247,0.1);
}
body.dark .icon-btn {
  color: #aaa;
  border-color: #2a3a4a;
}
body.dark .icon-btn:hover {
  background: rgba(79,195,247,0.1);
  border-color: #4fc3f7;
  color: #4fc3f7;
}

body.dark .tab-bar {
  background: #1a2733;
  border-bottom-color: #2a3a4a;
}
body.dark .tab-buttons button {
  color: #999;
}
body.dark .tab-buttons button:hover {
  background: #223344;
  color: #ccc;
}
body.dark .tab-buttons button.active-tab {
  background: #007acc;
  color: #fff;
  border-color: #007acc;
}

body.dark .toolbar {
  background: #15202b;
  border-bottom-color: #2a3a4a;
}
body.dark .search-bar {
  background: #1a2733;
  color: #d4d4d4;
  border-color: #2a3a4a;
}
body.dark .search-bar:focus {
  border-color: #4fc3f7;
  box-shadow: 0 0 0 2px rgba(79,195,247,0.15);
}
body.dark .toolbar-btn {
  background: #1a2733;
  color: #aaa;
  border-color: #2a3a4a;
}
body.dark .toolbar-btn:hover {
  background: #223344;
  border-color: #4fc3f7;
  color: #4fc3f7;
}
body.dark .toolbar-sep {
  background: #2a3a4a;
}

body.dark .feed-tile {
  background: #1a2733;
  border-color: #2a3a4a;
}
body.dark .feed-tile:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
body.dark .feed-tile h3 { color: #d4d4d4; }
body.dark .items a { color: #4fc3f7; }
body.dark .items a:hover { color: #81d4fa; }
body.dark .items a.read-link { color: #556; }
body.dark .items a.read-link:hover { color: #778; }
body.dark .item-date { color: #667; }
body.dark .item-snippet { color: #889; }
body.dark .feed-item { border-bottom-color: #223; }
body.dark .feed-item:last-child { border-bottom-color: transparent; }
body.dark .feed-status { border-top-color: #223; }
body.dark .items::-webkit-scrollbar-thumb { background: #445; }

body.dark .timeline-item {
  background: #1a2733;
  border-color: #2a3a4a;
}
body.dark .timeline-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
body.dark .timeline-source { background: #005999; }

body.dark .drag-over { outline-color: #4fc3f7; }
body.dark .kb-focused { outline-color: #4fc3f7; }

body.dark .modal-content {
  background: #1a2733;
  color: #d4d4d4;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}
body.dark .modal-close:hover { background: #223344; }
body.dark .form-group label { color: #aaa; }
body.dark .form-input {
  background: #15202b;
  color: #d4d4d4;
  border-color: #2a3a4a;
}
body.dark .form-input:focus {
  border-color: #4fc3f7;
  box-shadow: 0 0 0 2px rgba(79,195,247,0.15);
}
body.dark .btn-secondary {
  background: #15202b;
  color: #aaa;
  border-color: #2a3a4a;
}
body.dark .btn-secondary:hover { background: #223344; }

body.dark .settings-section h4 {
  color: #778;
  border-bottom-color: #2a3a4a;
}
body.dark .settings-row select {
  background: #15202b;
  color: #d4d4d4;
  border-color: #2a3a4a;
}
body.dark .settings-btn {
  background: #15202b;
  color: #aaa;
  border-color: #2a3a4a;
}
body.dark .settings-btn:hover { background: #223344; }
body.dark .settings-btn-danger {
  color: #f77;
  border-color: #f77;
}
body.dark .settings-btn-danger:hover { background: #2a1515; }
