/* ═══════════════════════════════════════════════════════════
   Drasi Dashboard — Dark Theme
   ═══════════════════════════════════════════════════════════ */

/* ─── Design Tokens ──────────────────────────────────────── */
:root {
  --bg-base: #0a0f0a;
  --bg-surface: #121a14;
  --bg-elevated: #1a2820;
  --bg-overlay: #22332a;
  --bg-hover: #264032;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text-primary: #f0f0f5;
  --text-secondary: #9d9db5;
  --text-muted: #6b6b80;
  --text-inverse: #0a0a0f;

  --accent: #4ade80;
  --accent-hover: #86efac;
  --accent-muted: rgba(74, 222, 128, 0.15);
  --accent-glow: rgba(74, 222, 128, 0.25);

  --success: #34d399;
  --success-muted: rgba(52, 211, 153, 0.15);
  --warning: #fbbf24;
  --warning-muted: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --danger-muted: rgba(248, 113, 113, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-accent: 0 0 20px var(--accent-glow);
  --shadow-glow: 0 0 30px rgba(74, 222, 128, 0.12);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

/* ─── Light Theme Tokens ─────────────────────────────────── */
[data-theme="light"] {
  --bg-base: #f8faf9;
  --bg-surface: #ffffff;
  --bg-elevated: #f0f4f1;
  --bg-overlay: #e8ede9;
  --bg-hover: #dfe6e1;

  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-default: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.2);

  --text-primary: #1a2e22;
  --text-secondary: #4a5e52;
  --text-muted: #7a8e82;
  --text-inverse: #f0f0f5;

  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-muted: rgba(22, 163, 74, 0.1);
  --accent-glow: rgba(22, 163, 74, 0.15);

  --success: #16a34a;
  --success-muted: rgba(22, 163, 74, 0.1);
  --warning: #d97706;
  --warning-muted: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-muted: rgba(220, 38, 38, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-accent: 0 0 20px var(--accent-glow);
  --shadow-glow: 0 0 30px rgba(22, 163, 74, 0.08);
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.5em 0; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  outline: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-accent);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #ef4444;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.3);
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--border-subtle);
}

/* ─── Form Inputs ────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239d9db5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.aggregation-group {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

.template-help {
  margin-top: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
}
.template-help summary {
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  background: rgba(255,255,255,0.02);
  user-select: none;
}
.template-help summary:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.04);
}
.template-help-body {
  padding: 12px 14px;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-secondary);
  max-height: 260px;
  overflow-y: auto;
}
.template-help-body h4 {
  margin: 10px 0 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}
.template-help-body h4:first-child { margin-top: 0; }
.template-help-body p {
  margin: 4px 0;
}
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 8px;
}
.help-table td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
.help-table td:first-child {
  white-space: nowrap;
  width: 1%;
}
.help-table code {
  background: rgba(255,255,255,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.7rem;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.form-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ─── Header ─────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand svg {
  color: var(--accent);
}

.header-brand h1 {
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-base);
}

.status-indicator.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-indicator.connected {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.2);
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px rgba(52, 211, 153, 0.4); }
  50% { box-shadow: 0 0 12px rgba(52, 211, 153, 0.8); }
}

/* ─── Main Layout ────────────────────────────────────────── */
.app-main {
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn var(--transition-base); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Toolbar ────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

.toolbar-spacer { flex: 1; }

/* ─── Dashboard List ─────────────────────────────────────── */
.dashboard-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.dashboard-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-base);
  cursor: default;
  position: relative;
  overflow: hidden;
}
.dashboard-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.1), transparent 50%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-base);
}
.dashboard-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.dashboard-card:hover::before {
  opacity: 1;
}

.dashboard-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dashboard-card .meta {
  color: var(--text-muted);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.widget-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-muted);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
}

.dashboard-card .actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

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

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 20px;
  color: var(--text-muted);
  opacity: 0.5;
}

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

.empty-state p {
  color: var(--text-muted);
  font-size: 0.875rem;
  max-width: 360px;
  margin-bottom: 24px;
}

/* ─── Editor Layout ──────────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  min-height: calc(100vh - 160px);
  position: relative;
}

/* Collapsed: hide the sidebar and give the canvas full width. */
.editor-layout.sidebar-collapsed {
  grid-template-columns: 1fr;
}

.editor-layout.sidebar-collapsed .editor-sidebar {
  display: none;
}

.editor-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header .dashboard-name-editable {
  flex: 1;
  min-width: 0;
}

.sidebar-toggle-btn,
.sidebar-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover,
.sidebar-expand-btn:hover {
  background: var(--accent-muted);
  color: var(--accent);
}

/* Floating "show panel" button, only visible when collapsed. */
.sidebar-expand-btn {
  display: none;
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
}

.editor-layout.sidebar-collapsed .sidebar-expand-btn {
  display: inline-flex;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.editor-sidebar .hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.query-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-muted);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  margin: 2px;
}

.editor-canvas {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-height: 650px;
}

