/* Componentes — fiéis ao Twenty CRM. Dependem de tokens.css. */

* { -webkit-font-smoothing: antialiased; box-sizing: border-box; }
[x-cloak] { display: none !important; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-secondary);
  font-size: 14px;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* ---------- Layout app ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 220px; min-width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  display: flex; flex-direction: column;
  padding: 8px 8px 16px;
}
.workspace {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 8px; border-radius: var(--radius-sm);
  cursor: default;
}
.workspace:hover { background: var(--bg-hover); }
.workspace__logo {
  width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: var(--blue); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
}
.workspace__name { font-weight: 600; font-size: 14px; color: var(--text-primary); }

.nav-section { margin-top: 12px; }
.nav-section__title {
  font-size: 11px; font-weight: 500; color: var(--text-light);
  text-transform: none; padding: 4px 8px; letter-spacing: .02em;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 8px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  text-decoration: none; transition: background .1s ease;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.is-active { background: var(--bg-hover); color: var(--text-primary); }
.nav-item svg { width: 16px; height: 16px; stroke-width: 2; color: currentColor; flex: none; }
.nav-spacer { flex: 1; }

/* Navegação por categorias + sub-itens com conector curvo (árvore) */
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.nav-group { display: flex; flex-direction: column; }
.nav-cat {
  display: flex; align-items: center; gap: 4px; width: 100%; height: 26px; padding: 0 6px;
  border: none; background: transparent; cursor: pointer; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--text-light); transition: background 0.1s ease, color 0.1s ease;
}
.nav-cat:hover { background: var(--bg-hover); color: var(--text-tertiary); }
.nav-cat__chev { width: 12px; height: 12px; stroke-width: 2.5; transition: transform 0.15s ease; flex: none; }
.nav-cat__chev.is-open { transform: rotate(90deg); }
/* 2.º nível (itens da categoria): conector curvo de árvore. */
.nav-sub { display: flex; flex-direction: column; gap: 2px; padding-left: 24px; padding-top: 2px; }
.nav-item--sub { position: relative; }
.nav-item--sub::before {
  content: ""; position: absolute; left: -13px; top: -15px; width: 11px; height: 29px;
  border-left: 1.5px solid var(--border-strong); border-bottom: 1.5px solid var(--border-strong);
  border-bottom-left-radius: 10px; pointer-events: none; opacity: 0.6;
}
.nav-item--sub.is-active::before { border-color: var(--blue); opacity: 0.5; }

/* 3.º nível (sub-itens de um item — sub-categorias): conector curvo de árvore. */
.nav-subsub { display: flex; flex-direction: column; gap: 2px; padding-left: 30px; padding-top: 2px; }
.nav-item--subsub { position: relative; }
.nav-item--subsub::before {
  content: ""; position: absolute; left: -14px; top: -15px; width: 12px; height: 29px;
  border-left: 1.5px solid var(--border-strong); border-bottom: 1.5px solid var(--border-strong);
  border-bottom-left-radius: 10px; pointer-events: none; opacity: 0.65;
}
.nav-item--subsub.is-active::before { border-color: var(--blue); opacity: 0.55; }

