:root {
  --background: 222 47% 6%;
  --foreground: 213 31% 91%;
  --card: 215 28% 11%;
  --primary: 32 95% 55%;
  --primary-foreground: 222 47% 6%;
  --secondary: 215 20% 18%;
  --secondary-foreground: 213 27% 84%;
  --muted-foreground: 215 14% 59%;
  --accent: 212 92% 50%;
  --destructive: 0 72% 51%;
  --success: 142 76% 45%;
  --border: 215 14% 22%;
  --border-hover: 215 14% 32%;
  --input: 215 20% 18%;
  --editor-panel: 215 28% 11%;
  --editor-panel-hover: 215 25% 14%;
  --editor-border: 215 14% 22%;
  --preview-bg: 0 0% 100%;
  --preview-border: 215 14% 30%;
  --shadow-lg: 0 10px 15px -3px hsl(0 0% 0% / 0.5), 0 4px 6px -4px hsl(0 0% 0% / 0.5);
  --shadow-glow: 0 0 20px hsl(var(--primary) / 0.3);
}

* {
  box-sizing: border-box;
  border-color: hsl(var(--border));
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code,
.editor-textarea,
.font-mono {
  font-family: "JetBrains Mono", "Fira Code", monospace;
}

.editor-sidebar {
  display: flex;
  flex-direction: column;
  width: 380px;
  min-width: 380px;
  height: 100%;
  background: hsl(var(--editor-panel));
  border-right: 1px solid hsl(var(--editor-border));
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid hsl(var(--editor-border));
  background: hsl(var(--secondary));
}

.sidebar-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.125rem;
  font-weight: 700;
  color: hsl(var(--primary));
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground));
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid hsl(var(--editor-border));
}

.sidebar-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}

.sidebar-footer {
  text-align: center;
  padding: 12px 16px;
  border-top: 1px solid hsl(var(--editor-border));
}

.editor-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 8px 16px;
  background: hsl(var(--editor-panel));
  border-bottom: 1px solid hsl(var(--editor-border));
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-center {
  flex: 1;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.preview-canvas {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  overflow: auto;
  background: hsl(222 47% 4%);
  background-image: radial-gradient(circle at 1px 1px, hsl(var(--border) / 0.3) 1px, transparent 0);
  background-size: 20px 20px;
}

.preview-frame {
  background: hsl(var(--preview-bg));
  border: 1px solid hsl(var(--preview-border));
  border-radius: 0.6rem;
  overflow: hidden;
  min-height: 600px;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
}

.preview-iframe {
  width: 100%;
  min-height: 600px;
  height: 100%;
  border: 0;
}

.editor-tabs {
  display: flex;
  border-bottom: 1px solid hsl(var(--editor-border));
}

.editor-tab {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: hsl(var(--muted-foreground));
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 12px;
  cursor: pointer;
  transition: 150ms ease;
}

.editor-tab:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--editor-panel-hover));
}

.editor-tab.active {
  color: hsl(var(--primary));
  border-bottom-color: hsl(var(--primary));
  background: hsl(var(--editor-panel-hover));
}

.editor-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
}

.editor-input,
.editor-textarea {
  width: 100%;
  font-size: 0.86rem;
  color: hsl(var(--foreground));
  background: hsl(var(--input));
  border: 1px solid hsl(var(--border));
  border-radius: 0.45rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.editor-input:hover,
.editor-textarea:hover {
  border-color: hsl(var(--border-hover));
}

.editor-input:focus,
.editor-textarea:focus {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.2);
}

.editor-textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

input[type="file"] {
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  padding: 8px 12px;
  border-radius: 6px;
  margin-right: 10px;
  cursor: pointer;
}

.editor-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 0.45rem;
  padding: 8px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: 150ms ease;
}

.editor-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.editor-btn-primary {
  color: hsl(var(--primary-foreground));
  background: hsl(var(--primary));
}

.editor-btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: var(--shadow-glow);
}

.editor-btn-secondary {
  color: hsl(var(--secondary-foreground));
  background: hsl(var(--secondary));
  border-color: hsl(var(--border));
}

