/* ────────────────────────────────────────────────────────────────────────────
   Fortunia IDE — VS Code Dark Theme
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #1e1e1e;
  --bg-sidebar:   #252526;
  --bg-panel:     #1e1e1e;
  --bg-input:     #3c3c3c;
  --bg-hover:     #2a2d2e;
  --bg-active:    #37373d;
  --bg-tab:       #2d2d2d;
  --bg-tab-act:   #1e1e1e;
  --border:       #3c3c3c;
  --border-focus: #007acc;
  --text:         #cccccc;
  --text-dim:     #858585;
  --text-bright:  #ffffff;
  --accent:       #007acc;
  --accent-hover: #1f8ad2;
  --green:        #4ec9b0;
  --yellow:       #dcdcaa;
  --orange:       #ce9178;
  --red:          #f44747;
  --warn:         #ff8c00;
  --info:         #75beff;
  --statusbar:    #007acc;
  --statusbar-bg: #007acc;
  --font-ui:      -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  --radius:       3px;
  --transition:   120ms ease;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 13px; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px; font: inherit; outline: none; }
input:focus, select:focus { border-color: var(--border-focus); }
a { color: var(--accent); text-decoration: none; }
ul { list-style: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #424242; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 9999;
}
.login-card {
  background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 6px;
  padding: 40px 48px; width: 360px; text-align: center;
}
.login-card .logo { font-size: 28px; font-weight: 700; color: var(--text-bright); margin-bottom: 6px; }
.login-card .subtitle { color: var(--text-dim); margin-bottom: 28px; font-size: 12px; }
.login-card input { width: 100%; margin-bottom: 12px; padding: 8px 12px; font-size: 13px; }
.login-card .btn-login {
  width: 100%; background: var(--accent); color: #fff; padding: 9px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; transition: background var(--transition);
}
.login-card .btn-login:hover { background: var(--accent-hover); }
.login-error { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 18px; }

/* ── App Shell ────────────────────────────────────────────────────────────── */
#app {
  display: none; flex-direction: column; height: 100vh; overflow: hidden;
}
#app.visible { display: flex; }

/* Title bar */
#titlebar {
  height: 30px; background: #323233; display: flex; align-items: center;
  padding: 0 12px; gap: 8px; flex-shrink: 0; user-select: none;
  border-bottom: 1px solid var(--border); justify-content: space-between;
}
#titlebar .logo { font-weight: 600; font-size: 12px; color: var(--text-dim); }
#titlebar .project-name { font-size: 12px; color: var(--text); }
#titlebar .titlebar-actions { display: flex; gap: 6px; }

/* Main layout: sidebar + editor area */
#main {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}

/* ── Activity Bar (left icons) ────────────────────────────────────────────── */
#activity-bar {
  width: 48px; background: #333333; display: flex; flex-direction: column;
  align-items: center; padding-top: 4px; flex-shrink: 0; border-right: 1px solid var(--border);
  gap: 2px; z-index: 10;
}
.activity-btn {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); color: var(--text-dim); transition: color var(--transition), background var(--transition);
  position: relative;
}
.activity-btn:hover { color: var(--text); }
.activity-btn.active { color: var(--text-bright); }
.activity-btn.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: var(--text-bright); border-radius: 0 2px 2px 0;
}
.activity-btn svg { width: 22px; height: 22px; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: 240px; background: var(--bg-sidebar); display: flex; flex-direction: column;
  flex-shrink: 0; border-right: 1px solid var(--border); overflow: hidden;
}
#sidebar-header {
  height: 35px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
#sidebar-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-dim);
}
.sidebar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); color: var(--text-dim); transition: color var(--transition), background var(--transition);
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn svg { width: 14px; height: 14px; }

/* Project selector */
#project-selector {
  padding: 8px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#project-selector select { width: 100%; font-size: 12px; }

