:root {
  --bg: #1a1d23;
  --surface: #252830;
  --surface2: #2e323c;
  --border: #3a3f4b;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #4a9eff;
  --accent-hover: #3d8ce6;
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1d23 0%, #2d3142 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: min(380px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo { font-size: 48px; margin-bottom: 12px; }

.login-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.login-card p { color: var(--text-muted); margin-bottom: 24px; font-size: 0.9rem; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

.login-card button:hover { background: var(--accent-hover); }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 10px; }

/* App layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.titlebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.logo { font-size: 1.2rem; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar button {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.toolbar button:hover:not(:disabled) { background: var(--border); }
.toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }
.toolbar button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar button.btn-danger:hover:not(:disabled) { background: rgba(255, 107, 107, 0.2); border-color: var(--danger); color: var(--danger); }

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.view-toggle { margin-left: auto; display: flex; gap: 2px; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.85rem;
}

.breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.breadcrumb button:hover { background: var(--surface2); }
.breadcrumb span.sep { color: var(--text-muted); }

.file-area {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.file-list {
  display: grid;
  gap: 8px;
}

.grid-view .file-list {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

.list-view .file-list {
  grid-template-columns: 1fr;
}

.file-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  user-select: none;
  transition: background 0.15s;
}

.list-view .file-item {
  flex-direction: row;
  padding: 8px 12px;
  gap: 12px;
}

.file-item:hover { background: var(--surface2); }
.file-item.selected { background: rgba(74, 158, 255, 0.15); border-color: var(--accent); }

.file-icon { font-size: 2.2rem; line-height: 1; }
.list-view .file-icon { font-size: 1.5rem; }

.file-name {
  font-size: 0.8rem;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
}

.list-view .file-name { flex: 1; text-align: left; }

.file-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: none;
}

.list-view .file-meta { display: block; min-width: 120px; text-align: left; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 0.95rem;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.progress-wrap {
  width: min(280px, 100%);
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6eb6ff);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Modals */
.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(640px, 94vw);
  box-shadow: var(--shadow);
}

.modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal-sm { width: min(400px, 94vw); }
.modal-image { width: min(860px, 96vw); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--surface2); color: var(--text); }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

#editorContent {
  width: 100%;
  min-height: 360px;
  padding: 16px;
  background: var(--surface2);
  color: var(--text);
  border: none;
  resize: vertical;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

.server-info-body {
  padding: 12px 18px 8px;
}

.server-info-section {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin: 14px 0 8px;
}

.server-info-section:first-child {
  margin-top: 0;
}

.server-info-path {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.server-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 5px 0;
  font-size: 0.88rem;
}

.server-info-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.server-info-value {
  text-align: right;
  word-break: break-word;
}

.server-info-mono {
  font-size: 0.78rem;
  color: var(--text);
}

.server-info-meter {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0 4px;
}

.server-info-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6eb6ff);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.server-info-meter-fill.meter-warn {
  background: linear-gradient(90deg, #e9a23b, #f0c060);
}

.server-info-meter-fill.meter-crit {
  background: linear-gradient(90deg, #e85d5d, var(--danger));
}

#promptInput {
  width: calc(100% - 36px);
  margin: 16px 18px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
}

.image-preview-wrap {
  padding: 16px;
  text-align: center;
  max-height: 70vh;
  overflow: auto;
}

.image-preview-wrap img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: var(--radius);
}

.perm-path {
  padding: 8px 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
}

.perm-grid { padding: 8px 18px; }

.perm-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, 60px);
  align-items: center;
  padding: 6px 0;
  gap: 8px;
}

.perm-header { color: var(--text-muted); font-size: 0.8rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 4px; }
.perm-row label { text-align: center; cursor: pointer; }
.perm-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.perm-octal {
  padding: 8px 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.perm-octal input {
  width: 80px;
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: monospace;
  text-align: center;
}

.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  padding: 8px 18px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-ghost:hover { background: var(--surface2); color: var(--text); }

@media (max-width: 600px) {
  .toolbar button { padding: 6px 8px; font-size: 0.78rem; }
  .grid-view .file-list { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
}
