/* ==========================================================================
   Componentes compartilhados: cards, métricas, botões, pílulas, formulários,
   abas, tabelas, diálogos e avisos. Usa somente tokens de tokens.css.
   ========================================================================== */

/* Cards ------------------------------------------------------------------ */
.panel, .metric, .result {
  background: var(--card); color: var(--ink);
  border: 1px solid var(--card-border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}
.panel { padding: var(--s-5); min-width: 0; }
.panel > h2 + .help, .panel > h2 + p { margin-top: var(--s-1); }
.panel > h2 + :is(form, .form-grid, .table-scroll, .comm-notice) { margin-top: var(--s-4); }

/* Métricas */
.metric { display: flex; flex-direction: column; align-items: stretch; padding: var(--s-4); text-align: left; transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
button.metric { cursor: pointer; font: inherit; }
.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-float); }
.metric-top { display: flex; justify-content: space-between; align-items: center; color: var(--subtle); font-size: 14px; }
.metric-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); font-size: 15px; }
.metric:nth-child(2) .metric-icon { background: var(--info-soft); color: var(--info); }
.metric:nth-child(3) .metric-icon { background: var(--warning-soft); color: var(--warning-ink); }
.metric:nth-child(4) .metric-icon, .metric:nth-child(5) .metric-icon { background: var(--danger-soft); color: var(--danger); }
.number { margin: var(--s-3) 0 2px; font-size: var(--fs-num); font-weight: 800; line-height: 1.1; letter-spacing: -.02em; color: var(--ink); }
.metric-label { font-size: var(--fs-md); font-weight: 600; line-height: 1.35; color: var(--ink-2); }
.metric-foot { margin-top: auto; padding-top: var(--s-2); font-size: var(--fs-xs); color: var(--subtle); }
.result { padding: var(--s-4); }
.result span { font-size: var(--fs-sm); color: var(--muted); }
.result b { display: block; margin-top: var(--s-2); font-size: 24px; font-weight: 800; letter-spacing: -.02em; }

/* Botões ------------------------------------------------------------------ */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 36px; padding: 0 var(--s-4); border: 0; border-radius: var(--r-pill);
  background: var(--accent-gradient); color: var(--on-accent); box-shadow: var(--shadow-accent);
  font-size: var(--fs-md); font-weight: 700; line-height: 1.2; text-decoration: none; white-space: nowrap;
  transition: transform .15s var(--ease), box-shadow .15s, filter .15s;
}
.button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.button:active { transform: none; }
.button:disabled { opacity: .5; filter: none; transform: none; box-shadow: none; }
.secondary-button, .button.secondary-button, button.secondary {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); box-shadow: var(--shadow-xs);
}
.secondary-button:hover { border-color: var(--accent-soft-2); color: var(--accent-ink); filter: none; }
.button.compact, .compact { min-height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.button.full, .full { width: 100%; }
.icon-button { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 var(--s-1); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--muted); font-size: 17px; }
.icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.text-button { padding: 0; border: 0; background: none; color: var(--accent-ink); font-size: var(--fs-sm); font-weight: 700; text-decoration: none; }
.text-button:hover { text-decoration: underline; }
.danger-button { color: var(--danger) !important; }

/* Pílulas / etiquetas */
.pill, .live {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent-ink); font-size: var(--fs-xs); font-weight: 700; line-height: 1.5; white-space: nowrap;
}
.live { background: var(--success-soft); color: var(--success); }
.pill.overdue { background: var(--warning-soft); color: var(--warning-ink); }

