/* Componentes — ver IDENTIDADE-VISUAL.md secao 6 */

/* ---------- Botões ---------- */
.btn-primary, .btn-ghost, .btn-outline, .btn-destructive {
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.08s ease, box-shadow 0.12s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:disabled, .btn-ghost:disabled, .btn-outline:disabled, .btn-destructive:disabled {
  opacity: 0.4;
  pointer-events: none;
}
.btn-primary {
  background: var(--color-brand);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.12);
}
.btn-primary:hover { background: var(--color-brand-hover); box-shadow: var(--shadow-brand); }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost { background: transparent; color: var(--color-subtle); }
.btn-ghost:hover { background: var(--color-panel); color: var(--color-heading); }
.btn-ghost:active { transform: scale(0.97); }

.btn-outline {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-body);
  box-shadow: var(--shadow-soft-sm);
}
.btn-outline:hover { background: var(--color-panel); border-color: var(--color-muted); }
.btn-outline:active { transform: scale(0.97); }

/* Centralizada aqui (a identidade de origem documenta a ausência disto e
   recomenda criá-la — ver SPEC.md §3) */
.btn-destructive { background: rgba(220,38,38,0.1); color: var(--color-error); }
.btn-destructive:hover { background: rgba(220,38,38,0.2); }
.btn-destructive:active { transform: scale(0.97); }

/* ---------- Input ---------- */
.input {
  width: 100%;
  padding: 6px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--color-body);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:hover { border-color: var(--color-subtle); }
