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

:root {
  --z-tooltip: 800;
  --monospace: 'Google Sans Code', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  --sans-serif: 'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-family: var(--sans-serif);
}

button {
  font-family: inherit;
}

body {
  background: var(--sand-1);
  color: var(--sand-12);
  height: 100vh;
  overflow: hidden;
  --panel-header-height: 2.5rem;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: grid;
  grid-template-columns: minmax(0, 20%) 1fr minmax(0, 20%);
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--sand-6);
}

.app-container:has(file-explorer.collapsed):has(reserved-panel.collapsed) {
  grid-template-columns: 40px 1fr 40px;
}

.app-container:has(file-explorer.collapsed):not(:has(reserved-panel.collapsed)) {
  grid-template-columns: 40px 1fr minmax(0, 20%);
}

.app-container:not(:has(file-explorer.collapsed)):has(reserved-panel.collapsed) {
  grid-template-columns: minmax(0, 20%) 1fr 40px;
}

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

file-explorer.collapsed {
  min-width: 40px;
  max-width: 40px;
}

file-explorer .header {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 8px 12px;
  background: var(--sand-2);
  border-bottom: 1px solid var(--sand-6);
  height: var(--panel-header-height);
}

file-explorer .header h2 {
  font-size: 14px;
  font-weight: 500;
}

file-explorer.collapsed .header h2 {
  display: none;
}

file-explorer .button:first-of-type {
  margin-left: auto;
}

file-explorer .button {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--sand-11);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem;
  line-height: 1rem;
}

file-explorer .button i {
  display: block;
  height: 1rem;
  width: 1rem;
}


file-explorer .button:hover {
  color: var(--sand-12);
  background: var(--sand-4);
  border-radius: 3px;
}

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

file-explorer.collapsed .tree-view {
  display: none;
}

file-explorer.collapsed .header {
  padding: 0;
  justify-content: center;
}

file-explorer.collapsed .header > *:not(.collapse-button) {
  display: none;
}

file-explorer details {
  margin: 2px 0;
}

file-explorer summary {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

file-explorer summary::-webkit-details-marker {
  display: none;
}

file-explorer summary:hover {
  background: var(--sand-3);
}

file-explorer .folder-icon {
  flex-shrink: 0;
  font-size: 1rem;
  color: var(--sand-11);
}

file-explorer .file-icon {
  flex-shrink: 0;
  font-size: 1rem;
  color: var(--sand-11);
}

file-explorer .file-icon.icon-file-lock {
  color: #a61e1e;
}

file-explorer .file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 8px;
  border-radius: 3px;
}

file-explorer .file-extname {
  font-weight: 600;
}

file-explorer .file-item:hover {
  background: var(--sand-3);
}

file-explorer .file-name {
  flex: 1;
  cursor: pointer;
}

file-explorer .mjs-button {
  flex-shrink: 0;
  padding: 1px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--sand-7);
  background: var(--sand-3);
  color: var(--sand-11);
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.2;
  transition: all 0.15s ease;
}

file-explorer .mjs-button:hover {
  background: var(--sand-4);
  border-color: var(--sand-8);
  color: var(--sand-12);
}

file-explorer .mjs-button:active {
  background: var(--sand-5);
  transform: translateY(1px);
}

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

editor-panel .tab-bar-wrapper {
  position: relative;
  display: flex;
  background: var(--sand-2);
  border-bottom: 1px solid var(--sand-6);
  height: var(--panel-header-height);
}

