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

:root {
  --bg: #020617;
  --surface: #0F172A;
  --surface-hover: #1E293B;
  --border: #1E293B;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --text-dark: #cbd5e1;
  --blue: #3B82F6;
  --green: #22C55E;
  --green-hover: #16a34a;
  --red: #EF4444;
  --btn-bg: #1E293B;
  --btn-hover: #334155;
  --glass: rgba(15, 23, 42, 0.85);
  --glass-border: rgba(255, 255, 255, 0.05);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Fira Sans', -apple-system, sans-serif;
  font-size: 16px; /* Aumentado para mobile */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Topbar ──────────────────────────────────── */
#topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
  z-index: 50;
}

#topbar .brand {
  color: var(--text);
  font-weight: 700;
  font-family: 'Fira Code', monospace;
  font-size: 16px;
  letter-spacing: -0.05em;
}

/* Dropdown & Services Menu */
.dropdown-container {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  padding: 16px;
  width: 320px;
  max-width: calc(100vw - 32px);
  z-index: 200;
  display: none;
  flex-direction: column;
}
.dropdown-menu.show {
  display: flex;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-header {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

#services-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.badge {
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}

.service-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.service-chip:hover { 
  border-color: var(--blue); 
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.service-chip.readonly { cursor: default; }
.service-chip.readonly:hover { border-color: var(--border); transform: none; box-shadow: none; }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
  box-shadow: 0 0 8px currentColor;
  opacity: 0.8;
}
.dot.active { background: var(--green); color: var(--green); }
.dot.inactive { background: var(--red); color: var(--red); }

.chip-name { font-size: 14px; font-weight: 500; color: var(--text); flex: 1; }

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; margin-left: auto; }
.toggle {
  position: relative; width: 40px; height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: background 0.3s;
  cursor: pointer;
}
.toggle .slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
}
.toggle input:checked + .slider { background: var(--blue); border-color: var(--blue); }
.toggle input:checked + .slider::before {
  transform: translateX(16px);
  background: #fff;
}

/* ── Main layout ─────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Explorer ────────────────────────────────── */
#explorer {
  width: 300px; min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 40;
}

#explorer.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

#sort-bar {
  display: flex; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sort-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  transition: all 0.2s;
}
.sort-btn:hover { color: var(--text); border-color: var(--text-muted); }
.sort-btn.active {
  background: var(--btn-bg);
  border-color: var(--blue);
  color: var(--blue);
}

#file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.tree-dir { cursor: pointer; }
.tree-dir-name {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  color: var(--text-dark);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}
.tree-dir-name:hover { color: var(--text); background: var(--surface-hover); }
.tree-dir-name .arrow { font-size: 10px; transition: transform 0.2s; }
.tree-dir.open > .tree-dir-name .arrow { transform: rotate(90deg); }
.tree-children { display: none; padding-left: 12px; }
.tree-dir.open > .tree-children { display: block; }

.tree-file {
  padding: 8px 16px 8px 32px;
  color: var(--text-muted);
  font-size: 14px;
  font-family: 'Fira Code', monospace;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: all 0.2s;
  border-left: 2px solid transparent;
}
.tree-file:hover { color: var(--text); background: var(--surface-hover); }
.tree-file.active {
  color: var(--text);
  background: var(--surface-hover);
  border-left: 2px solid var(--blue);
  font-weight: 500;
}

/* ── Editor panel ────────────────────────────── */
#editor-panel {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}

#editor-toolbar {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  flex-shrink: 0;
}

#file-path-label {
  color: var(--text-dark); 
  font-size: 14px; 
  font-family: 'Fira Code', monospace;
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-btn {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.tb-btn:hover { background: var(--btn-hover); border-color: var(--text-muted); }
.tb-btn.active {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--blue);
  color: var(--blue);
}
.icon-btn { padding: 8px; }

.tools-group, .mode-group {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.tools-group .tb-btn, .mode-group .tb-btn {
  border: none; background: transparent; padding: 6px 12px; border-radius: 6px;
}
.tools-group .tb-btn:hover, .mode-group .tb-btn:hover { background: var(--btn-hover); }
.mode-group .active { background: var(--btn-bg); color: var(--text); }

#save-btn {
  background: var(--green); border: none;
  color: #fff; border-radius: 8px;
  padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
}
#save-btn:hover:not(:disabled) { 
  background: var(--green-hover); 
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.3);
}
#save-btn:disabled {
  background: var(--btn-bg);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

