:root {
  --bg: #0b1120;
  --surface: #0f172a;
  --card: #1e293b;
  --card-hover: #26354d;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Buttons & Inputs */
.btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--card-hover); border-color: #475569; }
.btn.active { background: var(--accent-strong); border-color: var(--accent); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #0369a1; }
.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }
.btn-full { width: 100%; padding: 10px; font-size: 14px; }

.text-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.text-input:focus { border-color: var(--accent); }
.search-sm { width: 190px; padding: 5px 9px; font-size: 12px; }

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
  background: radial-gradient(circle at top, #172554 0%, #0b1120 65%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.55);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.brand-logo { width: 44px; height: 44px; }
.brand-row h1 { margin: 0; font-size: 20px; }
.brand-row p { margin: 2px 0 0; }
.field-label { display: block; margin: 12px 0 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.error-banner {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fecaca;
  padding: 8px 10px;
  border-radius: 7px;
  margin-bottom: 12px;
  font-size: 12px;
}
.login-hint { margin: 14px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.top-left, .top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.brand-mini {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  padding-right: 8px;
  border-right: 1px solid var(--border);
}
.tab-nav { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 11px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.tab-btn.active {
  color: #fff;
  background: var(--card);
  border-color: var(--border);
}

.status-badge {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd;
}
.status-badge.ok { background: rgba(34, 197, 94, 0.14); border-color: rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.status-badge.warn { background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.4); color: #fde68a; }

.mini-pill {
  position: fixed;
  top: 8px;
  right: 10px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); }

/* Tab Panes */
.tab-pane {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}
.tab-pane.active {
  display: flex;
  flex-direction: column;
}

/* Screen Tab */
.screen-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: #131c31;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}
.inline-select select, .fkey-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
}

.special-keys-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: #0d1526;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.key-group { display: flex; align-items: center; gap: 5px; }
.key-sep { width: 1px; height: 20px; background: var(--border); }
.key-btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.key-btn:hover { background: var(--card-hover); }
.key-btn.latched { background: var(--accent-strong); border-color: var(--accent); color: #fff; }

.screen-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020617;
  overflow: auto;
  outline: none;
  touch-action: none;
}
#screen-canvas {
  display: block;
  background: #000;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.65);
  cursor: default;
}
.screen-waiting {
  position: absolute;
  padding: 12px 18px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(2, 132, 199, 0.25);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-box {
  background: var(--surface);
  border: 1px solid var(--accent);
  padding: 18px 28px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}

/* Apps & Windows Tab */
.pane-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-actions { display: flex; gap: 8px; align-items: center; }

.launch-form { display: flex; gap: 8px; }
.windows-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 10px;
}
.win-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.win-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-meta { font-size: 11px; color: var(--muted); }
.win-actions { display: flex; gap: 5px; flex-wrap: wrap; }

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
.app-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.app-tile:hover { background: var(--card-hover); border-color: var(--accent); }
.app-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-cat { font-size: 11px; color: var(--muted); }

/* Files Tab */
.files-layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}
.files-sidebar {
  width: 225px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-section { margin-bottom: 18px; }
.sidebar-section h3 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.sidebar-list { display: flex; flex-direction: column; gap: 4px; }
.side-item {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.side-item:hover { background: var(--card); }
.drive-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.drive-bar-fill { height: 100%; background: var(--accent); }

.files-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.files-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #131c31;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.path-form { display: flex; flex: 1 1 220px; gap: 5px; }
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  font-size: 12px;
}
.crumb-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
}
.crumb-btn:hover { background: var(--card); }

.files-table-wrap { flex: 1 1 auto; overflow: auto; }
.files-table { width: 100%; border-collapse: collapse; }
.files-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.files-table td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.45);
  font-size: 13px;
}
.files-table tr:hover td { background: rgba(30, 41, 59, 0.6); }
.file-link {
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.file-link:hover { color: var(--accent); }
.col-size { width: 100px; white-space: nowrap; color: var(--muted); }
.col-date { width: 155px; white-space: nowrap; color: var(--muted); }
.col-actions { width: 270px; white-space: nowrap; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* Terminal Tab */
.terminal-pane { background: #050a14; }
.term-stats-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
}
.term-chips {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: #0b1222;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.chip-btn {
  background: var(--card);
  color: #cbd5e1;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { border-color: var(--accent); color: #fff; }
.term-output {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.term-cmd-line { color: #38bdf8; margin-top: 8px; font-weight: 600; }
.term-err { color: #fca5a5; }
.term-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.term-prompt {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #38bdf8;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.term-input {
  flex: 1 1 auto;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-wide { max-width: 900px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.preview-body img, .preview-body video { max-width: 100%; max-height: 68vh; display: block; margin: auto; }
.preview-body iframe { width: 100%; height: 68vh; border: none; background: #fff; }
.preview-editor { width: 100%; min-height: 55vh; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.toast-container {
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}
.progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0;
}
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.1s; }

@media (max-width: 780px) {
  .files-sidebar { display: none; }
  .col-date { display: none; }
}
