:root {
  --bg: #12161c;
  --panel: #181d25;
  --panel-2: #1f252f;
  --border: #2a313d;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4f8dfd;
  --accent-2: #2fbf8f;
  --danger: #e6584f;
  --warn: #d9a441;
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

/* App shell (index.php only) - a flex column so .panes always fills
   whatever vertical space actually remains, whatever else is on screen
   (transfer panel, etc), instead of a hardcoded height calc() that has
   no idea what else might be present. */
.app-shell {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- Auth screens ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at 30% 20%, #1a2130, #0e1116 70%);
}

.auth-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: 0.5px;
}

.auth-card h1 { margin: 0; font-size: 19px; }
.auth-sub { margin: -8px 0 6px; color: var(--muted); font-size: 13px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

input[type=text], input[type=password], input[type=number] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  outline: none;
}
input[type=text]:focus, input[type=password]:focus, input[type=number]:focus {
  border-color: var(--accent);
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.checkbox-row input { width: auto; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #3f7bec; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-ghost { background: transparent; }
.btn-icon { width: 40px; height: 40px; font-size: 18px; border-radius: 50%; }
.btn-file { position: relative; overflow: hidden; }
.btn-danger { border-color: rgba(230, 88, 79, .4); color: #ff9891; }
.btn-danger:hover { background: rgba(230, 88, 79, .12); border-color: var(--danger); }

.alert {
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.alert-error { background: rgba(230, 88, 79, .12); color: #ff9891; border: 1px solid rgba(230,88,79,.35); }

/* ---------- Top bar ---------- */
.topbar {
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
}
.brand-name { font-weight: 600; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.app-user-pill {
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.conn-pill {
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(47, 191, 143, .12);
  color: #7fe0bd;
  border: 1px solid rgba(47, 191, 143, .3);
}

/* ---------- Connect screen ---------- */
.connect-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 60px 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}
.connect-card { width: 420px; display: flex; flex-direction: column; gap: 14px; }
.connect-card h2 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); font-size: 12.5px; margin: -6px 0 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.save-connection-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  margin-top: -4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.save-connection-fields[hidden] { display: none; }

.connect-form-actions {
  display: flex;
  gap: 10px;
}
.connect-form-actions .btn-block { flex: 1; }

.saved-connections-card { width: 420px; }
.saved-connections-card[hidden] { display: none; }
.saved-connections-card h2 { margin: 0 0 12px; font-size: 15px; }

.saved-connections-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.saved-connection-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.saved-connection-info { flex: 1; min-width: 0; }
.saved-connection-name {
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.saved-connection-detail {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.saved-connection-nopass {
  font-size: 10.5px;
  color: var(--warn);
  margin-left: 6px;
}

.saved-connection-passrow {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  flex-basis: 100%;
}
.saved-connection-passrow input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 12.5px;
}

/* ---------- Panes ---------- */
.panes {
  display: grid;
  grid-template-columns: 1fr 56px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}
.pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.pane[data-side="remote"] { border-right: none; border-left: 1px solid var(--border); }

.pane-header {
  padding: 12px 16px 6px;
}
.pane-header h2 { margin: 0; font-size: 14px; display: flex; align-items: baseline; gap: 8px; }
.pane-sub { font-size: 11.5px; color: var(--muted); font-weight: 400; font-family: var(--mono); }

.pane-toolbar {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  flex-wrap: wrap;
}

.pane-path {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow-x: auto;
  white-space: nowrap;
}

.pane-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.row {
  display: grid;
  grid-template-columns: 20px 1fr 90px 130px;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  cursor: default;
  border-bottom: 1px solid transparent;
}
.row:hover { background: var(--panel-2); }
.row.selected { background: rgba(79, 141, 253, .14); }
.row .icon { font-size: 14px; text-align: center; }
.row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.row .size, .row .mtime {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}
.row.dir .name { color: #dbe6ff; font-weight: 500; }
.row-empty { padding: 20px 16px; color: var(--muted); font-size: 13px; }

.pane-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--panel);
}

.statusbar {
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-family: var(--mono);
}

.transfer-panel {
  padding: 10px 16px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.transfer-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  margin-bottom: 6px;
}
.transfer-info #transferLabel { font-weight: 600; color: var(--text); }
.transfer-info #transferStats { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.transfer-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--border);
}
.transfer-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease-out;
}

.toast-stack {
  position: fixed;
  bottom: 40px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--accent-2); }

@media (max-width: 900px) {
  .panes { grid-template-columns: 1fr; height: auto; }
  .pane-actions { flex-direction: row; padding: 10px; }
}

/* ---------- History drawer ---------- */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 60;
}

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 61;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.35);
}

/* [hidden] and .history-drawer have equal specificity on their own, so
   the later rule (ours) would otherwise win and defeat `hidden` entirely.
   This selector is more specific than plain .history-drawer, so it
   correctly overrides display:flex whenever the attribute is present. */
.history-drawer[hidden] {
  display: none;
}

.history-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.history-drawer-header h3 { margin: 0; font-size: 15px; }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.history-empty {
  padding: 30px 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.history-row {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.history-row-dir { font-family: var(--mono); color: var(--muted); }
.history-row-summary {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.status-badge {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-done { background: rgba(47,191,143,.15); color: #7fe0bd; }
.status-error { background: rgba(230,88,79,.15); color: #ff9891; }
.status-conflict { background: rgba(217,164,65,.15); color: #f0c675; }
.status-interrupted { background: rgba(139,147,163,.18); color: #b7bdc9; }
.status-running { background: rgba(79,141,253,.15); color: #a9c6ff; animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.history-row-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.history-row-bar-track {
  height: 4px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--border);
}
.history-row-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease-out;
}

.history-row-files-wrap { margin-top: 2px; }

.history-files-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  padding: 0;
  cursor: pointer;
}
.history-files-toggle:hover { text-decoration: underline; }

.history-row-files {
  margin-top: 6px;
  max-height: 160px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.history-row-files[hidden] { display: none; }

.history-file-line {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 0;
}
.history-file-more { color: var(--muted); font-style: italic; }