#editor-area {
  flex: 1; position: relative; overflow: hidden;
}

#editor-textarea {
  position: absolute; inset: 0;
  background: var(--bg); color: var(--text);
  border: none; outline: none; resize: none;
  padding: 32px 32px 100px 32px; font-family: 'Fira Code', monospace;
  font-size: 15px; line-height: 1.8;
  tab-size: 2;
  overflow-y: auto;
  min-height: 100%;
}

#editor-preview {
  position: absolute; inset: 0;
  background: var(--bg);
  padding: 32px 32px 100px 32px;
  overflow-y: auto;
  display: none;
  line-height: 1.8;
  font-size: 16px;
}

/* Markdown preview styles */
#editor-preview h1 { font-size: 2.2em; font-weight: 700; margin-bottom: 24px; color: #fff; }
#editor-preview h2 { font-size: 1.6em; margin-top: 32px; margin-bottom: 16px; color: #fff; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
#editor-preview p { color: var(--text-dark); margin: 16px 0; }
#editor-preview code {
  background: var(--surface); padding: 4px 6px;
  border-radius: 6px; font-family: 'Fira Code', monospace; font-size: 0.9em;
  color: var(--blue);
}
#editor-preview pre {
  background: var(--surface); padding: 20px;
  border-radius: 12px; overflow-x: auto; margin: 24px 0;
  border: 1px solid var(--border);
}
#editor-preview pre code { background: none; color: inherit; padding: 0; }
#editor-preview a { color: var(--blue); text-decoration: none; }
#editor-preview a:hover { text-decoration: underline; }
#editor-preview ul, #editor-preview ol { padding-left: 24px; color: var(--text-dark); margin: 16px 0; }
#editor-preview li { margin-bottom: 8px; }
#editor-preview blockquote {
  border-left: 4px solid var(--blue);
  padding-left: 16px; color: var(--text-muted); margin: 24px 0;
  font-style: italic; background: rgba(59,130,246,0.05); padding: 12px 16px; border-radius: 0 8px 8px 0;
}

/* ── Floating Toolbar ────────────────────────── */
#floating-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  display: flex !important;
  gap: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,255,255,0.1);
  max-width: 95vw;
  width: max-content;
  overflow-x: auto;
  z-index: 100;
  scroll-behavior: smooth;
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s;
}
#floating-toolbar.hidden-bar {
  opacity: 0; pointer-events: none; transform: translate(-50%, 10px); display: flex !important;
}
#floating-toolbar::-webkit-scrollbar { display: none; }
#floating-toolbar .tb-btn { border-radius: 999px; padding: 10px 16px; flex-shrink: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); font-size: 13px; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
#floating-toolbar .tb-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Empty state ─────────────────────────────── */
#empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center; height: 100%;
}
#empty-state p { font-size: 16px; font-weight: 500; }

/* ── Overlay mobile ──────────────────────────── */
#mobile-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
#mobile-overlay.show { opacity: 1; visibility: visible; }

/* ── Login page ──────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}
.login-page::before {
  content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.05), transparent 60%);
  z-index: -1;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}
.login-logo { margin-bottom: 24px; color: var(--blue); }
.login-box h1 { color: var(--text); font-size: 24px; font-weight: 700; letter-spacing: -0.05em; font-family: 'Fira Code', monospace; margin-bottom: 8px; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }
.login-box label { display: block; text-align: left; color: var(--text-dark); font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.login-box input {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 12px 16px; font-size: 15px;
  margin-bottom: 20px; outline: none; transition: all 0.2s;
}
.login-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
.login-box button {
  width: 100%; background: var(--blue); border: none;
  color: #fff; border-radius: 8px; padding: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; display: flex; justify-content: center; align-items: center;
}
.login-box button:hover { background: #2563eb; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.login-error { color: var(--red); background: rgba(239, 68, 68, 0.1); padding: 10px; border-radius: 6px; font-size: 13px; margin-top: 16px; display: none; font-weight: 500; }

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-hover); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Mobile Responsive ───────────────────────── */
@media (max-width: 900px) {
  #topbar { padding: 12px; }
  
  #explorer {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 320px;
    max-width: 85vw;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  }
  
  #explorer.open { transform: translateX(0); }
  
  .tools-group { display: none; } /* Hide formatting tools on small screens for cleaner UI */
  
  #editor-textarea, #editor-preview { padding: 20px; }
  
  /* Make save and specific tools sticky or rearranged if needed, but for now flex will wrap them cleanly */
}
