/* ============================================================
   WIDGET DASHBOARD — Design System
   ============================================================ */

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

/* ---- Tokens ---- */
:root {
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Dark theme (default) */
  --bg-base:        #07090f;
  --bg-surface:     #0d1117;
  --bg-card:        rgba(255,255,255,0.04);
  --bg-card-hover:  rgba(255,255,255,0.07);
  --bg-modal:       #111827;
  --bg-input:       rgba(255,255,255,0.06);

  --border-subtle:  rgba(255,255,255,0.08);
  --border-card:    rgba(255,255,255,0.1);
  --border-focus:   var(--accent);

  --text-primary:   #f0f4ff;
  --text-secondary: #8b9cc8;
  --text-muted:     #4b5680;
  --text-inverse:   #07090f;

  --accent:         #7c3aed;
  --accent-light:   #a855f7;
  --accent-glow:    rgba(124,58,237,0.35);
  --cyan:           #06b6d4;
  --cyan-glow:      rgba(6,182,212,0.25);
  --green:          #10b981;
  --red:            #ef4444;
  --amber:          #f59e0b;

  --topbar-h:       56px;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --radius-xl:      20px;

  --shadow-card:    0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
  --shadow-modal:   0 24px 80px rgba(0,0,0,0.7);
  --shadow-glow:    0 0 24px var(--accent-glow);

  --transition:     0.18s cubic-bezier(0.4,0,0.2,1);
  --transition-slow:0.35s cubic-bezier(0.4,0,0.2,1);
}

/* AMOLED theme — negro puro */
body.theme-amoled {
  --bg-base:        #000000;
  --bg-surface:     #000000;
  --bg-card:        rgba(255,255,255,0.05);
  --bg-card-hover:  rgba(255,255,255,0.09);
  --bg-modal:       #0a0a0a;
  --bg-input:       rgba(255,255,255,0.07);

  --border-subtle:  rgba(255,255,255,0.07);
  --border-card:    rgba(255,255,255,0.12);

  --text-primary:   #ffffff;
  --text-secondary: #9ba8c8;
  --text-muted:     #4a5270;

  --shadow-card:    0 4px 24px rgba(0,0,0,0.8), 0 1px 4px rgba(0,0,0,0.6);
  --shadow-modal:   0 24px 80px rgba(0,0,0,0.95);
}
.theme-amoled .canvas-grid {
  background-image: radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* Light theme */
body.theme-light {
  --bg-base:        #f0f2f8;
  --bg-surface:     #e8ebf4;
  --bg-card:        rgba(255,255,255,0.85);
  --bg-card-hover:  rgba(255,255,255,0.95);
  --bg-modal:       #ffffff;
  --bg-input:       rgba(0,0,0,0.05);

  --border-subtle:  rgba(0,0,0,0.07);
  --border-card:    rgba(0,0,0,0.1);

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --text-inverse:   #f0f4ff;

  --shadow-card:    0 4px 20px rgba(0,0,0,0.1), 0 1px 4px rgba(0,0,0,0.07);
  --shadow-modal:   0 24px 60px rgba(0,0,0,0.2);
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition-slow), color var(--transition-slow);
}

/* ---- Topbar ---- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  backdrop-filter: blur(12px);
  gap: 16px;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-center { flex: 1; text-align: center; }

.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon {
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-text {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 60%, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status-text {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: color var(--transition);
}
.status-text.saved { color: var(--green); }
.status-text.error { color: var(--red); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}
.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-card);
}

.btn-icon {
  padding: 7px;
  aspect-ratio: 1;
}
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border-color: rgba(239,68,68,0.25); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

/* ---- Canvas ---- */
.canvas {
  position: relative;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

.canvas-grid {
  position: relative;
  width: 100%;
  min-height: calc(100vh - var(--topbar-h));
}

/* Subtle dot grid background */
.theme-dark .canvas-grid {
  background-image: radial-gradient(circle, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 28px 28px;
}
.theme-light .canvas-grid {
  background-image: radial-gradient(circle, rgba(0,0,0,0.07) 1px, transparent 1px);
  background-size: 28px 28px;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--transition-slow);
}
.canvas-empty.hidden { opacity: 0; pointer-events: none; }

.empty-icon {
  font-size: 56px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.4;
}
.canvas-empty h2 { font-size: 22px; font-weight: 700; color: var(--text-secondary); }
.canvas-empty p { font-size: 15px; color: var(--text-muted); }
.canvas-empty .btn { pointer-events: all; }

/* ---- Widget Card ---- */
.widget-card {
  position: absolute;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition), border-color var(--transition);
  animation: widget-appear 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
  min-width: 160px;
  min-height: 100px;
  touch-action: none;
  user-select: none;
}

.widget-card:hover {
  border-color: var(--border-card);
  box-shadow: var(--shadow-card), 0 0 0 1px var(--border-card);
}
.widget-card.dragging {
  box-shadow: var(--shadow-card), var(--shadow-glow);
  border-color: var(--accent);
  z-index: 50 !important;
  opacity: 0.92;
}

@keyframes widget-appear {
  from { opacity: 0; transform: scale(0.88) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.widget-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border-subtle);
  cursor: grab;
  flex-shrink: 0;
}
.widget-header:active { cursor: grabbing; }

.widget-icon { font-size: 15px; line-height: 1; flex-shrink: 0; }
.widget-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.widget-actions { display: flex; gap: 2px; flex-shrink: 0; }
.widget-action-btn {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 12px;
}
.widget-action-btn:hover { background: var(--bg-input); color: var(--text-primary); }
.widget-action-btn.close:hover { background: rgba(239,68,68,0.15); color: var(--red); }

