/*
 * CryptoDesk Main Dashboard Stylesheet
 * Custom CSS utilizing vanilla variables, clean SaaS metrics, and premium UI states.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--text-main);
}

a {
  text-decoration: none;
  color: inherit;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
}

/* Header styling */
.app-header {
  height: 64px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  background-color: var(--primary);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.app-title span {
  color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.refresh-info {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-family: monospace;
}

/* Toast Notification Styles */
.sync-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--text-main);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  cursor: pointer;
}

.sync-toast.show {
  transform: translateY(0);
  opacity: 1;
}

.sync-toast:hover {
  background-color: #000;
}

.sync-pulse {
  animation: pulseOpacity 1.5s infinite ease-in-out;
}

@keyframes pulseOpacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  border: 1px solid transparent;
  outline: none;
  font-size: 14px;
}

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

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

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: var(--bg-main);
  border-color: #cbd5e1;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

/* App Body Layout */
.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Sidebar Styling */
.app-sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 20px 16px;
  gap: 24px;
}

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  padding-left: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.collapsible-header {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}

.collapsible-header:hover {
  color: var(--text-main);
}

.collapsible-header .chevron-icon {
  transition: transform 0.3s ease;
  opacity: 0.7;
}

.collapsible-header.collapsed .chevron-icon {
  transform: rotate(-90deg);
}

.sidebar-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-list.collapsed {
  display: none !important;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
}

.sidebar-item:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
}

.sidebar-item.active {
  background-color: #eff6ff;
  color: var(--primary);
}

.sidebar-item-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-item-badge {
  font-size: 11px;
  background-color: #f1f5f9;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-item.active .sidebar-item-badge {
  background-color: #dbeafe;
  color: var(--primary);
}

/* Source item special style */
.source-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--border-color);
  flex-shrink: 0;
}

.source-status.ok {
  background-color: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.source-status.error {
  background-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* Main Dashboard Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 24px;
  gap: 20px;
}

/* Statistics row */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  flex-shrink: 0;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background-color: #f1f5f9;
}

