*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
input, button, select, textarea { font-family: inherit; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242733;
  --border: #2e3142;
  --text: #e4e6f0;
  --text-dim: #8b8fa3;
  --green: #00d26a;
  --green-bg: rgba(0,210,106,0.1);
  --red: #ff4d4f;
  --red-bg: rgba(255,77,79,0.1);
  --blue: #4f8cff;
  --blue-bg: rgba(79,140,255,0.1);
  --orange: #f5a623;
  --orange-bg: rgba(245,166,35,0.1);
  --purple: #a855f7;
  --purple-bg: rgba(168,85,247,0.1);
  --gold: #fbbf24;
  --gold-bg: rgba(251,191,36,0.1);
  --cyan: #06b6d4;
  --cyan-bg: rgba(6,182,212,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1.5rem;
}

.container { max-width: 1800px; margin: 0 auto; }

header {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; cursor: pointer; }
.dashboard-title-input {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  background: var(--surface2);
  border: 1px solid var(--orange);
  border-radius: 6px;
  color: var(--text);
  padding: 0.1rem 0.4rem;
  outline: none;
  width: 280px;
}
.minimize-btn { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); cursor: pointer; font-size: 0.85rem; padding: 0.25rem 0.55rem; transition: all 0.15s; }
.minimize-btn:hover { border-color: var(--blue); color: var(--blue); }
.tile.tile-collapsed > .tile-content { display: none; }
.tile.tile-collapsed > .tile-header { border-bottom: none; cursor: pointer; }
.dashboard-grid.minimized .tile { cursor: grab; }
.dashboard-grid.minimized .tile.dragging { opacity: 0.3; }
.dashboard-grid.minimized .tile.drag-over { border-top: 2px solid var(--blue); }

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: pulse 2s infinite;
}
.status-dot.error { background: var(--red); animation: none; }
.status-dot.warn { background: var(--orange); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Currency toggle */
.currency-toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.currency-toggle button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.currency-toggle button.active {
  background: var(--blue-bg);
  color: var(--blue);
}

/* Language toggle */
.lang-toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-toggle button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.lang-toggle button.active {
  background: var(--blue-bg);
  color: var(--blue);
}

/* ===== TILE SYSTEM ===== */
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.tile-header h2 {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tile-header .tile-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-weight: 500;
}
.tile-content {
  padding: 0.8rem 1.2rem;
}

/* ===== TILE OVERVIEW (compact card for tile mode) ===== */
.tile-ov { display: flex; flex-direction: column; gap: 0.3rem; }
.tile-ov-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  line-height: 1.4;
}
.tile-ov-primary {
  font-size: 1.05rem;
  font-weight: 700;
}
.tile-ov-label {
  color: var(--text-dim);
  font-size: 0.72rem;
}
.tile-ov-dim {
  color: var(--text-dim);
  font-size: 0.7rem;
}
.tile-ov-more {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  padding-top: 0.2rem;
  cursor: pointer;
}
.tile-ov-more:hover { color: var(--blue); }
.tile-ov-header {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 500;
  margin-top: 0.2rem;
  margin-bottom: -0.1rem;
}
.tile-ov-header:first-child { margin-top: 0; }

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.2rem;
  align-items: start;
}

/* Expanded or configuring tiles span full width */
.dashboard-grid .tile:has(
  .portfolio-detail.open,
  .health-detail.open,
  .fin-detail.open,
  .cal-detail.open,
  .todo-detail.open,
  .calories-detail.open,
  .weather-detail.open,
  .football-detail.open,
  .youtube-detail.open,
  .esports-detail.open,
  .streaming-detail.open,
  .energy-detail.open,
  .shopping-detail.open,
  .transport-detail.open,
  .car-detail.open,
  .x-detail.open,
  .cfg-panel.open
) {
  grid-column: 1 / -1;
}

.load-more-btn {
  width: 100%;
  padding: 0.55rem;
  margin-top: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.load-more-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-bg);
}

.tile-loading {
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 1.5rem 0;
  text-align: center;
}
.tile-error {
  color: var(--red);
  font-size: 0.75rem;
  padding: 1rem 0;
  text-align: center;
  opacity: 0.7;
}

/* Shared date navigation arrows */
.date-nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.25rem 0.45rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.date-nav-btn:hover { border-color: var(--text); color: var(--text); }

/* Tile header color picker */
.tile-color-input {
  position: absolute;
  width: 0; height: 0;
  opacity: 0;
  pointer-events: none;
}
.tile-header h2 { cursor: pointer; }