.input:focus { border-color: var(--color-brand); box-shadow: var(--shadow-brand); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }
.input::placeholder { color: var(--color-muted); }
.input-error { border-color: #f87171 !important; box-shadow: 0 0 0 1px rgba(248,113,113,0.3) !important; }

/* ---------- Card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft-sm);
}
.card.clickable:hover { box-shadow: var(--shadow-soft); border-color: var(--color-subtle); cursor: pointer; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 5px;
  background: var(--color-panel);
  color: var(--color-subtle);
  border: 1px solid var(--color-border);
}

/* ---------- Shell: Topnav ---------- */
.topnav {
  height: 44px;
  background: var(--color-nav-bg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  color: #cbd5e1;
}
.topnav__brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; font-size: 13px; }
.topnav__brand svg { flex-shrink: 0; }
.topnav__logo { height: 22px; max-width: 120px; object-fit: contain; border-radius: 3px; }
.topnav__tabs { display: flex; align-items: stretch; gap: 4px; height: 100%; flex: 1; }
.topnav__tab {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 13px;
  color: #b8c4d6;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  height: 100%;
}
.topnav__tab:hover { color: #fff; }
.topnav__tab.active { color: #fff; font-weight: 500; border-bottom-color: var(--color-brand); }
.topnav__more { position: relative; color: #b8c4d6; cursor: pointer; padding: 0 8px; }
.topnav__right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.topnav__build {
  font-size: 11px;
  font-family: var(--font-geist-mono);
  color: #8a9bb8;
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 5px;
}
.topnav__user-avatar {
  width: 26px; height: 26px; border-radius: var(--radius-full);
  background: var(--color-brand);
  color: #fff; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* ---------- Shell: Sidebar ---------- */
.app-shell { display: flex; height: calc(100vh - 44px); }
.sidebar {
  width: 224px;
  background: var(--color-canvas);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  transition: width 0.15s ease;
}
.sidebar.collapsed { width: 40px; }
.sidebar__header { padding: 8px 8px 8px 12px; display: flex; align-items: center; justify-content: space-between; }
.sidebar__title { color: var(--color-subtle); text-transform: uppercase; letter-spacing: 0.05em; }
.sidebar__toggle { padding: 2px 6px; font-size: 13px; }
.sidebar.collapsed .sidebar__title, .sidebar.collapsed .sidebar__nav, .sidebar.collapsed .sidebar__footer-name { display: none; }
.sidebar.collapsed .sidebar__header { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .sidebar__footer { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .sidebar__toggle { transform: scaleX(-1); }
.sidebar__search { padding: 4px 4px 12px; }
.sidebar__results { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.sidebar__item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-md);
  font-size: 13px; color: var(--color-subtle);
  text-decoration: none; cursor: pointer;
}
.sidebar__item:hover { background: var(--color-panel); color: var(--color-heading); }
.sidebar__group { padding: 10px 12px 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--color-muted, var(--color-body)); }
.sidebar__item--sub { padding-left: 24px; }
.sidebar__item.active { background: var(--color-brand-muted); color: var(--color-brand); font-weight: 500; }
.sidebar__footer {
  border-top: 1px solid var(--color-border);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
  position: relative;
}
.sidebar__footer:hover { background: var(--color-panel); }
.sidebar__footer-avatar {
  width: 24px; height: 24px; border-radius: var(--radius-full);
  background: var(--color-brand); color: #fff;
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar__footer-name { font-size: 12px; color: var(--color-heading); flex: 1; }

.main-content { flex: 1; overflow-y: auto; padding: 24px; max-width: calc(var(--content-scale, 1) * 100%); margin-inline: auto; }

/* ---------- Dropdown genérico (menu de usuário, footer, "···") ---------- */
.dropdown {
  position: absolute;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft-lg);
  min-width: 180px;
  padding: 6px;
  z-index: 50;
}
.dropdown__item {
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--color-body);
  cursor: pointer;
}
.dropdown__item:hover { background: var(--color-panel); }
.dropdown__item.destructive { color: var(--color-error); }

/* ---------- Empty state (ver também bloco de utilitários abaixo) ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 96px 0; gap: 12px; color: var(--color-subtle); font-size: 13px;
}

.topnav__user-avatar.has-img, .sidebar__footer-avatar.has-img { background-size: cover; background-position: center; }
.dropdown__item.disabled { opacity: 0.45; cursor: not-allowed; }
.dropdown { position: fixed; }

/* ---------- Utilitários ---------- */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--color-muted); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-ghost--danger { color: var(--color-error); }
.btn-ghost--danger:hover { background: rgba(220,38,38,0.1); color: var(--color-error); }
.empty-state__icon { font-size: 28px; }
.empty-state__title { font-weight: 600; color: var(--color-heading); font-size: 14px; }
.empty-state { text-align: center; }

/* ---------- Página / cabeçalho ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-title { font-size: 20px; line-height: 28px; font-weight: 600; color: var(--color-heading); margin: 0; }
.page-sub { margin: 2px 0 0; font-size: 13px; color: var(--color-subtle); }

/* ---------- Toolbar / tabela / paginação ---------- */
.list-card { overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--color-border); flex-wrap: wrap; }
.toolbar__search { flex: 1 1 220px; max-width: 360px; }
.toolbar__filter { width: auto; min-width: 140px; }
.toolbar__count { margin-left: auto; font-size: 12px; color: var(--color-subtle); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; padding: 8px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--color-subtle); border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.table th.th-sort { cursor: pointer; user-select: none; }
.table th.th-sort:hover { color: var(--color-heading); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--color-border); color: var(--color-body); max-width: 280px; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-panel); }
.table tr.row-click { cursor: pointer; }
.td-actions { text-align: right; white-space: nowrap; width: 1%; }
.pager { display: flex; gap: 4px; justify-content: center; padding: 10px; }
.pager:empty { display: none; }
.pager__cur { background: var(--color-brand-muted); color: var(--color-brand); font-weight: 600; }
.pager__gap { padding: 3px 4px; color: var(--color-muted); }
.badge-row { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- Badges (variantes) ---------- */
.badge--success { background: rgba(22,163,74,0.12); color: var(--color-success); border-color: rgba(22,163,74,0.3); }
.badge--warning { background: rgba(217,119,6,0.12); color: var(--color-warning); border-color: rgba(217,119,6,0.3); }
.badge--error { background: rgba(220,38,38,0.1); color: var(--color-error); border-color: rgba(220,38,38,0.3); }
.badge--brand { background: var(--color-brand-muted); color: var(--color-brand); border-color: rgba(69,183,209,0.35); }

/* ---------- Skeleton ---------- */
.skeleton-wrap { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.skeleton { height: 18px; border-radius: var(--radius-sm); background: var(--color-panel); }
@keyframes pulse { 50% { opacity: .45; } }
.animate-pulse { animation: pulse 1.4s cubic-bezier(.4,0,.6,1) infinite; }

/* ---------- Formulários ---------- */
.form-card { padding: 20px; margin-bottom: 16px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--color-heading); margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field--span2 { grid-column: span 2; }
.field--span3 { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 500; color: var(--color-subtle); }
.field .req { color: var(--color-error); }
.field__hint { font-size: 11px; color: var(--color-muted); }
.field__error { font-size: 11px; color: var(--color-error); min-height: 0; }
.field.has-error .input { border-color: #f87171; box-shadow: 0 0 0 1px rgba(248,113,113,0.3); }
textarea.input { resize: vertical; font-family: inherit; }
select.input { padding-right: 24px; }
.field--check { justify-content: center; }
.check { display: inline-flex !important; align-items: center; gap: 8px; font-size: 13px !important; color: var(--color-body) !important; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--color-brand); }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; }
.perm-group { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 12px; margin-bottom: 12px; }
.perm-group__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 13px; color: var(--color-heading); }
.form-error { background: rgba(220,38,38,0.1); color: var(--color-error); border: 1px solid rgba(220,38,38,0.3); border-radius: var(--radius-md); padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }
.details-sum { cursor: pointer; font-size: 12px; color: var(--color-subtle); padding: 4px 0; }
.sticky-footer { position: sticky; bottom: -24px; margin: 0 -24px -24px; padding: 12px 24px; background: var(--color-canvas); border-top: 1px solid var(--color-border); display: flex; align-items: center; gap: 8px; z-index: 5; }
.sticky-footer .spacer { flex: 1; }
.dirty-flag { font-size: 12px; color: var(--color-warning); }
.form-narrow { max-width: calc(var(--content-scale, 1) * 100%); margin-inline: auto; }
.strength { height: 4px; border-radius: 2px; background: var(--color-panel); overflow: hidden; margin-top: 4px; }
.strength > i { display: block; height: 100%; width: 0; background: var(--color-error); transition: width .15s, background .15s; }
.autocomplete { position: relative; }
.autocomplete__list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-soft-lg); max-height: 220px; overflow-y: auto; margin-top: 2px; }
.autocomplete__item { padding: 7px 10px; font-size: 13px; cursor: pointer; }
.autocomplete__item:hover, .autocomplete__item.active { background: var(--color-panel); }
.logo-box { display: flex; align-items: center; gap: 16px; }
.logo-box__img { width: 96px; height: 96px; border: 1px dashed var(--color-border); border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--color-panel); color: var(--color-muted); font-size: 11px; text-align: center; }
.logo-box__img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 8px 12px; font-size: 13px; color: var(--color-subtle); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--color-heading); border-bottom-color: var(--color-brand); font-weight: 500; }