.editor-btn-secondary:hover:not(:disabled) {
  border-color: hsl(var(--border-hover));
  background: hsl(var(--editor-panel-hover));
}

.editor-btn-ghost {
  background: transparent;
  color: hsl(var(--muted-foreground));
}

.editor-btn-ghost:hover:not(:disabled) {
  color: hsl(var(--foreground));
  background: hsl(var(--secondary));
}

.editor-btn-danger {
  color: #fff;
  background: hsl(var(--destructive));
}

.editor-btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

.device-btn {
  border: 1px solid transparent;
  border-radius: 0.45rem;
  color: hsl(var(--muted-foreground));
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  transition: 150ms ease;
}

.device-btn:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--secondary));
}

.device-btn.active {
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.14);
}

.widget-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 8px 8px;
}

.widget-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-size: 0.68rem;
  font-weight: 600;
  text-align: center;
  cursor: grab;
  user-select: none;
  transition: 150ms ease;
}

.widget-btn:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
  background: hsl(var(--editor-panel-hover));
  box-shadow: 0 4px 12px hsl(var(--primary) / 0.15);
}

.widget-btn.dragging,
.widget-btn:active {
  cursor: grabbing;
  transform: scale(0.95);
  opacity: 0.72;
}

.widget-category-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  padding: 8px;
  border-radius: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.widget-category-btn:hover {
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
}

.empty-state {
  padding: 16px;
  text-align: center;
  border: 1px dashed hsl(var(--border));
  border-radius: 0.5rem;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--secondary) / 0.5);
}

.empty-state i {
  display: block;
  margin-bottom: 8px;
  font-size: 1.2rem;
  opacity: 0.65;
}

.tag-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: hsl(var(--primary) / 0.16);
  color: hsl(var(--primary));
  font-size: 0.75rem;
  font-family: "JetBrains Mono", monospace;
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border: 1px solid hsl(var(--border));
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.color-swatch input[type="color"] {
  width: 38px;
  height: 38px;
  margin: -3px;
  border: 0;
  cursor: pointer;
}

.context-menu {
  position: fixed;
  z-index: 80;
  min-width: 160px;
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--editor-border));
  background: hsl(var(--editor-panel));
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  padding: 4px;
  animation: popIn 0.14s ease-out;
}

.context-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: hsl(var(--foreground));
  text-align: left;
  cursor: pointer;
  padding: 8px;
  font-size: 0.82rem;
}

.context-menu-item:hover {
  background: hsl(var(--secondary));
}

.context-menu-item.danger {
  color: hsl(var(--destructive));
}

.context-menu-item.danger:hover {
  background: hsl(var(--destructive) / 0.14);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: hsl(0 0% 0% / 0.7);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-content {
  width: min(600px, 92vw);
  max-height: 90vh;
  border-radius: 0.75rem;
  border: 1px solid hsl(var(--editor-border));
  background: hsl(var(--editor-panel));
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid hsl(var(--editor-border));
  padding: 14px 16px;
}

.modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 1.1rem;
}

.modal-close:hover {
  color: hsl(var(--foreground));
}

.modal-body {
  padding: 16px;
  max-height: calc(90vh - 140px);
  overflow: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid hsl(var(--editor-border));
  padding: 12px 16px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  background: hsl(var(--editor-panel));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-left-width: 3px;
  border-radius: 0.5rem;
  padding: 10px 12px;
  min-width: 180px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease;
}

.toast.success {
  border-left-color: hsl(var(--success));
}

.toast.error {
  border-left-color: hsl(var(--destructive));
}

.toast.info {
  border-left-color: hsl(var(--accent));
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
}

.hidden {
  display: none !important;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 1200px) {
  .editor-sidebar {
    width: 320px;
    min-width: 320px;
  }
}

@media (max-width: 960px) {
  .editor-sidebar {
    width: 280px;
    min-width: 280px;
  }

  .widget-grid {
    grid-template-columns: 1fr;
  }

  .widget-btn {
    flex-direction: row;
    justify-content: flex-start;
    padding: 10px;
    text-align: left;
  }
}