:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --danger: #dc2626;
  --success: #059669;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* Boot screen */
.boot-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  color: var(--text-muted);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.main { padding: 24px; max-width: 1200px; margin: 0 auto; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}
.brand i { color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.tab {
  background: transparent;
  border: 0;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 7px;
  font: inherit;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* Views */
.view { display: none; }
.view.active { display: block; }
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.view h1 { font-size: 22px; margin: 0; }

/* Buttons */
.btn-primary, .btn-secondary {
  border: 0;
  padding: 10px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, transform 0.05s;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }

/* Widgets list */
.widgets-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.widget-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}
.widget-card:hover { box-shadow: var(--shadow-md); }

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-icon {
  font-size: 48px;
  color: var(--text-muted);
  opacity: 0.4;
  margin-bottom: 16px;
}
.empty h2 { font-size: 18px; margin: 0 0 8px; }
.empty p { color: var(--text-muted); margin: 0 0 20px; }

/* Error banner */
.error-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--danger);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-width: 360px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}
.modal-panel-sm { max-width: 440px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.modal-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  padding: 6px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.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);
  background: var(--bg);
  flex-shrink: 0;
}

/* Modal tabs */
.modal-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.modal-tab {
  background: transparent;
  border: 0;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-view { display: none; }
.modal-view.active { display: block; }

/* Form fields */
.field {
  display: block;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
}
.field-help {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="color"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input[type="color"] {
  padding: 4px;
  height: 38px;
  cursor: pointer;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  cursor: pointer;
  user-select: none;
}

/* Product picker */
.product-picker { position: relative; }
.product-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 10;
}
.product-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.product-result:hover { background: var(--bg); }
.product-result img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
  flex-shrink: 0;
}
.product-result-info {
  flex: 1;
  min-width: 0;
}
.product-result-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-result-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.product-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 8px;
}
.product-selected-info { flex: 1; min-width: 0; }
.product-selected button {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--accent);
  padding: 4px;
  border-radius: 4px;
}
.product-selected button:hover { background: var(--surface); }

/* Bundles presets */
.bundles-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.bundle-preset {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  background: var(--surface);
}
.bundle-preset:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.bundle-preset.active {
  border-color: var(--accent);
  background: var(--accent-light);
}
.bundle-preset input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}
.bundle-preset-info { flex: 1; min-width: 0; }
.bundle-preset-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.bundle-preset-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Info callout */
.info-callout {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: #fef9e7;
  border: 1px solid #f9e07f;
  border-radius: 8px;
  font-size: 13px;
  color: #78350f;
}
.info-callout > i {
  font-size: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}
.info-callout strong { display: block; margin-bottom: 4px; }
.info-callout p { margin: 0 0 8px; line-height: 1.45; }
.info-callout a {
  color: #92400e;
  font-weight: 600;
  text-decoration: none;
}
.info-callout a:hover { text-decoration: underline; }

/* Danger button */
.btn-danger {
  background: var(--danger);
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: #b91c1c; }

/* Widget card actions */
.widget-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.widget-card-actions button {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}
