:root {
  --bg: #000000;

  --surface: #050505;
  --surface-2: #0b0b0b;

  --border: #1a1a1a;
  --border-hover: #2a2a2a;

  --text: #ffffff;
  --muted: #8a8a8a;

  --radius: 20px;
}

/* RESET */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden; /* Importante para canvas livre */
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
}

/* HEADER */
.header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 18px;
}

.logo {
  width: 68px;
  user-select: none;
  -webkit-user-drag: none;
  transition: 0.2s ease;
}

.logo:hover {
  transform: scale(1.05);
}

.header-text {
  font-size: 40px;
  letter-spacing: 6px;
}

.header-subtext {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* TOOLBAR */
.toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 20px;
}

.toolbar button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 14px;
  transition: 0.2s ease;
}

.toolbar button:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.toolbar button.btn-danger:hover {
  border-color: #ff4444;
  color: #ff4444;
}

/* WORKSPACE (CANVAS) */
#workspace {
  position: relative;
  width: 100%;
  height: calc(100vh - 140px);
  padding: 20px;
  overflow: hidden;
}

/* EMPTY STATE */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

/* WIDGET ARCHITECTURE (O CONTÊINER) */
.widget {
  position: absolute;
  min-width: 220px;
  min-height: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Evita vazamento de conteúdo dos widgets */
  user-select: none;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.widget:hover {
  border-color: var(--border-hover);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* WIDGET INTERNAL STRUCTURE */
.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 6px;
  background: transparent;
}

.widget-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  font-weight: 700;
}

.widget-content {
  flex: 1;
  padding: 6px 14px 14px;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* Permite scroll se o conteúdo passar do tamanho */
}

/* REMOVE BUTTON */
.remove-widget {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  transition: color 0.2s;
}

.remove-widget:hover {
  color: #ff4444;
}

/* RESIZE HANDLE */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  right: 4px;
  bottom: 4px;
  background: transparent;
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  border-bottom-right-radius: 4px;
  z-index: 10;
}

.widget:hover .resize-handle {
  border-color: var(--muted);
}

/* ==========================================================================
   INTERFACES DOS COMPONENTES (WIDGET FACTORY)
   ========================================================================== */

/* 1. NOTA */
.widget-textarea {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
}

/* 2. RELÓGIO */
.widget-clock {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-family: monospace;
  font-size: 2rem;
  letter-spacing: 1px;
}

/* 3. CONTADOR */
.widget-counter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: auto 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}

.widget-counter button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  transition: 0.2s;
}

.widget-counter button:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

.count-value {
  font-size: 1.5rem;
  font-family: monospace;
}

/* WIDGET PLACEHOLDER (FALLBACK) */
.widget-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ==========================================================================
   MODAL DE SELEÇÃO DE WIDGETS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  width: 90%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  transition: color 0.2s;
}

.btn-close:hover {
  color: var(--text);
}

.modal-grid {
  --grid-content: attr(data-type);
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  overflow-y: auto;
}

.widget-option {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 16px 12px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  transition: all 0.2s ease;
}

.widget-option:hover {
  border-color: var(--border-hover);
  background: #0f0f0f;
  transform: translateY(-2px);
}

.widget-option .icon {
  font-size: 22px;
}

/* ==========================================================================
   CSS IDE PANEL & GERENCIADOR DE ARQUIVOS
   ========================================================================== */
#cssPanel {
  position: fixed;
  top: 0;
  right: -560px; /* Expandido para acomodar a UI da IDE confortavelmente */
  width: 560px;
  height: 100vh;
  background: rgba(5, 5, 5, 0.98);
  backdrop-filter: blur(25px);
  border-left: 1px solid var(--border);
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

#cssPanel.open {
  right: 0;
}

.css-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.css-title-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.css-title-area h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* INPUT DO NOME DO ARQUIVO .CSS */
#cssFileName {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: monospace;
  font-size: 12px;
  outline: none;
  width: 80%;
  transition: color 0.2s ease;
}

#cssFileName:focus {
  color: var(--text);
}

.css-header button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  transition: color 0.2s ease;
}