editor-panel .tab-bar {
  display: flex;
  flex: 1;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

editor-panel .tab-bar::-webkit-scrollbar {
  display: none;
}

editor-panel .tab-scroll-arrow {
  display: none;
  position: absolute;
  top: 0;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 100%;
  background: linear-gradient(to right, var(--sand-2), transparent);
  border: none;
  color: var(--sand-11);
  cursor: pointer;
  font-size: 20px;
  font-weight: bold;
  padding: 0;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

editor-panel .tab-scroll-arrow.visible {
  opacity: 1;
  pointer-events: auto;
}

editor-panel .tab-scroll-arrow:hover {
  color: var(--sand-12);
}

editor-panel .tab-scroll-left {
  left: 0;
  background: linear-gradient(to right, var(--sand-2) 75%, transparent);
}

editor-panel .tab-scroll-right {
  right: 0;
  background: linear-gradient(to left, var(--sand-2) 75%, transparent);
}

editor-panel .tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  background: var(--sand-3);
  border-right: 1px solid var(--sand-6);
  cursor: pointer;
  font-size: 0.875rem;
  white-space: nowrap;
  color: var(--sand-11);
  user-select: none;
}

editor-panel .tab.active {
  background: var(--sand-1);
  color: var(--sand-12);
  font-weight: 500;
}

editor-panel .tab:not(.active):hover {
  background: var(--sand-4);
  color: var(--sand-12);
}

editor-panel .tab-name {
  display: flex;
  align-items: baseline;
}

editor-panel .tab-extension {
  font-weight: 600;
  color: var(--sand-11);
}

editor-panel .tab-close {
  background: none;
  border: none;
  color: var(--sand-11);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

editor-panel .tab-close:hover {
  color: var(--sand-12);
  background: var(--sand-5);
}

editor-panel .tab-tooltip {
  font-size: 0.875rem;
  color: var(--sand-11);
  position: absolute;
  width: max-content;
  max-width: 400px;
  top: 0;
  left: 0;
  background: var(--sand-2);
  border: 1px solid var(--sand-6);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  z-index: 10;
  word-break: break-all;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease 0s;
}

editor-panel .tab-tooltip.visible {
  opacity: 0.9;
  pointer-events: auto;
}

editor-panel .editor-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

editor-panel .editor-codemirror {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  overflow: hidden;
}

editor-panel .editor-codemirror.active {
  display: block;
}

/* CodeMirror customization */
editor-panel .cm-editor {
  height: 100%;
  background: var(--sand-1);
  color: var(--sand-12);
}

editor-panel .cm-gutters {
  background: var(--sand-1);
  color: var(--sand-11);
  border-right: 1px solid var(--sand-6);
}

editor-panel .empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--sand-11);
  font-size: 14px;
}

editor-panel .empty-state.hidden {
  display: none;
}

/* Reserved Panel */
reserved-panel {
  display: flex;
  flex-direction: column;
  background: var(--sand-1);
  border-left: 1px solid var(--sand-6);
  overflow: hidden;
}

reserved-panel.collapsed {
  min-width: 40px;
  max-width: 40px;
}

reserved-panel .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--sand-2);
  border-bottom: 1px solid var(--sand-6);
  height: var(--panel-header-height);
}

reserved-panel .header h2 {
  font-size: 14px;
  font-weight: 500;
}

reserved-panel.collapsed .header h2 {
  display: none;
}

reserved-panel .collapse-btn {
  background: none;
  border: none;
  color: var(--sand-11);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
}

reserved-panel .collapse-btn:hover {
  color: var(--sand-12);
  background: var(--sand-4);
  border-radius: 3px;
}

reserved-panel .content {
  flex: 1;
  display: flex;
  color: var(--sand-11);
  font-size: 14px;
  overflow: hidden;
}

reserved-panel.collapsed .content {
  display: none;
}

reserved-panel .output-textarea {
  flex: 1;
  width: 100%;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Google Sans Code', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 14px;
  line-height: 1.5;
  background: var(--sand-1);
  color: var(--sand-12);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--sand-2);
}

::-webkit-scrollbar-thumb {
  background: var(--sand-6);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--sand-7);
}

/* Toolbar */
toolbar-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--sand-2);
  border-bottom: 1px solid var(--sand-6);
  min-height: 44px;
  gap: 16px;
  position: relative;
}

toolbar-panel .title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--sand-12);
  user-select: none;
  letter-spacing: -0.02em;
}

