/* ── Reset & Variables ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg-card:     #1a1d27;
  --bg-hover:    #22263a;
  --border:      #2a2d3e;
  --primary:     #6c63ff;
  --primary-hover:#5a52e0;
  --success:     #22c55e;
  --error:       #ef4444;
  --warning:     #f59e0b;
  --info:        #3b82f6;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --sidebar-w:   240px;
  --topbar-h:    56px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --transition:  .18s ease;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Screens ──────────────────────────────────────────────────────── */
.screen { height: 100vh; }
.screen.hidden { display: none !important; }
.screen.active { display: flex; }

/* ── Login ────────────────────────────────────────────────────────── */
#screen-login {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, #1a1040 0%, #0f1117 70%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}
.logo-icon { font-size: 28px; }
.logo h1 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
}
.field input:focus { border-color: var(--primary); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: none;
  transition: background var(--transition), opacity var(--transition);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-hover); }
.btn-ghost    { background: transparent; color: var(--text-dim); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg-hover); color: var(--text); }
.btn-danger   { background: var(--error); color: #fff; }
.btn-full     { width: 100%; justify-content: center; }
.btn-sm       { padding: 5px 12px; font-size: 12px; }
.btn-icon     { padding: 8px; font-size: 16px; }
.btn-spinner  { font-size: 13px; }

/* ── Error / Util ─────────────────────────────────────────────────── */
.error-msg  { color: var(--error); font-size: 12px; margin-top: 8px; padding: 8px 12px; background: rgba(239,68,68,.1); border-radius: var(--radius-sm); }
.hidden     { display: none !important; }

/* ── App Layout ───────────────────────────────────────────────────── */
#screen-app { flex-direction: row; overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width var(--transition), min-width var(--transition);
  overflow: hidden;
}
#sidebar.collapsed { width: 56px; min-width: 56px; }
#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .nav-item span:last-child,
#sidebar.collapsed .user-details,
#sidebar.collapsed .btn-ghost { display: none; }
#sidebar.collapsed .nav-item { justify-content: center; padding: 12px; }
#sidebar.collapsed .user-info { justify-content: center; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.sidebar-title { overflow: hidden; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover  { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: rgba(108,99,255,.15); color: var(--primary); }
.nav-icon { font-size: 16px; min-width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  min-width: 32px;
}
.user-details { overflow: hidden; }
.user-name  { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { display: block; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main Content ─────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* Connection badge */
.connection-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.badge-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}
.connection-badge.connected    .badge-dot { background: var(--success); box-shadow: 0 0 6px var(--success); }
.connection-badge.disconnected .badge-dot { background: var(--error); }
.connection-badge.connecting   .badge-dot { background: var(--warning); animation: pulse 1s infinite; }

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

/* ── Views ────────────────────────────────────────────────────────── */
.view {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}
.view.hidden { display: none !important; }
.view.active { display: block; }

.view-header { margin-bottom: 24px; }
.view-header h2 { font-size: 22px; font-weight: 700; }
.view-subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.card-body { padding: 20px; }

/* ── Stats Grid ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon { font-size: 28px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }

/* ── Workflow Grid ────────────────────────────────────────────────── */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.workflow-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.workflow-card:hover   { border-color: var(--primary); background: var(--bg-hover); }
.workflow-card.selected { border-color: var(--primary); background: rgba(108,99,255,.1); }
.workflow-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.workflow-desc { font-size: 11px; color: var(--text-muted); }

/* ── Command Form ─────────────────────────────────────────────────── */
.param-field { margin-bottom: 16px; }
.param-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.param-field input, .param-field select, .param-field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.param-field input:focus, .param-field select:focus, .param-field textarea:focus { border-color: var(--primary); }
.param-required { color: var(--error); margin-left: 2px; }
.param-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ── Result Display ───────────────────────────────────────────────── */
.result-badge {
  font-size: 11px; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: .5px;
}
.result-badge.success { background: rgba(34,197,94,.15); color: var(--success); }
.result-badge.error   { background: rgba(239,68,68,.15);  color: var(--error); }
.result-badge.pending { background: rgba(245,158,11,.15); color: var(--warning); }
.result-badge.running { background: rgba(59,130,246,.15); color: var(--info); }

.result-message {
  font-size: 14px; color: var(--text); margin-bottom: 14px;
}
.result-data {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
}
.result-redirect {
  margin-top: 12px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
.result-redirect a { color: var(--primary); text-decoration: underline; }

/* ── Command List ─────────────────────────────────────────────────── */
.command-list, .history-list { display: flex; flex-direction: column; gap: 8px; }
.command-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}
.command-item:hover { border-color: var(--primary); }
.command-item-left { display: flex; flex-direction: column; gap: 3px; }
.command-item-id   { font-size: 11px; color: var(--text-muted); font-family: monospace; }
.command-item-wf   { font-size: 13px; font-weight: 600; }
.command-item-time { font-size: 11px; color: var(--text-muted); }
.command-item-right { display: flex; align-items: center; gap: 10px; }

/* ── History ──────────────────────────────────────────────────────── */
.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition);
}
.history-item:hover { border-color: var(--primary); }
.history-workflow { font-weight: 600; font-size: 13px; }
.history-time     { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.select-sm {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 12px; outline: none;
}

/* ── Pagination ───────────────────────────────────────────────────── */
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.page-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text-dim); border-radius: var(--radius-sm); padding: 5px 12px; font-size: 12px; cursor: pointer; }
.page-btn.active { border-color: var(--primary); color: var(--primary); }
.page-btn:hover:not(.active) { border-color: var(--text-muted); color: var(--text); }

/* ── Empty State ──────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--text-muted); padding: 32px; font-size: 13px; }

/* ── Toast ────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slideIn .2s ease;
  min-width: 260px; max-width: 380px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error); }
.toast.info    { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes slideOut { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(20px); } }

/* ── Redirect Overlay ─────────────────────────────────────────────── */
#redirect-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(4px);
}
.redirect-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 48px;
  text-align: center;
  box-shadow: var(--shadow);
}
.redirect-icon    { font-size: 40px; margin-bottom: 16px; animation: spin 1s linear infinite; }
.redirect-message { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.redirect-url     { font-size: 12px; color: var(--text-muted); }
@keyframes spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { position: fixed; z-index: 100; height: 100vh; transform: translateX(0); }
  #sidebar.mobile-hidden { transform: translateX(-100%); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .view { padding: 16px; }
}