/* ---------- Toast ---------- */
.toast-area { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: var(--radius-lg); background: var(--color-surface); border: 1px solid var(--color-border); border-left-width: 4px; box-shadow: var(--shadow-soft-lg); font-size: 13px; color: var(--color-body); }
.toast--success { border-left-color: var(--color-success); }
.toast--error { border-left-color: var(--color-error); }
.toast--info { border-left-color: var(--color-brand); }
.toast--warning { border-left-color: var(--color-warning); }
.toast__msg { flex: 1; }
.toast__close { background: none; border: none; color: var(--color-muted); cursor: pointer; font-size: 16px; line-height: 1; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(8,12,28,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-soft-xl); }
.modal__header { padding: 16px 20px 0; }
.modal__title { margin: 0; font-size: 15px; font-weight: 600; color: var(--color-heading); }
.modal__body { padding: 12px 20px; overflow-y: auto; }
.modal__text { margin: 0; font-size: 13px; color: var(--color-body); line-height: 1.5; }
.modal__footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field--span3 { grid-column: 1 / -1; }
  .topnav { gap: 8px; padding: 0 8px; }
  .topnav__build { display: none; }
  .main-content { padding: 16px; }
  .sticky-footer { margin: 0 -16px -16px; padding: 12px 16px; bottom: -16px; }
}
@media (max-width: 600px) {
  .form-grid, .form-grid--2 { grid-template-columns: 1fr; }
  .field--span2, .field--span3 { grid-column: auto; }
  .sidebar { position: fixed; z-index: 30; height: calc(100vh - 44px); }
  .sidebar.collapsed { width: 40px; }
  .app-shell .main-content { margin-left: 40px; }
}
.back-link { font-size: 12px; color: var(--color-subtle); text-decoration: none; display: inline-block; margin-bottom: 4px; }
.back-link:hover { color: var(--color-brand); }

[hidden] { display: none !important; }
.segmented { display: inline-flex; gap: 16px; }