/* ---------- Topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-secondary); }
.topbar {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
}
.topbar__title { font-size: 14px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.topbar__title svg { width: 16px; height: 16px; stroke-width: 2; color: var(--text-tertiary); }
.content { flex: 1; overflow: auto; padding: 16px 20px; }

.avatar {
  width: 24px; height: 24px; border-radius: var(--radius-pill);
  background: var(--accent-primary); color: var(--accent-text);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.iconbtn {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: grid; place-items: center; color: var(--text-tertiary);
  background: transparent; border: none; cursor: pointer; transition: background .1s ease;
}
.iconbtn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.iconbtn svg { width: 16px; height: 16px; stroke-width: 2; }

/* ---------- Botões ---------- */
.btn {
  height: 32px; display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer;
  background: var(--bg-secondary); color: var(--text-secondary);
  transition: background .1s ease, box-shadow .1s ease; white-space: nowrap;
}
.btn:hover { background: var(--bg-tertiary); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--blue); }
.btn svg { width: 16px; height: 16px; stroke-width: 2; }
.btn--sm { height: 24px; font-size: 13px; }
.btn--blue { background: var(--blue); color: #fff; border-color: transparent; }
.btn--blue:hover { background: var(--blue-hover); }
.btn--danger { background: var(--red); color: #fff; }
.btn--secondary { background: transparent; border-color: var(--border-medium); color: var(--text-secondary); }
.btn--secondary:hover { background: var(--bg-hover); }
.btn--ghost { background: transparent; border: none; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-hover); }

/* ---------- Inputs ---------- */
.input {
  height: 32px; width: 100%; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-medium); background: var(--bg-primary);
  font-size: 14px; color: var(--text-primary); font-family: var(--font);
}
.input::placeholder { color: var(--text-light); }
.input:focus { outline: none; box-shadow: var(--focus-ring); border-color: var(--blue); }
.label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }

.search {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border-medium); border-radius: var(--radius-sm);
  background: var(--bg-primary); color: var(--text-tertiary); width: 240px;
}
.search input { border: none; outline: none; background: transparent; font-size: 14px; width: 100%; color: var(--text-primary); }
.search svg { width: 14px; height: 14px; stroke-width: 2; }
.kbd {
  font-size: 11px; color: var(--text-tertiary); border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs); padding: 0 4px; background: var(--bg-secondary);
}

/* ---------- Tags ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  background: var(--tag-bg-gray); color: var(--tag-text-gray); white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.tag--blue { background: var(--tag-bg-blue); color: var(--tag-text-blue); }
.tag--green { background: var(--tag-bg-green); color: var(--tag-text-green); }
.tag--red { background: var(--tag-bg-red); color: var(--tag-text-red); }
.tag--orange { background: var(--tag-bg-orange); color: var(--tag-text-orange); }
.tag--purple { background: var(--tag-bg-purple); color: var(--tag-text-purple); }
.tag--amber { background: var(--tag-bg-amber); color: var(--tag-text-amber); }
.tag--plain::before { display: none; }

/* ---------- Painéis / cards ---------- */
.panel { background: var(--bg-primary); border: 1px solid var(--border-light); border-radius: var(--radius-sm); }
.panel__head { padding: 9px 14px; border-bottom: 1px solid var(--border-light); font-weight: 600; font-size: 13px; color: var(--text-primary); }
.panel__body { padding: 14px; }

.kpi { background: var(--bg-primary); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 14px 16px; }
.kpi__label { font-size: 12px; color: var(--text-tertiary); display: flex; align-items: center; gap: 6px; }
.kpi__label svg { width: 14px; height: 14px; stroke-width: 2; }
.kpi__value { margin-top: 6px; font-size: 24px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.02em; }
.kpi__value.is-danger { color: var(--red); }
.kpi__value.is-blue { color: var(--blue); }