/* File Explorer */
#file-explorer {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.tree-item {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 8px 2px 0; cursor: pointer; border-radius: var(--radius);
  transition: background var(--transition); user-select: none; position: relative;
}
.tree-item:hover { background: var(--bg-hover); }
.tree-item.selected { background: var(--bg-active); }
.tree-item .item-icon { width: 16px; height: 16px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.tree-item .item-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .item-actions { display: none; gap: 2px; }
.tree-item:hover .item-actions { display: flex; }
.tree-item .item-actions button { width: 18px; height: 18px; color: var(--text-dim); border-radius: 2px; display: flex; align-items: center; justify-content: center; }
.tree-item .item-actions button:hover { color: var(--text); background: var(--bg-input); }
.tree-dir > .item-name { font-weight: 400; }
.tree-indent { display: flex; flex-direction: column; }

.tree-item.unsaved .item-name::after {
  content: '●'; color: var(--text-dim); font-size: 8px; margin-left: 4px; vertical-align: middle;
}

/* ── Editor Area ──────────────────────────────────────────────────────────── */
#editor-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}

/* Tab bar */
#tab-bar {
  height: 35px; display: flex; background: var(--bg-tab); flex-shrink: 0;
  overflow-x: auto; overflow-y: hidden; border-bottom: 1px solid var(--border);
}
#tab-bar::-webkit-scrollbar { height: 3px; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 0 12px; min-width: 100px; max-width: 180px;
  height: 35px; cursor: pointer; background: var(--bg-tab); border-right: 1px solid var(--border);
  flex-shrink: 0; transition: background var(--transition); user-select: none; position: relative;
}
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--bg-tab-act); }
.tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px; background: var(--accent);
}
.tab .tab-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tab .tab-modified { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; display: none; }
.tab.modified .tab-modified { display: block; }
.tab.modified .tab-close { display: none; }
.tab:hover .tab-modified { display: none; }
.tab:hover .tab-close { display: flex !important; }
.tab .tab-close {
  display: none; width: 18px; height: 18px; align-items: center; justify-content: center;
  border-radius: 2px; color: var(--text-dim); flex-shrink: 0;
}
.tab.active .tab-close { display: flex; }
.tab .tab-close:hover { color: var(--text); background: var(--bg-input); }
.tab.modified.active .tab-close { display: flex; }
.tab.modified.active .tab-modified { display: none; }

/* Welcome / no file open */
#welcome-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--text-dim); gap: 12px;
}
#welcome-screen h2 { font-size: 20px; font-weight: 300; color: var(--text); }
#welcome-screen p { font-size: 13px; }

/* Monaco wrapper */
#monaco-container { flex: 1; overflow: hidden; display: none; }
#monaco-container.visible { display: block; }

/* ── Bottom Panel (Console/Logs) ──────────────────────────────────────────── */
#bottom-panel {
  height: 220px; background: var(--bg-panel); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden;
  transition: height 0.2s ease;
}
#bottom-panel.collapsed { height: 32px; }
#panel-tabs {
  height: 32px; display: flex; background: #252526; flex-shrink: 0;
  border-bottom: 1px solid var(--border); align-items: center;
}
.panel-tab {
  padding: 0 14px; height: 100%; display: flex; align-items: center;
  font-size: 12px; color: var(--text-dim); cursor: pointer; border-right: 1px solid var(--border);
  transition: color var(--transition); user-select: none; position: relative;
}
.panel-tab:hover { color: var(--text); }
.panel-tab.active { color: var(--text); }
.panel-tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px; background: var(--accent);
}
#panel-actions { margin-left: auto; display: flex; align-items: center; padding-right: 8px; gap: 4px; }

#console-output {
  flex: 1; overflow-y: auto; padding: 6px 12px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
}
.log-line { padding: 1px 0; border-radius: 2px; }
.log-line.error { color: var(--red); }
.log-line.warning { color: var(--warn); }
.log-line.info { color: var(--info); }
.log-line.ide { color: var(--green); }
.log-line.default { color: var(--text); }
.log-prefix { color: var(--text-dim); margin-right: 6px; }

/* SSE Status dot */
.sse-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim);
  display: inline-block; margin-right: 6px; flex-shrink: 0;
}
.sse-dot.connected { background: var(--green); box-shadow: 0 0 4px var(--green); }
.sse-dot.error { background: var(--red); }

