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

body, html {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #ffffff;
  color: #333333;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100%;
}

/* Sidebar */
#sidebar {
  width: 250px;
  min-width: 180px;
  background: #f3f3f3;
  display: flex;
  flex-direction: column;
  user-select: none;
  border-right: 1px solid #e0e0e0;
}

#sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
  border-bottom: 1px solid #e0e0e0;
}

#sidebar-actions {
  display: flex;
  gap: 2px;
}

#sidebar-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sidebar-actions button:hover { background: #e0e0e0; }

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

/* File tree items */
.tree-item {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.tree-item:hover { background: #e8e8e8; }
.tree-item.active { background: #d6ebff; }
.tree-item.selected { background: #cde4ff; }
.tree-root { font-weight: 500; }
.tree-root-wrapper > .tree-children { padding-left: 20px; }
.tree-children { display: none; padding-left: 20px; }
.tree-children.expanded { display: block; }

.tree-item .icon {
  width: 20px;
  height: 20px;
  margin-right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tree-item .icon svg { width: 100%; height: 100%; }

.tree-item .arrow {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 11px;
  transition: transform 0.1s;
}
.tree-item .arrow.expanded { transform: rotate(90deg); }
.tree-item .arrow.hidden { visibility: hidden; }

/* Divider */
#divider {
  width: 1px;
  cursor: col-resize;
  background: #e0e0e0;
  flex-shrink: 0;
  margin: 0 2px;
}
#divider:hover { background: #007acc; }

/* Main area */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Toolbar */
#toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f3f3f3;
  border-bottom: 1px solid #e0e0e0;
  padding: 2px 8px;
  min-height: 30px;
  gap: 4px;
}
#toolbar-left, #toolbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}
.tb-btn {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1;
}
.tb-btn:hover { background: #e0e0e0; color: #333; }
.tb-btn:disabled { opacity: 0.35; cursor: default; }
.tb-btn:disabled:hover { background: none; }
.tb-btn.active { background: #d0d0d0; color: #007acc; }

.tb-sep {
  width: 1px;
  height: 18px;
  background: #d0d0d0;
  margin: 0 4px;
  flex-shrink: 0;
}

.tb-select {
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 3px;
  color: #333;
  font-size: 12px;
  padding: 1px 4px;
  cursor: pointer;
  outline: none;
}
.tb-select:hover { border-color: #aaa; }

/* Tabs */
#tabs {
  display: flex;
  background: #f3f3f3;
  min-height: 35px;
  overflow-x: auto;
  border-bottom: 1px solid #e0e0e0;
}
#tabs::-webkit-scrollbar { height: 0; }

.tab {
  display: flex;
  align-items: center;
  padding: 5px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  border-right: 1px solid #e0e0e0;
  white-space: nowrap;
  color: #666;
  flex-shrink: 0;
  gap: 4px;
}
.tab .icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tab .icon svg { width: 100%; height: 100%; }
.tab:hover { background: #e8e8e8; }
.tab.active { background: #ffffff; color: #333; border-bottom: 2px solid #007acc; }

.tab .modified {
  width: 8px; height: 8px;
  background: #c4c4c4;
  border-radius: 50%;
  margin-left: 8px;
  display: none;
}
.tab.modified .modified { display: inline-block; }

.tab .close {
  margin-left: 8px;
  width: 18px; height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 14px;
  color: #999;
}
.tab .close:hover { background: #d0d0d0; color: #333; }

/* Editor */
#editor-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #999;
}
#welcome h2 { font-weight: 300; font-size: 24px; margin-bottom: 8px; }
#welcome p { font-size: 14px; }

#monaco-editor {
  width: 100%;
  height: 100%;
  display: none;
}

/* Context menu */
.context-menu {
  position: fixed;
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  padding: 4px 0;
  min-width: 160px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.context-menu .separator {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}
.context-menu div {
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
}
.context-menu div:hover { background: #e8f0fe; }

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#modal {
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 20px;
  min-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
#modal-title { font-size: 14px; margin-bottom: 12px; font-weight: 500; color: #333; }
#modal-input {
  width: 100%;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid #d0d0d0;
  color: #333;
  font-size: 14px;
  border-radius: 3px;
  outline: none;
}
#modal-input:focus { border-color: #007acc; }
#modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
#modal-buttons button {
  padding: 4px 14px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
}
#modal-ok { background: #0e639c; color: #fff; }
#modal-ok:hover { background: #1177bb; }
#modal-cancel { background: #e0e0e0; color: #333; }
#modal-cancel:hover { background: #d0d0d0; }

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* Login overlay */
#login-overlay {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#login-overlay.hidden { display: none; }
#login-box {
  background: #f8f8f8;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 32px;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  text-align: center;
}
#login-box h2 {
  font-weight: 400;
  font-size: 18px;
  margin-bottom: 20px;
  color: #333;
}
#login-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: #333;
}
#login-box input:focus { border-color: #007acc; }
#login-box button {
  margin-top: 16px;
  padding: 8px 28px;
  background: #0e639c;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}
#login-box button:hover { background: #1177bb; }
#login-error {
  color: #c5332e;
  font-size: 13px;
  margin-top: 8px;
}

/* Loading overlay */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
#loading-box {
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  padding: 20px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  font-size: 14px;
  color: #333;
  min-width: 400px;
}
#loading-log {
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.8;
  padding: 8px 12px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 4px;
  white-space: pre-wrap;
}
#loading-log .log-line { display: block; }
#loading-log .log-spin::before {
  content: '⏳ ';
}
#loading-log .log-ok::before {
  content: '✅ ';
}
#loading-log .log-fail::before {
  content: '❌ ';
}
#loading-close {
  margin-top: 4px;
  padding: 6px 24px;
  background: #0e639c;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
#loading-close:hover { background: #1177bb; }
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #d0d0d0;
  border-top-color: #007acc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