toolbar-panel .status-container {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

toolbar-panel .status-light {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

toolbar-panel .status-idle {
  background: var(--sand-7);
  opacity: 0.5;
}

toolbar-panel .status-running {
  background: #0091ff;
  animation: pulse 1.5s ease-in-out infinite;
}

toolbar-panel .status-done {
  background: #46a758;
}

toolbar-panel .status-error {
  background: #e5484d;
}

toolbar-panel .status-aborted {
  background: #f76b15;
}

toolbar-panel .status-fatal {
  background: #8e4ec6;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 4px rgba(0, 145, 255, 0.4);
  }
  50% {
    opacity: 0.6;
    box-shadow: 0 0 8px rgba(0, 145, 255, 0.8);
  }
}

toolbar-panel .status-text {
  font-size: 13px;
  color: var(--sand-11);
  font-weight: 500;
}

toolbar-panel .status-tooltip {
  display: none;
  font-size: 0.875rem;
  color: var(--sand-11);
  position: absolute;
  width: max-content;
  top: 0;
  left: 0;
  background: var(--sand-2);
  border: 1px solid var(--sand-6);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  z-index: var(--z-tooltip);
}

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

toolbar-panel .compile-btn {
  background: var(--sand-12);
  color: var(--sand-1);
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
  display: flex;
  flex-direction: row;
  align-items: center;
}

toolbar-panel .compile-btn i {
  margin-right: 0.25rem;
}

toolbar-panel .compile-btn:hover {
  background: var(--sand-11);
}

toolbar-panel .compile-btn:active {
  background: var(--sand-12);
  transform: translateY(1px);
}

toolbar-panel .compile-btn.loading {
  background: var(--sand-7);
  cursor: not-allowed;
  pointer-events: none;
}

toolbar-panel .compile-btn.loading:hover {
  background: var(--sand-7);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

toolbar-panel .compile-btn.loading i {
  animation: spin 1s linear infinite;
}

toolbar-panel .terminate-btn {
  background: #e5484d;
  color: white;
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

toolbar-panel .terminate-btn:hover {
  background: #dc3e42;
}

toolbar-panel .terminate-btn:active {
  background: #e5484d;
  transform: translateY(1px);
}

/* Console Panel */
console-panel {
  display: flex;
  flex-direction: column;
  background: var(--sand-1);
  border-top: 1px solid var(--sand-6);
  overflow: hidden;
  min-height: 200px;
  max-height: 400px;
  resize: vertical;
}

console-panel.collapsed {
  min-height: 40px;
  max-height: 40px;
  resize: none;
}

console-panel .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--sand-2);
  border-bottom: 1px solid var(--sand-6);
  height: var(--panel-header-height);
}

console-panel .header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

console-panel .header h2 {
  font-size: 14px;
  font-weight: 500;
}

console-panel.collapsed .header h2 {
  display: none;
}

console-panel .clear-btn {
  background: none;
  border: 1px solid var(--sand-7);
  color: var(--sand-11);
  cursor: pointer;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 3px;
  font-weight: 500;
}

console-panel .clear-btn:hover {
  background: var(--sand-4);
  color: var(--sand-12);
  border-color: var(--sand-8);
}

console-panel.collapsed .clear-btn {
  display: none;
}

console-panel .collapse-btn {
  background: none;
  border: none;
  color: var(--sand-11);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
}

console-panel .collapse-btn:hover {
  color: var(--sand-12);
  background: var(--sand-4);
  border-radius: 3px;
}

console-panel .console-content {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  font-family: var(--monospace);
  font-size: 0.875rem;
  line-height: 1.4;
}

console-panel.collapsed .console-content {
  display: none;
}

console-panel .console-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 12px;
  border-bottom: 1px solid transparent;
}

console-panel .console-message:hover {
  background: var(--sand-2);
}

console-panel .console-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

console-panel .console-text {
  flex: 1;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Console message type styles */
console-panel .console-log {
  color: var(--sand-12);
}

console-panel .console-log .console-icon {
  color: var(--sand-11);
}

console-panel .console-error {
  color: #e5484d;
  background: rgba(229, 72, 77, 0.05);
  border-bottom-color: rgba(229, 72, 77, 0.1);
}

console-panel .console-error .console-icon {
  color: #e5484d;
}

console-panel .console-warn {
  color: #f76b15;
  background: rgba(247, 107, 21, 0.05);
  border-bottom-color: rgba(247, 107, 21, 0.1);
}

console-panel .console-warn .console-icon {
  color: #f76b15;
}

console-panel .console-info {
  color: #0091ff;
  background: rgba(0, 145, 255, 0.05);
  border-bottom-color: rgba(0, 145, 255, 0.1);
}

console-panel .console-info .console-icon {
  color: #0091ff;
}