/* ---------- Guia do Usuário (markdown renderizado) ---------- */
.md { max-width: 860px; font-size: 14px; line-height: 1.65; color: var(--color-body); }
.md h1 { font-size: 24px; color: var(--color-heading); margin: 0 0 12px; }
.md h2 { font-size: 18px; color: var(--color-heading); margin: 32px 0 10px; padding-top: 12px; border-top: 1px solid var(--color-border); }
.md h3 { font-size: 15px; color: var(--color-heading); margin: 22px 0 8px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md a { color: var(--color-brand); }
.md img { max-width: 100%; height: auto; border: 1px solid var(--color-border); border-radius: 6px; margin: 4px 0 12px; display: block; }
.md code { font-family: var(--font-geist-mono); font-size: 12px; background: var(--color-panel); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--color-panel); padding: 12px; border-radius: var(--radius-md); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--color-brand); background: var(--color-panel); border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.md hr { border: none; border-top: 1px solid var(--color-border); margin: 24px 0; }
.md-tabela { overflow-x: auto; margin: 0 0 14px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th { text-align: left; background: var(--color-panel); color: var(--color-heading); }
.md th, .md td { padding: 7px 10px; border: 1px solid var(--color-border); vertical-align: top; }

/* ---------- Visualizador de DXF ---------- */
.dxfv { display: flex; flex-direction: column; gap: 8px; }
.dxfv__bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.dxfv__coord { margin-left: auto; font-family: var(--font-geist-mono); }
.dxfv__corpo { display: flex; gap: 10px; min-height: 420px; }
.dxfv__tela { flex: 1; min-height: 420px; height: 60vh; border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.dxfv__tela { position: relative; }
.dxfv__canvas { display: block; cursor: grab; position: absolute; left: 0; top: 0; }
.dxfv__canvas.grabbing { cursor: grabbing; }
.dxfv__camadas { width: 220px; overflow-y: auto; max-height: 60vh; border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 8px; }
.dxfv__cam { display: flex !important; gap: 6px; padding: 2px 0; font-size: 12px !important; }
.dxfv__cam .truncate { flex: 1; }
@media (max-width: 900px) { .dxfv__corpo { flex-direction: column; } .dxfv__camadas { width: auto; max-height: 160px; } }

/* ---------- Contexto de obra ---------- */
.obra-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; padding: 12px 16px; }
.obra-head__id { font-family: var(--font-geist-mono); font-size: 11px; color: var(--color-muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ws-card { position: relative; }
.ws-card__editar { position: absolute; top: 10px; right: 10px; width: 26px; height: 26px; border: 1px solid var(--color-border); border-radius: var(--radius-sm, 6px); background: var(--color-surface); color: var(--color-subtle); cursor: pointer; opacity: 0; transition: opacity .12s; }
.ws-card:hover .ws-card__editar, .ws-card__editar:focus-visible { opacity: 1; }
.stat { padding: 14px; } .stat__n { font-size: 24px; font-weight: 600; color: var(--color-heading); } .stat__l { font-size: 12px; color: var(--color-subtle); }
.totais-tabs { display: flex; gap: 4px; margin-bottom: 8px; } .totais-tabs button { padding: 3px 10px; font-size: 12px; }
.progress { height: 6px; background: var(--color-panel); border-radius: 3px; overflow: hidden; margin: 8px 0; } .progress > i { display: block; height: 100%; background: var(--color-brand); width: 0; transition: width .15s; }
.split { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; } @media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

/* ---------- Roteiros de teste ---------- */
.progresso { height: 8px; background: var(--color-border); border-radius: 4px; overflow: hidden; }
.progresso > span { display: block; height: 100%; background: var(--color-success); }
.teste-thumb { position: relative; display: inline-block; }
.teste-thumb img { height: 64px; max-width: 120px; object-fit: cover; border: 1px solid var(--color-border); border-radius: 4px; cursor: zoom-in; background: var(--color-surface); }
.teste-thumb__x { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; line-height: 14px; padding: 0; border-radius: 50%; border: 1px solid var(--color-border); background: var(--color-panel); color: var(--color-error); cursor: pointer; }
.teste-drop { border: 1px dashed var(--color-border); border-radius: 4px; padding: 10px 12px; cursor: pointer; }
.teste-drop.over, .teste-drop:focus { border-color: var(--color-brand); outline: none; }
