/* CSS Variables - Night Mode (default, 6PM - 8AM) */
:root, [data-theme="night"] {
  --bg-gradient: linear-gradient(135deg, #0a0a12 0%, #12121f 40%, #0d0d18 100%);
  --bg-orb-1: rgba(99, 102, 241, 0.12);
  --bg-orb-2: rgba(139, 92, 246, 0.08);
  --bg-orb-3: rgba(88, 28, 135, 0.06);
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --glass-blur: blur(20px);
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.35);
  --accent: #818cf8;
  --accent-glow: rgba(129, 140, 248, 0.25);
  --time-gradient: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(200, 210, 255, 0.8) 50%, rgba(167, 139, 250, 0.9) 100%);
  --success: #34d399;
  --warning: #fbbf24;
  --error: #f87171;
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
}

/* Day Mode (8AM - 6PM) - Still dark but warmer tones */
[data-theme="day"] {
  --bg-gradient: linear-gradient(135deg, #1a1a24 0%, #252532 40%, #1e1e2a 100%);
  --bg-orb-1: rgba(251, 191, 36, 0.08);
  --bg-orb-2: rgba(245, 158, 11, 0.06);
  --bg-orb-3: rgba(217, 119, 6, 0.04);
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.4);
  --accent: #f59e0b;
  --accent-glow: rgba(245, 158, 11, 0.2);
  --time-gradient: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 245, 230, 0.85) 50%, rgba(251, 191, 36, 0.9) 100%);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 1s ease, color 0.5s ease;
}

/* Animated background orbs */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 20% 20%, var(--bg-orb-1) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, var(--bg-orb-2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, var(--bg-orb-3) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  transition: background 1s ease;
}

/* Dashboard Layout */
.dashboard {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  height: 100vh;
  max-height: 100vh;
  padding: 20px 28px;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  overflow: hidden;
}

.top-row, .bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: 0; /* Critical for flex/grid children to shrink */
}

/* Glass Widget Base */
.widget {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0; /* Allow shrinking */
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.widget:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* Expanded widget state */
.widget.expanded {
  position: fixed;
  top: 40px;
  left: 40px;
  right: 40px;
  bottom: 40px;
  z-index: 600;
  transform: none;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
}

.widget.expanded::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: -1;
}

.widget.expanded .widget-content {
  max-height: none;
}

.widget.expanded:hover {
  transform: none;
}

.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.widget-header h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-secondary);
}

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

.expand-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.expand-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.widget-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  min-height: 0; /* Critical for overflow to work in flex */
}

/* Buttons */
.refresh-btn, .add-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.refresh-btn:hover, .add-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  transform: scale(1.05);
}

.refresh-btn.loading {
  animation: spin 1s linear infinite;
}

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

/* Clock Section */
.clock-section {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.clock-container {
  text-align: center;
}

.date {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.time {
  font-size: clamp(48px, 10vw, 88px);
  font-weight: 200;
  letter-spacing: -2px;
  background: var(--time-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  filter: drop-shadow(0 0 60px var(--accent-glow));
  transition: background 1s ease, filter 1s ease;
}

.greeting {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 12px;
  letter-spacing: 0.3px;
}

/* Email Widget */
.email-list {
  list-style: none;
}

.email-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 4px;
}

.email-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.email-item.unread {
  background: rgba(99, 102, 241, 0.1);
  border-left: 2px solid var(--accent);
}

.email-from {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.email-from .badge {
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.important {
  background: rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

.badge.starred {
  background: rgba(99, 102, 241, 0.2);
  color: var(--accent);
}

.email-subject {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.email-date {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Auth Prompt */
.auth-prompt {
  text-align: center;
  padding: 32px 20px;
}

.auth-prompt p {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 13px;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.auth-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

/* Calendar Widget */
.event-list {
  list-style: none;
}

.event-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 2px solid var(--accent);
  transition: all 0.2s ease;
}

.event-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.event-item.google {
  border-left-color: #4285f4;
}

.event-item.apple {
  border-left-color: #ff3b30;
}

.event-time {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.event-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.event-location {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Notes Widget */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  padding: 4px;
}

.note-card {
  padding: 12px;
  border-radius: var(--radius-sm);
  min-height: 80px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(0, 0, 0, 0.75);
  word-wrap: break-word;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.note-card:hover {
  transform: translateY(-2px) rotate(1deg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* News Widget */
.news-list {
  list-style: none;
}

.news-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 4px;
}

.news-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.news-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.news-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
}

.news-source {
  color: var(--accent);
  font-weight: 500;
}

/* Settings Button */
.settings-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border: none;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: var(--glass-shadow);
  transition: all 0.3s ease;
  z-index: 100;
}

.settings-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-primary);
  transform: rotate(90deg) scale(1.1);
  border-color: var(--accent);
}

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

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--glass-bg);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  width: 90%;
  max-width: 480px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.close-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Settings */
.setting-group {
  margin-bottom: 24px;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.setting-group input,
.setting-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 13px;
  transition: all 0.2s ease;
}

.setting-group input:focus,
.setting-group select:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.setting-group select option {
  background: #1a1a2e;
  color: var(--text-primary);
}

.help-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* RSS Feeds List */
.feeds-list {
  margin-bottom: 12px;
  max-height: 150px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-xs);
  margin-bottom: 6px;
  border: 1px solid var(--glass-border);
}

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

.feed-item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

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

.feed-item-delete {
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(248, 113, 113, 0.1);
  color: var(--error);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  margin-left: 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feed-item-delete:hover {
  background: rgba(248, 113, 113, 0.2);
}

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

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

.feed-add-form .save-btn {
  margin-top: 4px;
}

.save-btn {
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.2s ease;
}

.save-btn:hover {
  background: #818cf8;
  transform: translateY(-1px);
}

.delete-btn {
  padding: 10px 18px;
  background: rgba(248, 113, 113, 0.2);
  color: var(--error);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.delete-btn:hover {
  background: rgba(248, 113, 113, 0.3);
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

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

.theme-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.1);
}

/* Note Editor */
.note-editor {
  max-width: 380px;
}

#note-textarea {
  width: 100%;
  height: 140px;
  padding: 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 13px;
  resize: none;
  font-family: inherit;
  line-height: 1.5;
  transition: all 0.2s ease;
}

#note-textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.note-colors {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.color-btn {
  width: 28px;
  height: 28px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.color-btn:hover {
  transform: scale(1.15);
}

.color-btn.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.note-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* Loading States */
.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 32px;
}

.loading-spinner::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Responsive */
@media (max-width: 1200px) {
  .dashboard {
    padding: 20px 24px;
  }
}

@media (max-width: 900px) {
  .top-row, .bottom-row {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-template-rows: auto auto auto;
    min-height: auto;
    padding: 16px;
  }

  .clock-section {
    order: -1;
    padding: 32px 0;
  }
}

@media (max-width: 600px) {
  .time {
    font-size: 48px;
  }

  .dashboard {
    gap: 12px;
  }

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

  .widget-content {
    padding: 6px;
  }
}