.widget-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Resize handle */
.resize-handle {
  position: absolute;
  bottom: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize;
  display: flex; align-items: flex-end; justify-content: flex-end;
  padding: 3px;
  opacity: 0;
  transition: opacity var(--transition);
}
.widget-card:hover .resize-handle { opacity: 1; }
.resize-handle svg { color: var(--text-muted); }

/* ---- Widget Library Modal ---- */
.widget-library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.widget-lib-item {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.widget-lib-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-glow);
}
.widget-lib-icon { font-size: 32px; }
.widget-lib-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.widget-lib-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(12px);
  transition: transform var(--transition-slow);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-sm { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 18px; font-weight: 700; color: var(--text-primary); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* ---- Config Forms ---- */
.config-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.4px; text-transform: uppercase; }

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b9cc8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text-primary); }
.checkbox-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---- Widget: Clock ---- */
.clock-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 4px;
  height: 100%;
  text-align: center;
}
.clock-time {
  font-family: var(--font-mono);
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -1px;
  line-height: 1;
  background: linear-gradient(135deg, var(--text-primary) 40%, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.clock-seconds { font-size: 0.5em; color: var(--accent-light); -webkit-text-fill-color: var(--accent-light); }
.clock-date { font-size: 12px; color: var(--text-secondary); font-weight: 500; letter-spacing: 0.5px; margin-top: 4px; }
.clock-tz { font-size: 10px; color: var(--text-muted); letter-spacing: 0.3px; }

/* ---- Widget: Weather ---- */
.weather-widget {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}
.weather-main { display: flex; align-items: center; gap: 12px; }
.weather-icon-big { font-size: 42px; flex-shrink: 0; }
.weather-temp-block { display: flex; flex-direction: column; }
.weather-temp {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.weather-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; text-transform: capitalize; }
.weather-city { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.weather-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}
.weather-detail { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.weather-detail-icon { font-size: 14px; }
.weather-loading, .weather-error { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---- Widget: Dollar ---- */
.dollar-widget { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; height: 100%; overflow-y: auto; }
.dollar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--transition);
}
.dollar-row:hover { border-color: var(--border-card); }
.dollar-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.dollar-values { display: flex; gap: 12px; }
.dollar-val { text-align: right; }
.dollar-val-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.dollar-val-amount { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--text-primary); }
.dollar-updated { font-size: 10px; color: var(--text-muted); text-align: right; }

/* ---- Widget: Ping ---- */
.ping-widget { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; height: 100%; overflow-y: auto; }
.ping-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}
.ping-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  background: var(--text-muted);
  transition: background var(--transition);
}
.ping-dot.up { background: var(--green); box-shadow: 0 0 8px var(--green); }
.ping-dot.down { background: var(--red); box-shadow: 0 0 8px var(--red); }
.ping-dot.checking {
  background: var(--amber);
  animation: ping-pulse 1s ease-in-out infinite;
}
@keyframes ping-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.ping-label { flex: 1; font-size: 13px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ping-status { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); flex-shrink: 0; }
.ping-add-btn { display: flex; gap: 6px; margin-top: 4px; }
.ping-add-btn input { flex: 1; }

/* ---- Widget: Notes ---- */
.notes-widget { height: 100%; display: flex; flex-direction: column; }
.notes-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
}
.notes-textarea::placeholder { color: var(--text-muted); }

/* ---- Widget: Crypto ---- */
.crypto-widget { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; height: 100%; overflow-y: auto; }
.crypto-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-input); border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); }
.crypto-symbol { font-weight: 700; font-size: 13px; width: 60px; color: var(--text-primary); }
.crypto-price { flex: 1; font-family: var(--font-mono); font-size: 13px; color: var(--text-primary); }
.crypto-change { font-size: 12px; font-weight: 600; }
.crypto-change.up { color: var(--green); }
.crypto-change.down { color: var(--red); }

/* ---- Widget: iFrame ---- */
.iframe-widget { height: 100%; display: flex; flex-direction: column; }
.iframe-widget iframe { flex: 1; border: none; width: 100%; min-height: 0; }
.iframe-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px; }

/* ---- Widget: RSS ---- */
.rss-widget { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; height: 100%; overflow-y: auto; }
.rss-item { padding: 8px 0; border-bottom: 1px solid var(--border-subtle); }
.rss-item:last-child { border-bottom: none; }
.rss-item-title { font-size: 13px; font-weight: 500; color: var(--text-primary); line-height: 1.4; margin-bottom: 3px; }
.rss-item-title a { color: inherit; text-decoration: none; }
.rss-item-title a:hover { color: var(--accent-light); }
.rss-item-date { font-size: 10px; color: var(--text-muted); }
.rss-source { font-size: 11px; color: var(--text-muted); padding: 4px 0 8px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 4px; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-card); }

/* ---- Pulse animation for live data ---- */
.live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  margin-left: 4px;
  animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.5;transform:scale(0.8)} }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-modal);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  z-index: 999;
  animation: toast-in 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
  display: flex;
  align-items: center;
  gap: 8px;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.success::before { content: '✓'; color: var(--green); font-weight: 700; }
.toast.error::before   { content: '✕'; color: var(--red);   font-weight: 700; }
.toast.info::before    { content: 'ℹ'; color: var(--cyan);  font-weight: 700; }
