:root {
  --bg: #0f1115;
  --bg-card: #171a21;
  --bg-elevated: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-muted: #9aa0ab;
  --primary: #4f7cff;
  --primary-hover: #6690ff;
  --danger: #e5484d;
  --danger-hover: #ff6166;
  --success: #3dd68c;
  --radius: 10px;
  --font: 'Segoe UI', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.muted { color: var(--text-muted); }

/* ---- Auth screen ---- */
#screen-app-login {
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  width: 90%;
  max-width: 360px;
  text-align: center;
}
.auth-card h1 { margin-bottom: 4px; font-size: 22px; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.row-center { display: flex; align-items: center; gap: 12px; }
.conn-badge {
  background: var(--bg-elevated);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
}

.container { padding: 20px; max-width: 900px; margin: 0 auto; }
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-elevated); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }

/* ---- Forms ---- */
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 14px;
}
label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 6px; }
.form-row { display: flex; gap: 12px; }
.form-row > div { flex: 1; }
.small-field { max-width: 110px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.checkbox-label input { width: auto; margin: 0; }

.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---- Connections grid ---- */
.connections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.connection-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.connection-card:hover { border-color: var(--primary); }
.connection-card h3 { margin: 0 0 6px; font-size: 15px; }
.connection-card .proto-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  margin-bottom: 8px;
}
.connection-card .host-line { font-size: 13px; color: var(--text-muted); direction: ltr; text-align: right; }
.connection-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.connection-card-actions button {
  font-size: 12px;
  padding: 5px 10px;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-content {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.confirm-card { max-width: 380px; text-align: center; }
#confirm-message { margin-bottom: 18px; }

/* ---- Toolbar / breadcrumbs ---- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.breadcrumbs {
  font-size: 13px;
  color: var(--text-muted);
  direction: ltr;
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
}
.breadcrumbs span {
  cursor: pointer;
  color: var(--primary);
}
.breadcrumbs span:hover { text-decoration: underline; }
.toolbar-actions { display: flex; gap: 8px; }
.file-upload-btn { position: relative; }

.upload-progress {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}

/* ---- File list ---- */
.file-list { padding: 8px 20px 40px; max-width: 900px; margin: 0 auto; }
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.file-row:hover { background: var(--bg-card); }
.file-icon { font-size: 18px; width: 24px; text-align: center; }
.file-name { flex: 1; font-size: 14px; }
.file-meta { font-size: 12px; color: var(--text-muted); direction: ltr; }
.file-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.file-row:hover .file-actions { opacity: 1; }
.file-actions button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
}
.file-actions button:hover { background: var(--bg-elevated); color: var(--text); }
.loading, .empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; }

/* ---- Editor ---- */
.editor-card { max-width: 800px; width: 95%; }
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#editor-textarea {
  width: 100%;
  height: 55vh;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  direction: ltr;
  text-align: left;
  resize: vertical;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

.select-all-label { margin: 0; white-space: nowrap; }

/* ---- Bulk action bar ---- */
.bulk-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.bulk-actions { display: flex; gap: 8px; }
.bulk-actions .btn { font-size: 13px; padding: 7px 12px; }

/* ---- File row checkbox ---- */
.file-checkbox {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}
.file-row.selected { background: var(--bg-elevated); }

/* ---- Folder picker ---- */
.folder-picker-card { max-width: 480px; }
.picker-list { max-height: 45vh; overflow-y: auto; padding: 4px 0; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.picker-row:hover { background: var(--bg-elevated); }
.picker-row.current-target { background: var(--bg-elevated); border: 1px solid var(--primary); }

@media (max-width: 600px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-actions { justify-content: flex-end; }
  .bulk-bar { flex-direction: column; align-items: stretch; gap: 8px; }
}