.css-header button:hover {
  color: var(--text);
}

/* BARRA DE AÇÕES DA IDE (SALVAR / CARREGAR / DROP-DOWN) */
.css-actions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.btn-ide {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-ide:hover {
  border-color: var(--border-hover);
  background: #111;
  transform: translateY(-1px);
}

/* SELETOR DROP-DOWN DE ESTILOS SALVOS */
#cssFileSelector {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
  outline: none;
  font-family: inherit;
  transition: all 0.2s ease;
}

#cssFileSelector:focus {
  border-color: var(--border-hover);
  color: var(--text);
}

#cssFileSelector option {
  background: var(--surface);
  color: var(--text);
}

/* TEXTAREA DA IDE DE CODIFICAÇÃO */
#cssInput {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  color: #a7b7c5; /* Cor cinza-azulada limpa (estilo VS Code / JetBrains) */
  padding: 20px;
  font-family: "Fira Code", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  resize: none;
  tab-size: 2;
}

/*====CURSOR & RESPONSIVE====*/
.cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 10px;
  height: 10px;
  margin-left: -5px; 
  margin-top: -5px; 
  pointer-events: none;
  z-index: 9999;
  will-change: transform;
}

.cursor-dot {
  width: 100%;
  height: 100%;
  background-color: #fff;
  box-shadow: 0 0 15px 5px #a7b7c5;
  border-radius: 50%;
  opacity: 0.5;
  transform-origin: center center;
  transition:
    transform 0.15s ease-out,
    opacity 0.15s ease-out;
  will-change: transform;
}

.cursor.clicking .cursor-dot {
  transform: scale(0.6);
  opacity: 0.8;
}

/* RESPONSIVE */
@media (max-width: 700px) {
  .header-text {
    font-size: 26px;
  }

  #cssPanel {
    width: 100%;
  }

  .widget {
    min-width: 180px;
  }

  .modal-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

/* ==========================================================================
   SETTINGS MODAL STYLES (CORRIGIDO)
   ========================================================================== */
.modal-settings {
  max-width: 500px;
}

.settings-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

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

.setting-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-info label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.setting-info p {
  font-size: 12px;
  color: var(--muted);
}

/* Inputs dentro de configurações */
.settings-body select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  outline: none;
}

.settings-body select:focus {
  border-color: var(--border-hover);
}

/* CONTAINER DO RODAPÉ DO MODAL */
.settings-footer {
  margin-top: 25px;
  padding: 20px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between; /* Um botão em cada ponta */
  gap: 15px;
}

/* BASE DOS BOTÕES DO RODAPÉ */
.settings-footer button {
  padding: 12px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

/* BOTÃO APLICAR (FUTURISTA / GLASS) */
.settings-footer .btn-primary {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
  flex: 1; /* Faz o botão de aplicar ocupar o espaço restante */
}

.settings-footer .btn-primary:hover {
  background: #fff;
  color: #000;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

/* BOTÃO RESETAR (PERIGOSO) */
.settings-footer .btn-danger {
  background: transparent;
  color: #ff5555;
  border-color: rgba(255, 85, 85, 0.2);
}

.settings-footer .btn-danger:hover {
  background: rgba(255, 85, 85, 0.1);
  border-color: #ff5555;
  box-shadow: 0 0 15px rgba(255, 85, 85, 0.1);
}

.settings-footer button:active {
  scale: 0.95;
}

/* CONTROLE SWITCH (LIGA/DESLIGA CHIQUE) */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 34px;
  transition: 0.3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--muted);
  border-radius: 50%;
  transition: 0.3s;
}

input:checked + .slider {
  background-color: #ffffff;
  border-color: #ffffff;
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #000000;
}

/* ==========================================================================
   VISUAL GRID SYSTEM
   ========================================================================== */
#workspace::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(26, 26, 26, 0.712) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(26, 26, 26, 0.734) 1px, transparent 1px);
  background-size: 10px 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  z-index: 0;
}

#workspace.grid-enabled.dragging::before {
  opacity: 1;
}

.widget {
  z-index: 10;
}