/* ==========================================================================
   components.css — botões, campos, cards de KPI, badges, tabelas, modal,
   toasts, skeleton, tooltip, estados vazios, chips, abas e progresso
   ========================================================================== */

/* -------------------------------- Botões -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  border: 1px solid transparent; white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s, box-shadow .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn .icon { width: 17px; height: 17px; }
.btn--primary { background: var(--green-800); color: #fff; box-shadow: var(--shadow-xs); }
.btn--primary:hover { background: var(--green-700); }
.btn--lime { background: var(--lime-500); color: var(--green-950); }
.btn--lime:hover { background: var(--lime-400); }
.btn--ghost { background: var(--surface); color: var(--text-soft); border-color: var(--border); }
.btn--ghost:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn--xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; gap: 6px; }
.btn--xs .icon { width: 14px; height: 14px; }
.btn--block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  color: var(--text-soft); transition: background .15s;
}
.icon-btn:hover { background: var(--neutral-bg); color: var(--text); }

/* -------------------------------- Campos -------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1 1 150px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.field select, .field input {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); outline: none; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.field select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235F6F66' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.field select:hover, .field input:hover { border-color: var(--border-strong); }
.field select:focus, .field input:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(140, 198, 63, .25); }
.field--inline { flex-direction: row; align-items: center; gap: 8px; flex: 0 1 auto; min-width: 0; }
.field--inline > span { white-space: nowrap; }
.field--search { position: relative; flex: 2 1 240px; justify-content: flex-end; }
.field--search .icon { position: absolute; left: 12px; bottom: 10px; width: 17px; height: 17px; color: var(--text-muted); pointer-events: none; }
.field--search input { padding-left: 38px; }

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 14px; margin-bottom: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.filters--inline { padding: 0; margin: 0; background: none; border: 0; }
.filters__clear { margin-left: auto; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }

/* --------------------------- Segmented control -------------------------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--neutral-bg); border-radius: 11px; }
.seg__btn {
  height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted);
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--surface); color: var(--green-800); box-shadow: var(--shadow-sm); }
.seg--sm .seg__btn { height: 28px; padding: 0 10px; font-size: 12px; }

/* --------------------------------- Chips -------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--text-soft);
  transition: all .15s;
}
.chip span { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--neutral-bg); font-size: 11px; }
.chip:hover { border-color: var(--border-strong); }
.chip.is-active { background: var(--green-900); border-color: var(--green-900); color: #fff; }
.chip.is-active span { background: var(--lime-500); color: var(--green-950); }

/* --------------------------------- Badges ------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap; line-height: 1;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--success { background: var(--success-bg); color: var(--success); }
.badge--danger { background: var(--danger-bg); color: var(--danger); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--info { background: var(--info-bg); color: var(--info); }
.badge--neutral { background: var(--neutral-bg); color: var(--neutral); }

/* --------------------------------- KPIs --------------------------------- */
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 18px 18px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  transition: box-shadow .2s var(--ease), transform .2s var(--ease), border-color .2s;
  min-width: 0;
}
.kpi:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: var(--border-strong); }
.kpi__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kpi__label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.kpi__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none; }
.kpi__icon .icon { width: 18px; height: 18px; }
.kpi__value { font-family: var(--font-display); font-size: 25px; font-weight: 750; letter-spacing: -.02em; color: var(--text); line-height: 1.15; overflow-wrap: anywhere; }
.kpi__sub { font-size: 12.5px; color: var(--text-muted); }
.kpi__sub b { color: var(--text-soft); font-weight: 650; }
.kpi__change { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12.5px; font-weight: 650; }
.kpi__change .icon { width: 15px; height: 15px; }
.kpi__change .muted { font-weight: 500; }
.kpi__change.is-up { color: var(--success); }
.kpi__change.is-down { color: var(--danger); }
.kpi__change.is-flat { color: var(--text-muted); font-weight: 500; }

.kpi--green .kpi__icon { background: var(--green-100); color: var(--green-800); }
.kpi--lime .kpi__icon { background: var(--lime-100); color: var(--lime-600); }
.kpi--red .kpi__icon { background: var(--danger-bg); color: var(--danger); }
.kpi--amber .kpi__icon { background: var(--warning-bg); color: var(--warning); }
.kpi--blue .kpi__icon { background: var(--info-bg); color: var(--info); }
.kpi--teal .kpi__icon { background: #E0F4F2; color: #1F8A84; }
.kpi[data-kpi="faturamento"]::after {
  content: ""; position: absolute; left: 18px; right: 18px; top: 0; height: 3px; border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, var(--green-800), var(--lime-500));
}

.mini-split { display: grid; gap: 3px; margin-top: 4px; padding-top: 8px; border-top: 1px dashed var(--border); }
.mini-split li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); }
.mini-split b { margin-left: auto; color: var(--text-soft); font-weight: 650; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot--servicos { background: var(--chart-1); }
.dot--aulas { background: var(--chart-2); }
.dot--produtos { background: var(--chart-3); }

/* ------------------------------- Tooltip -------------------------------- */
.tip { position: relative; display: inline-grid; place-items: center; color: var(--text-muted); cursor: help; }
.tip .icon { width: 14px; height: 14px; opacity: .7; }
/* Balão único posicionado por JS (ui.js) e sempre mantido dentro da janela. */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 130; max-width: 260px; padding: 8px 10px; border-radius: 8px;
  background: var(--green-950); color: #fff; font-size: 12px; font-weight: 500; line-height: 1.4;
  box-shadow: var(--shadow); pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .15s, transform .15s;
}
.tooltip.is-visible { opacity: 1; transform: translateY(0); }