.stat-card.stat-total .stat-icon { color: var(--primary); background-color: #eff6ff; }
.stat-card.stat-new .stat-icon { color: var(--success); background-color: #ecfdf5; }
.stat-card.stat-alerts .stat-icon { color: var(--danger); background-color: #fef2f2; }
.stat-card.stat-sources .stat-icon { color: var(--warning); background-color: #fffbeb; }

.stat-details {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Actions Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

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

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  outline: none;
  font-size: 14px;
  color: var(--text-main);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

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

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.select-dropdown {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  outline: none;
  font-size: 14px;
  cursor: pointer;
}

.select-dropdown:focus {
  border-color: var(--primary);
}

.view-toggles {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-btn {
  border: none;
  background: var(--bg-card);
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

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

.view-btn.active {
  background-color: #f1f5f9;
  color: var(--primary);
}

/* Feed Listing Container */
.feed-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}

/* Grid View CSS */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* List View CSS */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Article Card Styles */
.article-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
}

.article-card:hover {
  transform: translateY(-2px);
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

/* Unread Indicator Bar */
.article-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 4px;
  background-color: var(--primary);
  border-radius: 0 4px 4px 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.article-card.unread::before {
  opacity: 1;
}

.article-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.article-source-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.article-source-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background-color: #eff6ff;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.article-time {
  font-size: 12px;
  color: var(--text-muted);
}

.article-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-main);
  transition: color var(--transition-fast);
}

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

.article-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* List view adjustments */
.articles-list .article-card {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
}

.articles-list .article-card::before {
  top: 12px;
  bottom: 12px;
}

.articles-list .article-left {
  flex: 1;
  min-width: 0;
  padding-right: 24px;
}

.articles-list .article-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.articles-list .article-header {
  margin-bottom: 4px;
}

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

.articles-list .article-desc {
  font-size: 12px;
  margin-bottom: 0;
  -webkit-line-clamp: 1;
}

/* Footer elements of Grid Card */
.article-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
  gap: 8px;
}

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

.topic-tag {
  font-size: 11px;
  font-weight: 500;
  background-color: #f1f5f9;
  color: #475569;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

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

.action-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.action-icon:hover {
  background-color: #f1f5f9;
  color: var(--text-main);
}

/* Badges for alert tiers */
.alert-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.alert-badge.high {
  background-color: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-badge.low {
  background-color: #fffbeb;
  color: var(--warning);
  border: 1px solid #fef3c7;
}

.alert-badge.info {
  background-color: #eff6ff;
  color: var(--primary);
  border: 1px solid #dbeafe;
}

/* Status Panel (displayed inside Sidebar / Header) */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

/* Loading States */
.sync-spinning {
  animation: spin 1s linear infinite;
}

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

.skeleton-card {
  height: 180px;
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-text {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
}

/* Sidebar toggling */
.sidebar-toggle-btn {
  display: none;
}

/* Responsive Breakpoints */

/* Tablet & Mobile Layouts */
@media (max-width: 1023px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 767px) {
  body {
    position: relative;
  }
  
  .sidebar-toggle-btn {
    display: block;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-main);
  }

  .app-sidebar {
    position: absolute;
    left: -280px;
    top: 64px;
    bottom: 0;
    z-index: 100;
    transition: left var(--transition-normal);
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.active {
    left: 0;
  }
  
  .app-main {
    padding: 16px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .search-wrapper {
    max-width: 100%;
  }

  .toolbar-controls {
    justify-content: space-between;
  }
  
  .articles-grid {
    grid-template-columns: 1fr;
  }

  .articles-list .article-card {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }

  .articles-list .article-card::before {
    top: 16px;
    bottom: 16px;
  }

  .articles-list .article-right {
    margin-top: 12px;
    justify-content: space-between;
  }
  
  .articles-list .article-left {
    padding-right: 0;
  }
}

/* Enhancements: Stats Grid Responsive Columns */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  flex-shrink: 0;
}

/* Enhancements: Dashboard Sub-Tabs Navigation */
.dashboard-tabs {
  display: flex;
  gap: 12px;
  border-bottom: 2px solid var(--border-color);
  margin-top: 8px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.dash-tab {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 16px;
  cursor: pointer;
  position: relative;
  transition: color var(--transition-fast);
}

.dash-tab:hover {
  color: var(--text-main);
}

.dash-tab.active {
  color: var(--primary);
}

.dash-tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background-color: var(--primary);
  border-radius: 3px 3px 0 0;
}

/* View Panels */
.view-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.view-panel.active {
  display: flex;
}

/* Source Monitor Grid */
.sources-monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  overflow-y: auto;
  padding-bottom: 20px;
  flex: 1;
}

/* Source Card Styling */
.source-monitor-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
}

.source-monitor-card:hover {
  transform: translateY(-2px);
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.source-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.source-card-title-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-avatar-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  text-transform: uppercase;
}

.source-card-name {
  font-size: 15px;
  font-weight: 600;
}

/* Health status lights */
.health-status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.health-status-badge.live {
  background-color: #ecfdf5;
  color: var(--success);
  border: 1px solid #d1fae5;
}

.health-status-badge.warning {
  background-color: #fffbeb;
  color: var(--warning);
  border: 1px solid #fef3c7;
}

.health-status-badge.error {
  background-color: #fef2f2;
  color: var(--danger);
  border: 1px solid #fee2e2;
}

/* Table detail rows inside card */
.source-details-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.source-details-table tr {
  border-bottom: 1px solid #f1f5f9;
}

.source-details-table tr:last-child {
  border-bottom: none;
}

.source-details-table td {
  padding: 6px 0;
  color: var(--text-main);
}

.source-details-table td.label {
  color: var(--text-muted);
  font-weight: 500;
}

.source-details-table td.value {
  text-align: right;
  font-weight: 600;
}

.source-error-desc {
  font-size: 11px;
  color: var(--danger);
  background-color: #fef2f2;
  padding: 8px;
  border-radius: 4px;
  border: 1px dashed #fca5a5;
  margin-top: 4px;
  word-break: break-word;
  max-height: 52px;
  overflow-y: auto;
}

/* Specific Article Card Source Border Accent Highlights */
.article-card.source-cointelegraph { border-top: 3px solid #f5a623; }
.article-card.source-coindesk { border-top: 3px solid #0080ff; }
.article-card.source-decrypt { border-top: 3px solid #0f172a; }
.article-card.source-crypto-briefing { border-top: 3px solid #3c5cd6; }
.article-card.source-bitcoin-news { border-top: 3px solid #f7931a; }
.article-card.source-bitcoin-magazine { border-top: 3px solid #ff5a00; }
.article-card.source-cryptoslate { border-top: 3px solid #1a33f3; }
.article-card.source-newsbtc { border-top: 3px solid #f44336; }
.article-card.source-cryptopotato { border-top: 3px solid #4caf50; }
.article-card.source-beincrypto { border-top: 3px solid #00e676; }
.article-card.source-u-today { border-top: 3px solid #ff3366; }
.article-card.source-default { border-top: 3px solid var(--primary); }

/* Avatar branding background colors */
.avatar-cointelegraph { background-color: #f5a623; }
.avatar-coindesk { background-color: #0080ff; }
.avatar-decrypt { background-color: #0f172a; }
.avatar-crypto-briefing { background-color: #3c5cd6; }
.avatar-bitcoin-news { background-color: #f7931a; }
.avatar-bitcoin-magazine { background-color: #ff5a00; }
.avatar-cryptoslate { background-color: #1a33f3; }
.avatar-newsbtc { background-color: #f44336; }
.avatar-cryptopotato { background-color: #4caf50; }
.avatar-beincrypto { background-color: #00e676; }
.avatar-u-today { background-color: #ff3366; }
.avatar-default { background-color: var(--primary); }

