:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warn: #f59e0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }
.view { width: 100%; height: 100%; display: flex; flex-direction: column; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* Buttons & Inputs */
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #334155; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }

/* Navigation Tabs & Tables */
.nav-tabs { display: flex; gap: 4px; margin-left: 14px; }
.nav-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active { color: #fff; background: var(--primary); }

.panel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel-bar h2 { font-size: 1.15rem; font-weight: 600; }

.filter-bar, .user-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.inline-field { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th, .data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { background: var(--surface-2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(59, 130, 246, 0.06); }
.badge-link { cursor: pointer; text-decoration: underline; color: #93c5fd; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.full-width { width: 100%; }

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.9rem;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select { padding: 5px 8px; font-size: 0.82rem; }

/* Login */
#login-view { align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem; color: #fff;
}
.brand-icon.sm { width: 30px; height: 30px; font-size: 0.8rem; border-radius: 7px; }
#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }

.error-msg {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Dashboard */
.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.search-input { width: 260px; }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.pill-ok { background: rgba(34, 197, 94, 0.15); color: #86efac; border-color: rgba(34, 197, 94, 0.4); }
.pill-warn { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border-color: rgba(245, 158, 11, 0.4); }

.dashboard-main { flex: 1; overflow-y: auto; padding: 24px; }
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s, transform 0.15s;
}
.agent-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.agent-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.agent-name { font-size: 1.05rem; font-weight: 600; }
.agent-meta { display: flex; flex-direction: column; gap: 4px; font-size: 0.83rem; color: var(--muted); }
.dot-online {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--success); margin-right: 6px; box-shadow: 0 0 8px var(--success);
}
.empty-state {
  max-width: 520px; margin: 80px auto; text-align: center;
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 12px; padding: 32px;
}
.empty-state h3 { margin-bottom: 10px; }
.empty-state code { background: var(--bg); padding: 2px 6px; border-radius: 4px; color: #93c5fd; }

/* Remote View */
.remote-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.remote-title { font-weight: 600; font-size: 0.92rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-pill {
  font-family: Consolas, monospace;
  font-size: 0.75rem;
  color: #cbd5e1;
  background: var(--bg);
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.canvas-stage {
  flex: 1;
  position: relative;
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
}
#remote-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: default;
  outline: none;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
}
.stream-overlay {
  position: absolute;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  padding: 14px 22px;
  border-radius: 8px;
  font-size: 0.95rem;
  pointer-events: none;
}

/* File Manager Drawer */
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(720px, 95vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.drawer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.fm-path-input { flex: 1; min-width: 180px; font-family: Consolas, monospace; font-size: 0.85rem; }
.upload-label { display: inline-flex; align-items: center; }
.fm-progress-wrap { padding: 8px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.fm-progress-text { font-size: 0.8rem; margin-bottom: 4px; color: #93c5fd; }
.fm-progress-bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.fm-progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.1s; }
.drawer-body { flex: 1; overflow-y: auto; }
.fm-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.fm-table th, .fm-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.fm-table th { background: var(--surface-2); position: sticky; top: 0; font-weight: 600; color: var(--muted); }
.fm-table tr:hover td { background: rgba(59, 130, 246, 0.08); }
.fm-name { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.fm-name.dir { color: #93c5fd; font-weight: 500; }
.fm-actions { display: flex; gap: 6px; }

/* Clipboard Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}
.modal-card {
  width: min(500px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-card textarea { margin: 14px 16px; resize: vertical; font-family: inherit; }
.modal-actions { padding: 0 16px 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid var(--primary);
  color: #e2e8f0;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.88rem;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
