/* n8n MCP Apps — Base Styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Fallbacks if host vars aren't injected */
  --color-bg: var(--color-background-primary, #0d1117);
  --color-bg-secondary: var(--color-background-secondary, #161b22);
  --color-bg-tertiary: var(--color-background-tertiary, #21262d);
  --color-surface: #1c2128;
  --color-border: var(--color-border-default, #30363d);
  --color-text: var(--color-text-primary, #e6edf3);
  --color-text-muted: var(--color-text-secondary, #8b949e);
  --color-text-dim: var(--color-text-tertiary, #6e7681);
  --color-accent: #ff6d5a;
  --color-accent-hover: #ff8a7a;
  --color-success: #3fb950;
  --color-warning: #d29922;
  --color-error: #f85149;
  --color-info: #58a6ff;
  --color-n8n: #ff6d5a; /* n8n brand orange-red */
  --color-n8n-light: #ff8a7a;
  --font-sans: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  --font-mono: var(--font-mono, 'SF Mono', 'Fira Code', monospace);
  --radius-sm: var(--border-radius-sm, 6px);
  --radius-md: var(--border-radius-md, 10px);
  --radius-lg: var(--border-radius-lg, 16px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout primitives */
.page { padding: 20px; max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; color: var(--color-text); display: flex; align-items: center; gap: 10px; }
.page-title .icon { font-size: 26px; }
.page-subtitle { font-size: 13px; color: var(--color-text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* Card */
.card { background: var(--color-bg-secondary); border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; transition: border-color var(--transition); }
.card:hover { border-color: var(--color-n8n); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--color-border); display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* Grid */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* Stats row */
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card { flex: 1; min-width: 140px; background: var(--color-bg-secondary); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--color-text); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
.stat-card.accent .stat-value { color: var(--color-n8n); }
.stat-card.success .stat-value { color: var(--color-success); }
.stat-card.warning .stat-value { color: var(--color-warning); }
.stat-card.error .stat-value { color: var(--color-error); }

/* Badge */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge.active { background: rgba(63,185,80,0.15); color: var(--color-success); }
.badge.inactive { background: rgba(139,148,158,0.15); color: var(--color-text-muted); }
.badge.error { background: rgba(248,81,73,0.15); color: var(--color-error); }
.badge.running { background: rgba(88,166,255,0.15); color: var(--color-info); }
.badge.n8n { background: rgba(255,109,90,0.15); color: var(--color-n8n); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; transition: all var(--transition); font-family: inherit; }
.btn-primary { background: var(--color-n8n); color: white; border-color: var(--color-n8n); }
.btn-primary:hover { background: var(--color-n8n-light); }
.btn-secondary { background: var(--color-bg-tertiary); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { border-color: var(--color-text-muted); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { color: var(--color-text); background: var(--color-bg-tertiary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: rgba(248,81,73,0.15); color: var(--color-error); border-color: rgba(248,81,73,0.3); }
.btn-danger:hover { background: rgba(248,81,73,0.25); }

/* Input */
.input, .select, .textarea { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; color: var(--color-text); font-family: inherit; width: 100%; transition: border-color var(--transition); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--color-n8n); box-shadow: 0 0 0 3px rgba(255,109,90,0.15); }
.input::placeholder { color: var(--color-text-dim); }
.search-box { position: relative; }
.search-box .input { padding-left: 36px; }
.search-box .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-dim); font-size: 14px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--color-text-muted); border-bottom: 1px solid var(--color-border); background: var(--color-bg-secondary); }
td { padding: 12px 16px; border-bottom: 1px solid var(--color-border); }
tr:hover td { background: rgba(255,109,90,0.04); }

/* Node flow diagram */
.flow-container { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 16px 0; }
.flow-node { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--color-bg-tertiary); border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; white-space: nowrap; transition: all var(--transition); }
.flow-node.trigger { border-color: var(--color-n8n); background: rgba(255,109,90,0.08); }
.flow-node:hover { border-color: var(--color-n8n); transform: translateY(-1px); }
.flow-arrow { color: var(--color-text-dim); font-size: 16px; flex-shrink: 0; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--color-border); margin-bottom: 20px; }
.tab { padding: 10px 18px; font-size: 13px; font-weight: 500; color: var(--color-text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all var(--transition); background: none; border-top: none; border-left: none; border-right: none; font-family: inherit; }
.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-n8n); border-bottom-color: var(--color-n8n); }

/* Code block */
.code { font-family: var(--font-mono); font-size: 12px; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 12px 16px; overflow-x: auto; white-space: pre-wrap; line-height: 1.6; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--color-text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; color: var(--color-text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; max-width: 400px; margin: 0 auto; }

/* Spinner */
.spinner { width: 20px; height: 20px; border: 2px solid var(--color-border); border-top-color: var(--color-n8n); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 20px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; z-index: 1000; animation: slideUp 0.3s ease-out; box-shadow: var(--shadow-lg); }
.toast.success { background: var(--color-success); color: white; }
.toast.error { background: var(--color-error); color: white; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-dim); }

/* Responsive */
@media (max-width: 768px) {
  .page { padding: 12px; }
  .stats-row { flex-direction: column; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