/* ─── Dashboard Name (inline edit) ───────────────────────── */
.dashboard-name-editable {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  outline: none;
  transition: all var(--transition-fast);
  width: 100%;
  font-family: var(--font-sans);
}
.dashboard-name-editable:hover {
  border-color: var(--border-default);
  background: var(--bg-base);
}
.dashboard-name-editable:focus {
  border-color: var(--accent);
  background: var(--bg-base);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* ─── Gridstack Overrides ────────────────────────────────── */
.grid-stack {
  min-height: 600px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
}

.grid-stack-item-content {
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.grid-stack-item-content:hover {
  border-color: var(--border-default);
}

.grid-stack-placeholder > .placeholder-content {
  background: var(--accent-muted) !important;
  border: 2px dashed var(--accent) !important;
  border-radius: var(--radius-md) !important;
}

/* ─── Widget Chrome ──────────────────────────────────────── */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 0.8rem;
  min-height: 36px;
}

.widget-header [data-role="title"] {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-type-indicator {
  width: 3px;
  height: 16px;
  border-radius: 2px;
  margin-right: 8px;
  flex-shrink: 0;
}
.widget-type-indicator.type-line_chart { background: #4ade80; }
.widget-type-indicator.type-bar_chart { background: #34d399; }
.widget-type-indicator.type-pie_chart { background: #fbbf24; }
.widget-type-indicator.type-table { background: #60a5fa; }
.widget-type-indicator.type-gauge { background: #f87171; }
.widget-type-indicator.type-kpi { background: #c084fc; }
.widget-type-indicator.type-text { background: var(--text-muted); }
.widget-type-indicator.type-map { background: #2dd4bf; }

.widget-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.grid-stack-item-content:hover .widget-actions { opacity: 1; }

.widget-body {
  flex: 1;
  min-height: 120px;
  padding: 8px;
  overflow: auto;
}

/* ─── Widget: Charts ─────────────────────────────────────── */
.widget-chart,
.widget-map {
  width: 100%;
  height: 100%;
  min-height: 140px;
}

/* ─── Widget: Table ──────────────────────────────────────── */
.widget-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}

.widget-table thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  z-index: 1;
}

.widget-table tbody td {
  padding: 7px 12px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}

.widget-table tbody tr {
  transition: background var(--transition-fast);
}
.widget-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
.widget-table tbody tr:hover {
  background: var(--bg-hover);
}
.widget-table a {
  color: var(--accent);
  text-decoration: none;
}
.widget-table a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ─── Widget: KPI ────────────────────────────────────────── */
.widget-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 16px;
  text-align: center;
}

.widget-kpi .kpi-value {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.widget-kpi .kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
}

/* ─── Widget: Text ───────────────────────────────────────── */
.widget-text {
  padding: 12px 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.widget-markdown {
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-y: auto;
  height: 100%;
}
.widget-markdown h1, .widget-markdown h2, .widget-markdown h3 {
  color: var(--text-primary);
  margin: 0 0 8px;
  font-weight: 600;
}
.widget-markdown h1 { font-size: 1.25rem; }
.widget-markdown h2 { font-size: 1.1rem; }
.widget-markdown h3 { font-size: 0.95rem; }
.widget-markdown p { margin: 0 0 8px; }
.widget-markdown ul, .widget-markdown ol { margin: 0 0 8px; padding-left: 20px; }
.widget-markdown li { margin-bottom: 4px; }
.widget-markdown code {
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.8rem;
}
.widget-markdown pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
}
.widget-markdown strong { color: var(--text-primary); font-weight: 600; }
.widget-markdown em { color: var(--text-secondary); }
.widget-markdown table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.widget-markdown th, .widget-markdown td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  font-size: 0.8rem;
}
.widget-markdown th { color: var(--text-muted); font-weight: 500; }
.widget-markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(74, 222, 128, 0.4);
  text-underline-offset: 2px;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}
.widget-markdown a:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}
.widget-error { color: var(--accent-error, #f87171); }
.widget-error pre { white-space: pre-wrap; word-break: break-word; }

/* ─── Widget Picker ──────────────────────────────────────── */
.widget-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 4px;
}

.widget-picker-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
}
.widget-picker-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: var(--shadow-accent);
  transform: translateY(-2px);
}
.widget-picker-card:hover .widget-picker-icon {
  color: var(--accent);
}

.widget-picker-icon {
  width: 36px;
  height: 36px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.widget-picker-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.widget-picker-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity var(--transition-base);
}
.modal-backdrop.modal-visible { opacity: 1; }
.modal-backdrop.modal-hiding { opacity: 0; }

.modal-dialog {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-base);
}
.modal-visible .modal-dialog {
  transform: scale(1) translateY(0);
}
.modal-hiding .modal-dialog {
  transform: scale(0.95) translateY(10px);
}

.modal-sm { width: 400px; }
.modal-md { width: 560px; }
.modal-lg { width: 720px; }
.modal-xl { width: 900px; }

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

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: all var(--transition-fast);
}
.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-message {
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
}

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

/* ─── Toast Notifications ────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
  font-size: 0.8125rem;
  color: var(--text-primary);
  pointer-events: auto;
  transform: translateX(120%);
  transition: transform var(--transition-base), opacity var(--transition-base);
  max-width: 380px;
}
.toast.toast-visible { transform: translateX(0); }
.toast.toast-hiding { transform: translateX(120%); opacity: 0; }

.toast-icon { display: flex; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--accent); }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1100px) {
  .editor-layout { grid-template-columns: 1fr; }
  .editor-sidebar { order: 2; }
}

@media (max-width: 600px) {
  .app-main { padding: 12px; }
  .dashboard-list { grid-template-columns: 1fr; }
  .modal-sm, .modal-md, .modal-lg, .modal-xl { width: calc(100vw - 24px); }
  .widget-picker-grid { grid-template-columns: repeat(2, 1fr); }
}