/* ── Status Bar ───────────────────────────────────────────────────────────── */
#status-bar {
  height: 22px; background: var(--statusbar-bg); display: flex; align-items: center;
  padding: 0 8px; gap: 14px; font-size: 12px; color: #ffffff; flex-shrink: 0; user-select: none;
}
.status-item { display: flex; align-items: center; gap: 4px; cursor: default; }
.status-item:hover { background: rgba(255,255,255,.15); border-radius: 2px; padding: 0 4px; }
.status-item.clickable { cursor: pointer; }
#save-status { margin-left: auto; }
.save-indicator { color: var(--green); font-size: 11px; }
.save-indicator.saving { color: var(--warn); }
.save-indicator.error { color: var(--red); }

/* ── Notifications / Toasts ───────────────────────────────────────────────── */
#notifications {
  position: fixed; top: 36px; right: 12px; z-index: 9998;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  background: #252526; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; min-width: 280px; max-width: 400px; box-shadow: 0 4px 14px rgba(0,0,0,.5);
  display: flex; gap: 10px; align-items: flex-start; pointer-events: all;
  animation: slideIn 200ms ease; font-size: 12px;
}
.toast.info .toast-icon { color: var(--info); }
.toast.success .toast-icon { color: var(--green); }
.toast.warning .toast-icon { color: var(--warn); }
.toast.error .toast-icon { color: var(--red); }
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-msg { color: var(--text-dim); line-height: 1.4; }
.toast-close { color: var(--text-dim); flex-shrink: 0; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; border-radius: 2px; }
.toast-close:hover { color: var(--text); background: var(--bg-hover); }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }

/* ── Context Menu ─────────────────────────────────────────────────────────── */
.context-menu {
  position: fixed; background: #252526; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 0; min-width: 160px; z-index: 9000;
  box-shadow: 0 4px 14px rgba(0,0,0,.5); font-size: 13px;
}
.context-item {
  padding: 6px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: background var(--transition);
}
.context-item:hover { background: var(--bg-active); }
.context-item.danger { color: var(--red); }
.context-separator { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 9000;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 6px;
  padding: 24px; min-width: 320px; max-width: 500px;
}
.modal h3 { margin-bottom: 16px; font-size: 14px; }
.modal input { width: 100%; margin-bottom: 12px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn { padding: 6px 14px; border-radius: var(--radius); font-size: 13px; transition: background var(--transition); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-active); }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-danger:hover { background: #b71c1c; }

/* ── Reload Button ────────────────────────────────────────────────────────── */
#reload-btn {
  background: #2d7d32; color: #fff; padding: 3px 10px; border-radius: var(--radius);
  font-size: 12px; display: flex; align-items: center; gap: 5px; transition: background var(--transition);
}
#reload-btn:hover { background: #388e3c; }
#reload-btn.loading { background: #555; pointer-events: none; }

/* ── Resize handle ────────────────────────────────────────────────────────── */
#panel-resize {
  height: 4px; cursor: ns-resize; background: transparent; flex-shrink: 0;
}
#panel-resize:hover { background: var(--accent); }

/* ── Problems panel (errors) ──────────────────────────────────────────────── */
#problems-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
  font-family: var(--font-mono); font-size: 12px;
}
.problem-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 4px 12px; cursor: pointer; transition: background var(--transition);
  line-height: 1.4;
}
.problem-item:hover { background: var(--bg-hover); }
.problem-icon { flex-shrink: 0; margin-top: 1px; }
.problem-icon.error { color: var(--red); }
.problem-icon.warning { color: var(--warn); }
.problem-icon.info { color: var(--info); }
.problem-loc { color: var(--text-dim); font-size: 11px; white-space: nowrap; }

/* ── Breadcrumbs ──────────────────────────────────────────────────────────── */
#breadcrumbs {
  height: 22px; display: flex; align-items: center; padding: 0 12px; gap: 4px;
  background: var(--bg); border-bottom: 1px solid var(--border); font-size: 12px;
  color: var(--text-dim); flex-shrink: 0; overflow: hidden;
}
.breadcrumb-sep { color: var(--border); }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; display: inline-block; }
