* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  color: #0f172a;
  background: radial-gradient(1200px 800px at 20% 0%, #eef2ff 0%, #ffffff 40%) fixed;
  -webkit-tap-highlight-color: transparent;
}

/* Layout */
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }
.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.sub { margin: 4px 0 0; color: #475569; font-size: 14px; }

.status {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; background: rgba(255,255,255,0.7);
  border: 1px solid rgba(148,163,184,0.35); border-radius: 10px;
  backdrop-filter: blur(8px); font-size: 13px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; flex-shrink: 0; }
.dot--ok { background: #22c55e; }
.dot--warn { background: #f59e0b; }
.dot--bad { background: #ef4444; }
.versionBadge { margin-left: 4px; font-size: 11px; color: #64748b; }

/* Cards */
.card {
  background: rgba(255,255,255,0.88);
  border: 1px solid rgba(148,163,184,0.3);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 8px 30px rgba(15,23,42,0.05);
}

/* Input area */
.label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.textarea {
  width: 100%; resize: vertical;
  border-radius: 10px; border: 1px solid rgba(148,163,184,0.45);
  padding: 12px; font-size: 15px; line-height: 1.4; background: #fff;
}
.textarea:focus { outline: 3px solid rgba(99,102,241,0.18); border-color: rgba(99,102,241,0.6); }

/* Button rows */
.btnRow {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; flex-wrap: wrap;
}
.btnGroup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btnRow > .btnGroup:last-child { margin-left: auto; }

.btn {
  border: 1px solid rgba(148,163,184,0.55); background: #fff; color: #0f172a;
  border-radius: 10px; padding: 10px 14px;
  font-weight: 600; font-size: 14px; cursor: pointer;
  white-space: nowrap; min-height: 42px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn--primary { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn--smart {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-color: #7c3aed; color: #fff; font-weight: 700;
}
.btn--smart:hover:not(:disabled) { filter: brightness(1.06); }
.btnSmall { padding: 7px 10px; font-size: 12px; min-height: 34px; }

/* Hint bar */
.hintBar {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; flex-wrap: wrap;
  min-height: 30px;
}
.hint { color: #64748b; font-size: 13px; }
.pill {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.45); color: #334155;
  background: rgba(248,250,252,0.9); flex-shrink: 0;
}
.pill--ok { border-color: rgba(34,197,94,0.45); color: #166534; background: rgba(220,252,231,0.7); }
.pill--warn { border-color: rgba(245,158,11,0.45); color: #92400e; background: rgba(254,243,199,0.7); }
.pill--bad { border-color: rgba(239,68,68,0.45); color: #991b1b; background: rgba(254,226,226,0.7); }

/* Platform toggle */
.platformToggle {
  display: flex; gap: 0; margin: 10px 0 4px;
  background: rgba(15,23,42,0.04); border-radius: 10px;
  padding: 3px; border: 1px solid rgba(148,163,184,0.3);
}
.platformBtn {
  flex: 1; padding: 8px 14px; border: none; background: transparent;
  font-size: 13px; font-weight: 600; color: #64748b;
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
  min-height: 36px;
}
.platformBtn:hover:not(.active) { color: #334155; }
.platformBtn.active {
  background: #fff; color: #0f172a;
  box-shadow: 0 1px 3px rgba(15,23,42,0.1);
}

/* Research toggle */
.toggleLabel {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none; font-size: 13px; color: #475569;
  min-height: 42px; padding: 0 4px;
}
.toggleLabel input { display: none; }
.toggleSwitch {
  width: 36px; height: 20px; border-radius: 999px;
  background: rgba(148,163,184,0.4); position: relative;
  transition: background 0.2s; flex-shrink: 0;
}
.toggleSwitch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 999px; background: #fff;
  transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggleLabel input:checked + .toggleSwitch { background: #7c3aed; }
.toggleLabel input:checked + .toggleSwitch::after { transform: translateX(16px); }
.toggleText { font-weight: 600; }

/* Complexity badge */
.complexityBadge {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0;
}
.complexityBadge--simple { background: rgba(220,252,231,0.8); color: #166534; border: 1px solid rgba(34,197,94,0.4); }
.complexityBadge--complex { background: rgba(237,233,254,0.8); color: #5b21b6; border: 1px solid rgba(124,58,237,0.4); }

/* Card header */
.cardHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.cardHeadRight { display: flex; align-items: center; gap: 8px; }
h2 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }

/* Code output */
.pre {
  margin: 0; background: rgba(15,23,42,0.04);
  border: 1px solid rgba(148,163,184,0.3); border-radius: 10px;
  padding: 12px; overflow: auto; max-height: 400px;
  font-size: 12px; line-height: 1.4; word-break: break-word;
}

/* Tabs */
.tabBar {
  display: flex; gap: 0; margin-bottom: 12px;
  border-bottom: 1px solid rgba(148,163,184,0.3);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tabBtn {
  padding: 10px 16px; border: none; background: transparent;
  color: #64748b; font-weight: 600; font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s; white-space: nowrap;
  min-height: 42px;
}
.tabBtn:hover { color: #0f172a; }
.tabBtn.active { color: #4f46e5; border-bottom-color: #4f46e5; }

/* Tab panels */
.tabPanel { min-height: 120px; }

/* Guide list */
.guideList { margin: 0; padding: 0 0 0 24px; list-style: decimal; }
.guideList li {
  padding: 10px 0; line-height: 1.55; font-size: 14px;
  color: #1e293b; border-bottom: 1px solid rgba(148,163,184,0.12);
}
.guideList li:last-child { border-bottom: none; }

/* Collapsible panels */
.panelCard { padding: 0; }
.panelToggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px; cursor: pointer; user-select: none;
  min-height: 48px;
}
.panelToggle:hover { background: rgba(248,250,252,0.6); border-radius: 14px; }
.panelRight { display: flex; align-items: center; gap: 8px; }
.chevron {
  display: inline-block; width: 18px; height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.chevron.open { transform: rotate(180deg); }
.panelBody { padding: 0 16px 16px; }

/* Templates / saved lists */
.templates { display: grid; gap: 8px; }
.tpl {
  border: 1px solid rgba(148,163,184,0.3); border-radius: 10px;
  padding: 12px; background: rgba(255,255,255,0.7);
}
.tplTop { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tplName { font-weight: 700; font-size: 14px; }
.tplDesc { margin-top: 4px; color: #475569; font-size: 13px; line-height: 1.4; }
.tplTags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.tagPill {
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: rgba(99,102,241,0.08); color: #4338ca;
  border: 1px solid rgba(99,102,241,0.15); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.tagPill:hover { background: rgba(99,102,241,0.16); border-color: rgba(99,102,241,0.3); }
.tagPill--active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.activeTagBar {
  margin-top: 8px; padding: 6px 10px; border-radius: 8px;
  background: rgba(99,102,241,0.06); font-size: 12px; color: #475569;
  display: flex; align-items: center; gap: 8px;
}
.tagClear {
  border: none; background: transparent; color: #ef4444;
  font-weight: 700; font-size: 12px; cursor: pointer; padding: 0;
}
.tplActions { margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; }

.link {
  border: none; background: transparent; color: #4f46e5;
  font-weight: 700; cursor: pointer; padding: 4px 0; font-size: 13px;
}
.mini {
  border: 1px solid rgba(148,163,184,0.55); background: #fff; color: #0f172a;
  border-radius: 10px; padding: 8px 12px; font-weight: 700; cursor: pointer;
  font-size: 12px; min-height: 36px;
}
.mini:active { transform: scale(0.97); }

/* Filter bar */
.filterBar { margin-bottom: 10px; }
.searchInput {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(148,163,184,0.45); font-size: 14px;
  margin-bottom: 8px; min-height: 42px;
}
.searchInput:focus { outline: 2px solid rgba(99,102,241,0.4); border-color: rgba(99,102,241,0.6); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pillBtn {
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.5); background: #fff; color: #475569;
  font-size: 12px; font-weight: 600; cursor: pointer; text-transform: capitalize;
  min-height: 32px;
}
.pillBtn:hover { background: rgba(248,250,252,0.9); }
.pillBtn.active { background: #4f46e5; border-color: #4f46e5; color: #fff; }

/* n8n list */
.n8nList { display: grid; gap: 8px; }
.n8nCatBadge {
  display: inline-block; margin-left: 6px; padding: 2px 8px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; border-radius: 999px;
  background: rgba(99,102,241,0.12); color: #4338ca; vertical-align: middle;
}
.n8nTpl[data-n8n-cat="personal"] .n8nCatBadge { background: rgba(34,197,94,0.15); color: #15803d; }
.n8nTpl[data-n8n-cat="work"] .n8nCatBadge { background: rgba(59,130,246,0.15); color: #1d4ed8; }
.n8nTpl[data-n8n-cat="core"] .n8nCatBadge { background: rgba(100,116,139,0.15); color: #475569; }

/* Reference */
.refBadge { font-size: 11px; color: #22c55e; font-weight: 600; }
.refIntro { margin: 0 0 12px; font-size: 13px; color: #475569; line-height: 1.5; }
.refIntro code { font-size: 12px; background: rgba(15,23,42,0.06); padding: 2px 6px; border-radius: 6px; }
.refSection { margin-bottom: 14px; }
.refSection h3 { margin: 0 0 8px; font-size: 13px; color: #0f172a; }
.refTable { width: 100%; font-size: 12px; border-collapse: collapse; }
.refTable th, .refTable td { text-align: left; padding: 8px 10px; border-bottom: 1px solid rgba(148,163,184,0.2); }
.refTable th { color: #475569; font-weight: 600; }
.refTable code { font-size: 11px; background: rgba(15,23,42,0.06); padding: 2px 6px; border-radius: 4px; }
#appleDocsLink { display: inline-block; margin-top: 10px; font-size: 13px; }
.refMeta { margin: 0 0 10px; font-size: 12px; color: #64748b; }

/* Misc */
.count { font-weight: 400; color: #64748b; font-size: 13px; }
.emptyState { padding: 16px; text-align: center; color: #64748b; font-size: 13px; }
.tpl.hidden { display: none; }

.footer {
  margin-top: 24px; padding-top: 12px;
  border-top: 1px solid rgba(148,163,184,0.25);
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  font-size: 11px; color: #94a3b8;
}

/* ─── Mobile ─── */
@media (max-width: 600px) {
  .wrap { padding: 14px 10px 40px; }
  h1 { font-size: 20px; }
  .sub { font-size: 13px; }
  .header { flex-direction: column; gap: 8px; }
  .status { align-self: flex-start; }

  .textarea { font-size: 16px; /* prevents iOS zoom */ }

  .btnRow { gap: 6px; }
  .btnRow > .btnGroup:last-child { margin-left: 0; }
  .btnGroup { width: 100%; }
  .btnGroup .btn { flex: 1; min-width: 0; text-align: center; }
  .btnGroup .toggleLabel { flex: 0 0 auto; }

  .card { padding: 12px; border-radius: 12px; }
  .panelToggle { padding: 12px; }
  .panelBody { padding: 0 12px 12px; }

  .tabBtn { padding: 10px 12px; font-size: 13px; }
  .pre { font-size: 11px; max-height: 300px; }

  .refTable { display: block; overflow-x: auto; }
}

/* ─── n8n Multi-select & Combine ─── */
.n8nSelectLabel { display: flex; align-items: center; flex-shrink: 0; }
.n8nSelectCb { width: 16px; height: 16px; cursor: pointer; accent-color: #6366f1; }
.n8nTpl--selected { border-left: 3px solid #6366f1; background: rgba(99,102,241,0.04); }

.combineBar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; margin-bottom: 8px;
  background: rgba(99,102,241,0.06); border-radius: 8px;
  font-size: 13px;
}
.combineBar .btn { font-size: 12px; padding: 5px 12px; background: #6366f1; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.combineBar .btn:disabled { opacity: 0.5; cursor: default; }
.combineBar .link { font-size: 12px; color: #6366f1; background: none; border: none; cursor: pointer; text-decoration: underline; }

/* ─── Packs ─── */
.packsSection { margin-bottom: 12px; }
.packsHeading { font-size: 15px; font-weight: 600; margin: 0 0 8px; color: #1e293b; }
.packsList { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.packCard {
  min-width: 230px; max-width: 270px; flex-shrink: 0;
  border: 1px solid rgba(148,163,184,0.3); border-radius: 12px;
  padding: 12px; background: rgba(255,255,255,0.7);
}
.packTop { display: flex; gap: 8px; margin-bottom: 8px; }
.packEmoji { font-size: 24px; line-height: 1; }
.packName { font-weight: 600; font-size: 14px; }
.packDesc { font-size: 12px; color: #475569; margin-top: 2px; }
.packActions { display: flex; justify-content: space-between; align-items: center; }
.packTemplateCount { font-size: 12px; color: #64748b; }
.packActions .btn { font-size: 11px; padding: 4px 10px; }

/* ─── Tooltips ─── */
[data-tooltip] { position: relative; }
[data-tooltip]::before,
[data-tooltip]::after {
  position: absolute; left: 50%; z-index: 100;
  pointer-events: none; opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  transform: translateX(-50%) translateY(4px);
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 8px);
  background: #1e293b; color: #f8fafc;
  font-size: 12px; font-weight: 500; line-height: 1.4;
  padding: 6px 10px; border-radius: 8px;
  max-width: 240px; width: max-content;
  text-align: center; white-space: normal;
}
[data-tooltip]::before {
  content: '';
  bottom: calc(100% + 2px);
  border: 5px solid transparent; border-top-color: #1e293b;
}
[data-tooltip]:hover::before,
[data-tooltip]:hover::after,
[data-tooltip].tooltip-active::before,
[data-tooltip].tooltip-active::after {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
/* Bottom variant */
[data-tooltip-pos="bottom"]::after {
  bottom: auto; top: calc(100% + 8px);
}
[data-tooltip-pos="bottom"]::before {
  bottom: auto; top: calc(100% + 2px);
  border-top-color: transparent; border-bottom-color: #1e293b;
}
/* Mobile: disable hover, use tap */
@media (hover: none) {
  [data-tooltip]:hover::before,
  [data-tooltip]:hover::after { opacity: 0; }
  [data-tooltip].tooltip-active::before,
  [data-tooltip].tooltip-active::after { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Getting Started ─── */
.gettingStarted { border-left: 3px solid #6366f1; }
.gettingStarted .panelBody { padding-bottom: 20px; }
.gsSteps { margin: 0; padding: 0 0 0 24px; list-style: decimal; }
.gsSteps li {
  padding: 6px 0; line-height: 1.5; font-size: 14px; color: #1e293b;
  border-bottom: 1px solid rgba(148,163,184,0.12);
}
.gsSteps li:last-child { border-bottom: none; }
.gsSteps strong { color: #4f46e5; }
.gsTips { margin: 14px 0 0; padding: 12px 14px; background: rgba(99,102,241,0.04); border-radius: 10px; }
.gsTips h3 { margin: 0 0 8px; font-size: 13px; color: #4f46e5; }
.gsTips ul { margin: 0; padding: 0 0 0 18px; list-style: disc; }
.gsTips li { padding: 3px 0; font-size: 13px; color: #475569; line-height: 1.45; }

/* ─── Workflow Visualizer ─── */
.wfVisual {
  position: relative;
  padding-left: 28px;
  margin-bottom: 12px;
}
.wfVisual::before {
  content: '';
  position: absolute; left: 8px; top: 0; bottom: 0;
  width: 3px; border-radius: 3px;
  background: linear-gradient(180deg, #6366f1 0%, #8b5cf6 50%, #c4b5fd 100%);
}
.wfNode {
  position: relative;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(148,163,184,0.3);
  border-left: 3px solid #8b5cf6;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  backdrop-filter: blur(6px);
  opacity: 0;
  animation: wfNodeFadeIn 0.4s ease forwards;
}
.wfNode--trigger { border-left-color: #6366f1; }
.wfNode--action { border-left-color: #8b5cf6; }
.wfNode--end { border-left-color: #c4b5fd; }
.wfNodeHeader { display: flex; align-items: center; gap: 6px; }
.wfNodeIcon { font-size: 16px; line-height: 1; flex-shrink: 0; }
.wfNodeLabel { font-weight: 700; font-size: 13px; color: #1e293b; }
.wfNodeType { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 0.03em; margin-left: auto; }
.wfNodeParams {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px;
  margin-top: 6px; font-size: 12px;
}
.wfParamKey { color: #64748b; font-weight: 600; }
.wfParamVal { color: #334155; word-break: break-word; }
.wfEndDot {
  width: 10px; height: 10px; border-radius: 999px;
  background: #c4b5fd; margin: 4px 0 0 -14px;
  position: relative;
}
@keyframes wfNodeFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.jsonDetails { margin-top: 4px; }
.jsonToggle {
  cursor: pointer; font-size: 12px; color: #64748b;
  padding: 6px 0; user-select: none; list-style: none;
}
.jsonToggle::-webkit-details-marker { display: none; }
.jsonToggle::before {
  content: '\25b6'; display: inline-block; margin-right: 6px;
  font-size: 10px; transition: transform 0.2s;
}
details[open] > .jsonToggle::before { transform: rotate(90deg); }

/* ─── Wide screens ─── */
@media (min-width: 900px) {
  .wrap { max-width: 860px; }
}
