:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2430;
  --panel: #11161d;
  --border: #263041;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --bg2: #ffffff;
  --bg3: #eef1f6;
  --panel: #ffffff;
  --border: #d7dee8;
  --text: #1a2230;
  --muted: #5b6779;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.12);
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
button:hover {
  background: var(--bg2);
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover {
  filter: brightness(1.1);
}
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
button.ghost {
  background: transparent;
}
input[type="text"],
input[type="password"],
input[type="search"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus,
select:focus {
  border-color: var(--accent);
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- login ---------- */
#login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2740 0%, var(--bg) 55%);
  z-index: 100;
  padding: 20px;
}
#login.hidden {
  display: none;
}
.login-card {
  width: min(380px, 100%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .logo {
  font-size: 40px;
  margin-bottom: 6px;
}
.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.login-card p {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 13px;
}
.login-card input {
  width: 100%;
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 2px;
}
.login-card button {
  width: 100%;
  padding: 11px;
}
.login-err {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 10px;
}

/* ---------- app shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
#app.hidden {
  display: none;
}
header.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  white-space: nowrap;
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.brand .dot.on {
  background: var(--accent2);
  box-shadow: 0 0 8px var(--accent2);
}
.brand .dot.off {
  background: var(--danger);
}
.topbar .spacer {
  flex: 1;
}
.pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.pill b {
  color: var(--text);
  font-weight: 600;
}
.iconbtn {
  padding: 7px 9px;
}

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
#files {
  flex: 0 0 var(--split, 46%);
  border-right: 1px solid var(--border);
}
#term {
  flex: 1 1 auto;
  background: #0b0f15;
}
#splitter {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--border);
  opacity: 0.4;
  transition: opacity 0.15s;
}
#splitter:hover {
  opacity: 1;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
}
.panel-head .title {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- file manager ---------- */
.crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  white-space: nowrap;
  scrollbar-width: thin;
}
.crumbs button {
  background: transparent;
  border: none;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--accent);
}
.crumbs button:hover {
  background: var(--bg3);
}
.crumbs .sep {
  color: var(--muted);
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
}
.toolbar .grow {
  flex: 1;
}
.toolbar input[type="search"] {
  min-width: 90px;
  max-width: 220px;
  flex: 1;
}
.filelist {
  flex: 1;
  overflow: auto;
  position: relative;
}
.dragover::after {
  content: "Drop files to upload";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(59, 130, 246, 0.15);
  border: 2px dashed var(--accent);
  color: var(--text);
  font-weight: 600;
  z-index: 5;
}
table.fl {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
table.fl thead th {
  position: sticky;
  top: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 8px;
  cursor: pointer;
  user-select: none;
  z-index: 2;
}
table.fl thead th.no-sort {
  cursor: default;
}
table.fl td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
table.fl tr:hover td {
  background: rgba(59, 130, 246, 0.08);
}
table.fl tr.sel td {
  background: rgba(59, 130, 246, 0.16);
}
.file-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.file-name .nm {
  overflow: hidden;
  text-overflow: ellipsis;
}
.ficon {
  width: 20px;
  text-align: center;
  flex: 0 0 22px;
  font-size: 15px;
}
.fsize,
.fdate,
.fmode {
  color: var(--muted);
  font-size: 12.5px;
}
.rowacts {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}
.rowacts button {
  padding: 3px 6px;
  font-size: 12px;
  background: transparent;
  border-color: transparent;
}
.rowacts button:hover {
  border-color: var(--border);
  background: var(--bg3);
}
.act-col {
  width: 110px;
}
.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}
.empty {
  padding: 30px;
  text-align: center;
  color: var(--muted);
}
.checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  padding: 10px;
}
.gcard {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  position: relative;
}
.gcard:hover {
  border-color: var(--accent);
}
.gcard.sel {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}
.gcard .ic {
  font-size: 30px;
}
.gcard .nm {
  margin-top: 6px;
  font-size: 12.5px;
  word-break: break-word;
}
.gcard .cb {
  position: absolute;
  top: 6px;
  left: 6px;
}

/* ---------- terminal ---------- */
.term-wrap {
  flex: 1;
  min-height: 0;
  padding: 6px 4px 0 8px;
  overflow: hidden;
}
#xterm {
  width: 100%;
  height: 100%;
}
#xterm .xterm {
  height: 100%;
  padding: 2px 0 2px 2px;
}
.term-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
}
.term-toolbar .grow {
  flex: 1;
}
.term-toolbar button {
  padding: 4px 8px;
  font-size: 12.5px;
}
.keybar {
  display: none;
  gap: 5px;
  padding: 6px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  overflow-x: auto;
}
.keybar button {
  padding: 7px 10px;
  font-size: 13px;
  min-width: 40px;
}
.keybar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.term-badge {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
}
#term {
  position: relative;
}
.term-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 15, 21, 0.75);
  z-index: 6;
  text-align: center;
  padding: 20px;
}
.term-overlay.hidden {
  display: none;
}

/* ---------- modal / menu ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 18px;
}
.overlay.hidden {
  display: none;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: min(440px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 20px;
}
.modal h3 {
  margin: 0 0 8px;
  font-size: 17px;
}
.modal p {
  color: var(--muted);
  margin: 0 0 16px;
  word-break: break-word;
}
.modal input {
  width: 100%;
  margin-bottom: 14px;
}
.modal .row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal img,
.modal pre {
  max-width: 100%;
  border-radius: 8px;
}
.modal pre {
  background: var(--bg);
  padding: 12px;
  overflow: auto;
  max-height: 60vh;
  font-size: 12.5px;
}
.preview-modal {
  width: min(900px, 100%);
}
.menu {
  position: fixed;
  z-index: 80;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px;
  min-width: 180px;
}
.menu.hidden {
  display: none;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
}
.menu button:hover {
  background: var(--bg3);
}
.menu button.danger {
  color: var(--danger);
  background: transparent;
}

/* ---------- mobile tabs ---------- */
.tabbar {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.tabbar button {
  flex: 1;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 10px;
  color: var(--muted);
}
.tabbar button.active {
  color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 90;
  max-width: 90vw;
  font-size: 13px;
}
.toast.hidden {
  display: none;
}
.toast.err {
  border-color: var(--danger);
  color: #ff9a9a;
}
.spin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: sp 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes sp {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  #splitter {
    display: none;
  }
  .main {
    flex-direction: column;
  }
  #files,
  #term {
    flex: 1 1 100%;
    border-right: none;
  }
  body[data-tab="files"] #term {
    display: none;
  }
  body[data-tab="term"] #files {
    display: none;
  }
  .tabbar {
    display: flex;
  }
  .keybar {
    display: flex;
  }
  .topbar .hide-sm {
    display: none;
  }
  .act-col {
    width: 84px;
  }
  .fmode {
    display: none;
  }
}
