:root {
  --orange: #F77331;
  --orange-dark: #d95f1f;
  --cream: #FFF9EB;
  --dark: #200F07;
  --white: #FFFFFF;
  --border: #ecddc0;
  --muted: #8a7a63;
  --success: #1f9d55;
  --danger: #d92d20;
  --warn: #b98900;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Poppins', -apple-system, Segoe UI, sans-serif;
  background: var(--cream);
  color: var(--dark);
}

a { color: inherit; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: var(--white);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--orange); display: inline-block; }
.sidebar .tagline { font-size: 11px; color: #c9baa4; margin-bottom: 28px; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  text-decoration: none;
  color: #e7dcc7;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); }
.sidebar nav a.active { background: var(--orange); color: var(--white); }
.sidebar .n8n-status { margin-top: auto; font-size: 11px; color: #a6987f; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar .n8n-status .pill { display: inline-flex; align-items: center; gap: 6px; }
.sidebar .n8n-status .led { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.sidebar .n8n-status .led.off { background: var(--danger); }
.sidebar .logout { color: #c9baa4; font-size: 12px; margin-top: 10px; cursor: pointer; }

.main { flex: 1; padding: 32px 40px; max-width: 1180px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 24px; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-primary { background: var(--orange); color: var(--white); }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { background: var(--white); color: var(--dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: #fdf3de; }
.btn-danger { background: var(--white); color: var(--danger); border: 1px solid #f3c8c3; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.app-card { display: flex; flex-direction: column; gap: 10px; }
.app-card-top { display: flex; align-items: center; gap: 12px; }
.app-badge {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--white); font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.app-badge-logo { background: #fff; border: 1px solid var(--border); padding: 8px; box-sizing: border-box; }
.app-badge-img { width: 100%; height: 100%; object-fit: contain; }
.app-card-title { font-weight: 600; font-size: 15px; }
.app-card-cat { font-size: 12px; color: var(--muted); }
.app-card-desc { font-size: 13px; color: #5a4d3c; line-height: 1.4; flex: 1; }
.status-chip { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; width: fit-content; }
.status-connected { background: #e6f6ea; color: var(--success); }
.status-not_connected { background: #f1e9d8; color: var(--muted); }
.status-needs_setup { background: #fdf1d6; color: var(--warn); }
.app-card-remove {
  background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1;
  cursor: pointer; padding: 2px 4px; border-radius: 6px; flex-shrink: 0;
}
.app-card-remove:hover { background: #fdf3de; color: var(--danger); }

/* ---------- Workflow cards ---------- */
.wf-card { display: flex; flex-direction: column; gap: 12px; }
.wf-flow { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.wf-flow .arrow { color: var(--muted); }
.wf-name { font-size: 15px; font-weight: 600; }
.wf-meta { font-size: 12px; color: var(--muted); }
.wf-actions { display: flex; gap: 8px; margin-top: auto; }

.toggle { position: relative; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; cursor: pointer; inset: 0; background: #d8cbb0;
  border-radius: 999px; transition: 0.15s;
}
.toggle .slider:before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: 0.15s;
}
.toggle input:checked + .slider { background: var(--success); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { background: #fbf1de; font-weight: 700; color: var(--dark); }
tr:last-child td { border-bottom: none; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.success::before { background: var(--success); }
.status-dot.error::before { background: var(--danger); }
.status-dot.running::before { background: var(--warn); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=number], input[type=time], input[type=password], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px; background: var(--white); color: var(--dark);
}
textarea { min-height: 90px; resize: vertical; }
.token-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Wizard ---------- */
.wizard-steps { display: flex; gap: 6px; margin-bottom: 24px; }
.wizard-steps .step {
  flex: 1; height: 4px; border-radius: 999px; background: #e9dcc0;
}
.wizard-steps .step.done, .wizard-steps .step.active { background: var(--orange); }
.step-panel { display: none; }
.step-panel.active { display: block; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.pick-card {
  border: 2px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer;
  background: var(--white); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.pick-card:hover { border-color: var(--orange); }
.pick-card.selected { border-color: var(--orange); background: #fff4e8; }
.pick-card .app-badge { width: 40px; height: 40px; font-size: 12px; }
.pick-card .name { font-size: 13px; font-weight: 600; }
.pick-card .cat { font-size: 11px; color: var(--muted); }
.pick-card.disabled { opacity: 0.55; cursor: not-allowed; }

.action-block { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: #fffdf6; }
.action-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

.wizard-nav { display: flex; justify-content: space-between; margin-top: 24px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .btn { margin-top: 14px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--dark); color: white;
  padding: 12px 18px; border-radius: 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  z-index: 999; max-width: 320px;
}
.toast.error { background: #7a1f18; }

.catalog-search { margin-bottom: 18px; }
.catalog-group h3 { font-size: 14px; color: var(--muted); margin: 20px 0 10px; }
.catalog-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.catalog-chip { background: var(--white); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 12px; font-family: inherit; color: var(--dark); }
.catalog-chip.clickable { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.catalog-chip.clickable:hover { background: #fdf3de; border-color: var(--orange); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--white); border-radius: 16px; padding: 40px; width: 340px; box-shadow: 0 10px 40px rgba(32,15,7,0.08); text-align: center; }
.login-card .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--orange); display: inline-block; margin-right: 6px; }
.login-card h1 { font-size: 18px; margin: 8px 0 2px; }
.login-card p { font-size: 13px; color: var(--muted); margin: 0 0 20px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 12px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; display: none; }