/* Formulários -------------------------------------------------------------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-md); font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  max-width: 100%; min-height: 36px; padding: 7px var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-size: var(--fs-base); font-weight: 500;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 80px; line-height: 1.5; resize: vertical; }
select { padding-right: 32px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%239b929a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:hover, select:hover, textarea:hover { border-color: var(--subtle); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; padding: 0; accent-color: var(--accent); flex: none; }
input[type=time], input[type=date] { font-variant-numeric: tabular-nums; }
input[readonly] { background: var(--surface-soft); color: var(--muted); }
[aria-invalid="true"] { border-color: var(--danger) !important; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin: 0; min-width: 0; }
legend { padding: 0 var(--s-1); font-size: var(--fs-md); font-weight: 700; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3) var(--s-4); margin: var(--s-4) 0; }
.form-grid .full, .form-grid > .wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line); flex-wrap: wrap; }
.form-actions .form-note { margin: 0; }
.form-note { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s-2); }
.help { margin-top: var(--s-2); font-size: var(--fs-sm); color: var(--muted); line-height: 1.5; font-weight: 400; }
.comm-error { margin: var(--s-2) 0; font-size: var(--fs-md); color: var(--danger); }
.comm-error:empty { display: none; }
.comm-check { display: flex; flex-direction: row; align-items: flex-start; gap: var(--s-2); }
.comm-check input { margin-top: 2px; }
.validation-error, .validation-warning, .status-strip, .comm-notice {
  margin: var(--s-2) 0; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); font-size: var(--fs-sm); line-height: 1.45;
}
.validation-error { background: var(--danger-soft); color: var(--danger); }
.validation-warning { background: var(--warning-soft); color: var(--warning-ink); }
.status-strip, .comm-notice { background: var(--surface-soft); color: var(--muted); border: 0; }
.field-validation { font-size: var(--fs-xs); color: var(--danger); }
:is(.row-actions, .crm-actions, .comm-actions) { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

/* Abas em pílula (CRM, Comunicação, Relatórios) e alternador segmentado ------ */
.comm-tabs, .report-tabs {
  display: flex; flex-wrap: wrap; gap: 2px; width: fit-content; max-width: 100%;
  margin: 0 0 var(--s-3); padding: 3px; border: 0; border-radius: var(--r-pill);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.comm-tabs :is(a, button), .report-tabs :is(a, button) {
  display: inline-flex; align-items: center; min-height: 30px; padding: 0 var(--s-4); border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--muted); font-size: var(--fs-md); font-weight: 700; text-decoration: none; white-space: nowrap; box-shadow: none;
}
.comm-tabs :is(a, button):hover, .report-tabs :is(a, button):hover { color: var(--ink); }
.comm-tabs :is(a.active, .selected, [aria-selected="true"], [aria-current="page"]),
.report-tabs :is(a.active, .selected, [aria-selected="true"], [aria-pressed="true"]) { background: var(--accent-soft); color: var(--accent-ink); }
.crm-view { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-pill); background: var(--surface-soft); border: 1px solid var(--line); }
.crm-view button { min-height: 26px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 700; }
.crm-view .selected { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-xs); }
.composer-tabs { display: flex; gap: var(--s-4); margin-bottom: var(--s-2); }
.composer-tabs button { padding: 4px 0; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }
.composer-tabs button.selected { color: var(--accent-ink); font-weight: 700; border-bottom-color: var(--accent); }

/* Configurações: abas verticais */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--gutter); align-items: start; }
.settings-tabs { position: sticky; top: calc(var(--header-h) + var(--s-2)); display: flex; flex-direction: column; gap: 2px; padding: var(--s-2); border-radius: var(--r-lg); background: var(--card); box-shadow: var(--shadow-card); }
.settings-tabs button { padding: var(--s-2) var(--s-3); min-height: 36px; border: 0; border-radius: var(--r-sm); background: transparent; text-align: left; color: var(--muted); font-size: var(--fs-base); font-weight: 600; }
.settings-tabs button:hover { background: var(--surface-soft); color: var(--ink); }
.settings-tabs button.selected { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; box-shadow: none; }

/* Tabelas ------------------------------------------------------------------ */
.table-scroll { overflow: auto; min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); text-align: left; }
th { padding: var(--s-2) var(--s-3); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--subtle); border-bottom: 1px solid var(--line); background: transparent; white-space: nowrap; }
td { padding: var(--s-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover td { background: var(--surface-soft); }
tr:last-child td { border-bottom: 0; }
.agent-name { display: flex; align-items: center; gap: var(--s-2); min-width: 130px; }

/* Estados vazios ------------------------------------------------------------- */
.empty { padding: var(--s-6) var(--s-4); text-align: center; color: var(--muted); }
.empty p { margin: var(--s-2) 0 var(--s-4); }
p.empty { padding: var(--s-5) var(--s-4); border: 1px dashed var(--line-strong); border-radius: var(--r-md); margin: var(--s-3) 0 0; }
.placeholder { min-height: 320px; display: grid; place-items: center; text-align: center; }
.placeholder > div { max-width: 480px; }
.placeholder .brand-icon { margin: 0 auto var(--s-4); }
.placeholder p { margin: var(--s-3) 0 var(--s-5); }

/* Diálogos ------------------------------------------------------------------ */
dialog { width: min(760px, calc(100vw - 32px)); max-height: 86vh; padding: var(--s-5); border: 1px solid var(--card-border); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
dialog::backdrop { background: rgba(24, 14, 20, .38); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: var(--s-3); margin: 0 0 var(--s-4); padding-bottom: var(--s-3); border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin-top: var(--s-1); }
#detail-body .empty { padding: var(--s-6); }

/* Aviso flutuante */
#toast { position: fixed; z-index: 50; left: 50%; bottom: var(--s-6); transform: translate(-50%, 8px); padding: var(--s-3) var(--s-5); border-radius: var(--r-pill); background: var(--ink); color: var(--surface); font-size: var(--fs-md); font-weight: 600; box-shadow: var(--shadow-pop); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s var(--ease); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 850px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-tabs { position: static; flex-direction: row; overflow-x: auto; border-radius: var(--r-pill); padding: 3px; }
  .settings-tabs button { white-space: nowrap; border-radius: var(--r-pill); min-height: 32px; }
}
@media (max-width: 520px) {
  .panel { padding: var(--s-4); }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .button { min-height: 40px; }
  .comm-tabs, .report-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
}
