:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --blue: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #d29922;
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

code {
  background: rgba(110, 118, 129, 0.25);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.hint {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  background: rgba(88, 166, 255, 0.12);
  color: var(--blue);
  border: 1px solid rgba(88, 166, 255, 0.35);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.error-banner {
  background: rgba(248, 81, 73, 0.14);
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: #ffa198;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

/* Topbar & Tabs */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--blue);
  font-size: 1.05rem;
}

.site-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.version-pill {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.35);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
}

.tabbar {
  display: flex;
  gap: 6px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--blue);
}

/* Workspace & Cards */
.workspace {
  padding: 20px;
  max-width: 1440px;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.full-span {
  grid-column: 1 / -1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h2 {
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3 {
  font-size: 0.92rem;
  color: var(--muted);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Forms & Buttons */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--muted);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

input[type="text"],
input[type="url"],
input[type="email"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
}

input[type="color"] {
  width: 100%;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
  font-size: 0.84rem !important;
}

.inline-input {
  display: flex;
  gap: 8px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 11px 16px;
  font-size: 0.96rem;
}

.btn-primary {
  background: #1f6feb;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #388bfd;
}

.btn-success {
  background: #238636;
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #2ea043;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #262c36;
}

.btn-danger {
  background: rgba(248, 81, 73, 0.16);
  border-color: rgba(248, 81, 73, 0.45);
  color: #ffa198;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.upload-label {
  cursor: pointer;
}

/* Repeatable Items */
.repeat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.repeat-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.repeat-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Code IDE Layout */
.ide-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  min-height: 70vh;
}

.file-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-tree {
  max-height: 58vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 0.84rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.file-item:hover {
  background: var(--surface-2);
}

.file-item.active {
  background: rgba(88, 166, 255, 0.15);
  color: var(--blue);
}

.file-size {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.editor-toolbar-actions {
  display: flex;
  gap: 8px;
}

.code-editor {
  min-height: 56vh;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
  font-size: 0.86rem !important;
  line-height: 1.55;
  tab-size: 2;
}

.binary-preview {
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
}

/* History & Lists */
.backup-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 58vh;
  overflow-y: auto;
}

.history-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.history-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Modal & Toast */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 200;
  max-width: 380px;
  font-size: 0.9rem;
}

.toast.success {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--red);
}

@media (max-width: 960px) {
  .panel-grid,
  .ide-layout,
  .form-grid-2,
  .form-grid-3,
  .color-grid {
    grid-template-columns: 1fr;
  }
}


/* ============================================
   CODE EDITOR TAB STYLES
   ============================================ */

.code-editor-layout {
  display: grid;
  grid-template-columns: 260px 1fr 400px;
  gap: 0;
  height: calc(100vh - 120px);
  background: var(--bg);
}

/* File Explorer Sidebar */
.code-file-explorer {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.explorer-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.explorer-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--surface-2);
  border-color: var(--blue);
  color: var(--blue);
}

.file-search {
  margin: 12px 16px;
  width: calc(100% - 32px);
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.file-search:focus {
  outline: none;
  border-color: var(--blue);
}

.file-tree-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.file-tree-item {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.85rem;
  user-select: none;
}

.file-tree-item:hover {
  background: var(--surface-2);
}

.file-tree-item.active {
  background: rgba(88, 166, 255, 0.15);
  color: var(--blue);
  font-weight: 500;
}

.file-tree-item i {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.file-tree-item .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tree-folder {
  font-weight: 600;
  color: var(--blue);
}

.file-tree-folder .folder-toggle {
  margin-right: 4px;
  transition: transform 0.2s;
}

.file-tree-folder.expanded .folder-toggle {
  transform: rotate(90deg);
}

.file-tree-children {
  padding-left: 20px;
}

/* Main Editor Area */
.code-editor-main {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.editor-tabs {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.tabs-container {
  display: flex;
  align-items: center;
  overflow-x: auto;
  min-height: 42px;
  padding: 0 8px;
}

.editor-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: all 0.2s;
}

.editor-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.editor-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.editor-tab .tab-close {
  opacity: 0;
  margin-left: 4px;
  padding: 0 4px;
  transition: opacity 0.2s;
}

.editor-tab:hover .tab-close,
.editor-tab.active .tab-close {
  opacity: 1;
}

.editor-tab .tab-close:hover {
  color: var(--red);
}

.tab-placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Monaco Editor Container */
.editor-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.monaco-editor-wrapper {
  width: 100%;
  height: 100%;
}

.editor-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.editor-placeholder i {
  font-size: 48px;
  opacity: 0.3;
}

.editor-placeholder h3 {
  font-size: 1.1rem;
  color: var(--text);
}

.editor-placeholder p {
  font-size: 0.9rem;
}

/* Editor Footer */
.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.footer-left,
.footer-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-item i {
  font-size: 0.75rem;
}

/* Preview Panel */
.code-preview-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.preview-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-actions {
  display: flex;
  gap: 4px;
}

.preview-iframe {
  flex: 1;
  border: none;
  background: white;
  width: 100%;
}

.preview-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.preview-placeholder i {
  font-size: 48px;
  opacity: 0.3;
}

/* Responsive */
@media (max-width: 1400px) {
  .code-editor-layout {
    grid-template-columns: 240px 1fr;
  }
  
  .code-preview-panel {
    display: none;
  }
}

@media (max-width: 768px) {
  .code-editor-layout {
    grid-template-columns: 1fr;
  }
  
  .code-file-explorer {
    display: none;
  }
}

/* File Icons */
.file-icon-html { color: #e34c26; }
.file-icon-css { color: #264de4; }
.file-icon-js { color: #f7df1e; }
.file-icon-json { color: #5fb3b3; }
.file-icon-md { color: #519aba; }
.file-icon-image { color: #c678dd; }
.file-icon-svg { color: #ff9800; }
.file-icon-folder { color: var(--blue); }
