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

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a26;
  --bg-hover: #222236;
  --border: #2a2a3a;
  --border-light: #3a3a50;
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent: #6366f1;
  --accent-hover: #7577f5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --danger: #ef4444;
  --success: #22c55e;
  --sidebar-width: 240px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

.tab-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-secondary);
  transition: all 0.15s;
  border-left: 3px solid transparent;
  user-select: none;
}

.tab-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tab-item.active {
  background: rgba(99, 102, 241, 0.08);
  color: var(--text-primary);
  border-left-color: var(--accent);
}

.tab-item .tab-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.tab-item .tab-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-item .tab-edit {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.tab-item:hover .tab-edit {
  opacity: 1;
}

.tab-item .tab-edit:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.add-tab-btn {
  margin: 8px 16px;
  padding: 8px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.add-tab-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
}

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

.import-btn {
  width: 100%;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.import-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ========== MAIN CONTENT ========== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  min-height: 100vh;
}

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

.tab-title {
  font-size: 1.5rem;
  font-weight: 700;
}

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

.btn-icon {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-icon.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-icon.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  box-shadow: none;
}

/* ========== WIDGET GRID ========== */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  align-items: start;
}

.widget-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s;
  cursor: grab;
}

.widget-card:hover {
  border-color: var(--border-light);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.widget-card.dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.widget-card.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.widget-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}

.widget-header-left .widget-type-badge {
  font-size: 1.1rem;
}

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

.widget-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.widget-actions button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.widget-body {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

/* Scrollbar styling */
.widget-body::-webkit-scrollbar { width: 6px; }
.widget-body::-webkit-scrollbar-track { background: transparent; }
.widget-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.widget-body::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ========== RSS WIDGET ========== */
.feed-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.feed-item:last-child { border-bottom: none; }

.feed-item a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.4;
  display: block;
  transition: color 0.15s;
}

.feed-item a:hover { color: var(--accent); }

.feed-item .feed-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.feed-add-btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
  margin-top: 8px;
}

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

.feed-section {
  margin-bottom: 16px;
}

.feed-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  margin-bottom: 4px;
}

.feed-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.feed-section-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.feed-section-actions button:hover {
  color: var(--accent);
}

/* ========== NOTES WIDGET ========== */
.notes-textarea {
  width: 100%;
  min-height: 150px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.notes-textarea::placeholder {
  color: var(--text-muted);
}

.notes-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 8px;
}

/* ========== BOOKMARKS WIDGET ========== */
.bookmark-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: all 0.15s;
  margin-bottom: 4px;
}

.bookmark-item:hover {
  background: var(--bg-hover);
}

.bookmark-icon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  background: var(--bg-hover);
  flex-shrink: 0;
}

.bookmark-item a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bookmark-item a:hover { color: var(--accent); }

.bookmark-item .bookmark-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 4px;
}

.bookmark-item:hover .bookmark-delete { opacity: 1; }
.bookmark-item .bookmark-delete:hover { color: var(--danger); }

/* ========== CLOCK WIDGET ========== */
.clock-container {
  text-align: center;
  padding: 20px 0;
}

.clock-time {
  font-size: 3rem;
  font-weight: 200;
  color: var(--accent);
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 2px;
}

.clock-seconds {
  font-size: 1.2rem;
  color: var(--text-muted);
  vertical-align: super;
}

.clock-date {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ========== MODALS ========== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ========== WIDGET TYPE GRID ========== */
.widget-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.widget-type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  color: var(--text-primary);
}

.widget-type-card:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
  box-shadow: 0 0 16px var(--accent-glow);
}

.widget-type-icon { font-size: 2rem; }
.widget-type-name { font-weight: 600; font-size: 0.95rem; }
.widget-type-desc { font-size: 0.8rem; color: var(--text-secondary); }

/* ========== FORM ELEMENTS ========== */
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  margin-top: 16px;
}

label:first-child { margin-top: 0; }

input[type="text"],
input[type="url"],
input[type="file"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="url"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="file"] {
  padding: 8px;
  cursor: pointer;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  padding: 10px 20px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* ========== LOADING ========== */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ========== BROWSE SOURCES ========== */
.modal-large {
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
}

.source-search {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  margin-bottom: 16px;
}

.source-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.source-categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.category-pill {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.category-pill:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.category-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.source-card {
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: left;
  transition: all 0.15s;
}

.source-card:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
}

.source-card-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
  display: block;
}

.source-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: block;
  margin-bottom: 4px;
}

.source-card-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 10px;
  line-height: 1.3;
}

.source-card-add {
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  width: 100%;
  transition: all 0.15s;
}

.source-card-add:hover {
  background: var(--accent-hover);
}

.custom-reddit-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.custom-reddit-section h3 {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.custom-reddit-section form {
  display: flex;
  gap: 8px;
}

.custom-reddit-section input {
  flex: 1;
}

/* ========== WEATHER WIDGET ========== */
.weather-container {
  text-align: center;
  padding: 16px 0;
}

.weather-location {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.weather-current {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.weather-icon {
  font-size: 3rem;
}

.weather-temp {
  font-size: 2.5rem;
  font-weight: 300;
  color: var(--accent);
}

.weather-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  text-transform: capitalize;
}

.weather-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 0.85rem;
}

.weather-detail {
  padding: 8px;
  background: var(--bg-hover);
  border-radius: 6px;
}

.weather-detail-label {
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.weather-detail-value {
  color: var(--text-primary);
  font-weight: 600;
}

.weather-change-location {
  margin-top: 16px;
  padding: 6px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
}

.weather-change-location:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ========== RESPONSIVE ========== */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 101;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.2rem;
}

.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar { width: 200px; }
  :root { --sidebar-width: 200px; }
  .main-content { padding: 16px; }
  .widget-grid { grid-template-columns: 1fr; }
  .widget-type-grid { grid-template-columns: 1fr; }
  .source-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px; }
  .header-actions { flex-wrap: wrap; gap: 6px; }
  .btn-icon { padding: 6px 12px; font-size: 0.85rem; }
}

@media (max-width: 640px) {
  .mobile-menu-toggle { display: block; }
  .mobile-overlay.active { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  :root { --sidebar-width: 0px; }
  .main-content { margin-left: 0; padding-top: 60px; }

  .content-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .header-actions {
    width: 100%;
  }

  .btn-icon {
    flex: 1;
    min-width: 120px;
  }

  .modal {
    width: 95%;
    padding: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-large {
    width: 95%;
  }

  .widget-type-grid {
    gap: 10px;
  }

  .widget-type-card {
    padding: 16px;
  }

  .category-pill {
    font-size: 0.8rem;
    padding: 5px 12px;
  }

  .custom-reddit-section form {
    flex-direction: column;
  }

  .weather-details {
    grid-template-columns: 1fr;
  }
}