/* ---------- Tabela "record index" (densa, 32px) ---------- */
.rtable { width: 100%; border-collapse: collapse; background: var(--bg-primary);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm); overflow: hidden; }
.rtable thead th {
  height: 30px; text-align: left; padding: 0 10px; font-size: 12px; font-weight: 500;
  color: var(--text-tertiary); border-bottom: 1px solid var(--border-light); background: transparent;
}
.rtable tbody td { padding: 0 10px; }
.rtable tbody td { height: 32px; padding: 0 8px; font-size: 14px; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); }
.rtable tbody tr:last-child td { border-bottom: none; }
.rtable tbody tr:hover { background: var(--bg-hover); }
.rtable a.cell-strong { color: var(--text-primary); font-weight: 500; text-decoration: none; }
.rtable a.cell-strong:hover { color: var(--blue); }
.rtable .empty { text-align: center; color: var(--text-light); height: 80px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.kanban::-webkit-scrollbar { height: 10px; }
.kanban::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.kanban-col { width: 240px; min-width: 240px; display: flex; flex-direction: column; }
.kanban-col__head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 8px; }
.kanban-col__title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-primary); }
.kanban-col__dot { width: 8px; height: 8px; border-radius: 50%; }
.kanban-col__count { font-size: 12px; color: var(--text-tertiary); }
.kanban-col__list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.op-card {
  background: var(--bg-primary); border: 1px solid var(--border-light); border-radius: var(--radius-md);
  padding: 10px 12px; cursor: grab; transition: box-shadow .12s ease, border-color .12s ease;
}
.op-card:hover { box-shadow: var(--shadow-light); border-color: var(--border-medium); }
.op-card:active { cursor: grabbing; }
.op-card__title { font-size: 14px; font-weight: 500; color: var(--text-primary); text-decoration: none; display: block; }
.op-card__title:hover { color: var(--blue); }
.op-card__sub { margin-top: 2px; font-size: 12px; color: var(--text-tertiary); }
.op-card__foot { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; }
.op-card__amount { font-size: 13px; font-weight: 600; color: var(--text-primary); }

/* ---------- Timeline (record page) ---------- */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { position: relative; padding: 0 0 16px 18px; border-left: 1px solid var(--border-medium); }
.tl-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.tl-item__dot { position: absolute; left: -5px; top: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.tl-item__title { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.tl-item__body { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.tl-item__meta { font-size: 12px; color: var(--text-light); margin-top: 4px; }

.field-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-light); font-size: 14px; }
.field-row:last-child { border-bottom: none; }
.field-row__k { color: var(--text-tertiary); }
.field-row__v { color: var(--text-primary); font-weight: 500; }

/* Command palette (⌘K) */
.cmdk-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: grid; place-items: start center; padding-top: 13vh; z-index: 50; }
.cmdk { width: 580px; max-width: 92vw; background: var(--bg-primary); border: 1px solid var(--border-medium); border-radius: var(--radius-md); box-shadow: var(--shadow-modal); overflow: hidden; }
.cmdk__input { width: 100%; height: 50px; border: none; border-bottom: 1px solid var(--border-light); padding: 0 16px; font-size: 15px; background: transparent; color: var(--text-primary); outline: none; font-family: var(--font); }
.cmdk__list { max-height: 340px; overflow: auto; padding: 6px; }
.cmdk__group { font-size: 11px; color: var(--text-light); padding: 8px 10px 4px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.03em; }
.cmdk__item { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--text-secondary); text-decoration: none; font-size: 14px; }
.cmdk__item:hover { background: var(--bg-hover); color: var(--text-primary); }
.cmdk__item svg { width: 15px; height: 15px; stroke-width: 2; flex: none; color: var(--text-tertiary); }

/* Edição inline (folha de cálculo) */
.cell-edit { display: inline-block; min-width: 24px; padding: 1px 4px; margin: -1px -4px; border-radius: var(--radius-xs); cursor: text; }
.cell-edit:hover { background: var(--bg-hover); box-shadow: inset 0 0 0 1px var(--border-medium); }
.cell-input { width: 100%; min-width: 60px; height: 24px; padding: 0 6px; border: 1.5px solid var(--blue);
  border-radius: var(--radius-xs); font-size: 14px; font-family: var(--font); color: var(--text-primary);
  background: var(--bg-primary); outline: none; box-shadow: var(--focus-ring); }

/* HTMX */
.htmx-swapping { opacity: 0; transition: opacity .12s ease-out; }
.sortable-ghost { opacity: .35; }
.sortable-drag { transform: rotate(2deg); }
.focus-ring:focus-visible { outline: none; box-shadow: var(--focus-ring); }