/* -------------------------------- Tabela -------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 11px 14px; text-align: left; white-space: nowrap; }
.table thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--text-muted);
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border);
  user-select: none;
}
.table th.is-sortable { cursor: pointer; }
.table th.is-sortable:hover { color: var(--text); }
.table th.is-sorted { color: var(--green-800); }
.table .sort-icon { width: 13px; height: 13px; margin-left: 4px; vertical-align: -2px; opacity: .45; }
.table th.is-sorted .sort-icon { opacity: 1; }
.table tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--green-50); }
.table tfoot td { background: var(--surface-2); font-weight: 700; border-top: 1px solid var(--border-strong); }
.table .is-num { text-align: right; }
.table-meta { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.days { font-weight: 650; color: var(--warning); }
.days--high { color: var(--danger); }

/* --------------------------------- Modal -------------------------------- */
.modal-root { position: fixed; inset: 0; z-index: 90; display: none; }
.modal-root.is-open { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6, 38, 26, .5); backdrop-filter: blur(2px); animation: fade-in .18s var(--ease); }
.modal {
  position: relative; display: flex; flex-direction: column; width: 100%; min-width: 0; max-height: calc(100vh - 48px);
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: modal-in .22s var(--ease);
}
.modal--md { max-width: 640px; }
.modal--lg { max-width: 1040px; }
.modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.modal__header h2 { font-size: 19px; }
.modal__subtitle { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; color: var(--text-muted); font-size: 13px; }
.modal__body { padding: 20px 22px 24px; overflow-y: auto; }

.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.details > div {
  padding: 12px 14px; background: var(--surface);
  /* linhas desenhadas pelas próprias células: sobras no fim da grade ficam brancas */
  border-top: 1px solid var(--border); border-left: 1px solid var(--border); margin: -1px 0 0 -1px;
}
.details dt { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px; }
.details dd { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }

/* --------------------------------- Toast -------------------------------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 14px 14px 16px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-lg); border-left: 4px solid var(--info); animation: toast-in .25s var(--ease);
}
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: all .2s; }
.toast__icon { width: 20px; height: 20px; margin-top: 1px; }
.toast__body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.toast__body strong { font-size: 14px; }
.toast__body span { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.toast__close { color: var(--text-muted); padding: 2px; border-radius: 6px; }
.toast__close .icon { width: 16px; height: 16px; }
.toast--success { border-left-color: var(--success); }
.toast--success .toast__icon { color: var(--success); }
.toast--error { border-left-color: var(--danger); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--info .toast__icon { color: var(--info); }

/* ------------------------------- Loading -------------------------------- */
.loading { position: fixed; inset: 0; z-index: 110; display: none; place-items: center; background: rgba(243, 246, 242, .75); backdrop-filter: blur(3px); }
.loading.is-visible { display: grid; }
.loading__box { display: flex; align-items: center; gap: 14px; padding: 18px 22px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-weight: 600; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--lime-100); border-top-color: var(--green-700); animation: spin .8s linear infinite; }

/* ------------------------------- Skeleton ------------------------------- */
.skeleton {
  border-radius: var(--radius-lg); background: linear-gradient(90deg, #E9EFEA 0%, #F5F8F5 50%, #E9EFEA 100%);
  background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton--card { height: 132px; }
.skeleton--chart { height: 300px; margin-top: 20px; }

/* ------------------------------ Empty state ----------------------------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; text-align: center; color: var(--text-muted); }
.empty__icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--green-50); color: var(--green-700); margin-bottom: 6px; }
.empty__icon .icon { width: 26px; height: 26px; }
.empty h3 { color: var(--text); }
.empty p { max-width: 420px; font-size: 13.5px; }
.empty .btn { margin-top: 10px; }

/* ------------------------------- Progresso ------------------------------ */
.progress { position: relative; height: 10px; border-radius: 999px; background: var(--neutral-bg); overflow: hidden; flex: 1; }
.progress__bar { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green-700), var(--lime-500)); transition: width .5s var(--ease); }
.progress__bar--mid { background: linear-gradient(90deg, #C99A2E, #E3C04B); }
.progress__bar--low { background: linear-gradient(90deg, #C4513B, #E88A5F); }
.progress-row { display: grid; grid-template-columns: 130px 1fr 52px; align-items: center; gap: 12px; }
.progress-row__label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.progress-row__value { text-align: right; font-weight: 700; font-size: 13px; }

/* --------------------------------- Abas --------------------------------- */
.tabs { display: flex; gap: 4px; margin: 18px 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs__btn { padding: 10px 14px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs__btn:hover { color: var(--text); }
.tabs__btn.is-active { color: var(--green-800); border-bottom-color: var(--lime-500); }

/* ------------------------------- Listas --------------------------------- */
.check-list { display: grid; gap: 10px; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; color: var(--text-soft); }
.check-list .icon { color: var(--success); margin-top: 1px; }
.warn-list { display: grid; gap: 6px; margin-top: 12px; }
.warn-list li { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--warning); }

/* ------------------------------- Animações ------------------------------ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }
