/* =====================================================
   Admin v3 — Componentes compartilhados
   KPI / Sparkline / PixAmount / StatusChip / Hotkey / Sheet /
   Accordion / Tabs / PageHeader / Card / Button / Input
   ===================================================== */

/* =====================================================
   Page header (substituto do AdminPageHeader em páginas reskinadas)
   ===================================================== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--s-3);
    margin-bottom: var(--s-6);
}

.page-header__title {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--fw-semibold);
    color: var(--text);
    letter-spacing: -0.01em;
    margin: 0;
}

.page-header__subtitle {
    color: var(--text-mute);
    font-size: var(--text-sm);
    margin: var(--s-1) 0 0;
}

.page-header__actions {
    display: flex;
    gap: var(--s-2);
    flex-wrap: wrap;
}

/* =====================================================
   Card (substituto de .panel)
   ===================================================== */
.card {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-5);
    box-shadow: var(--shadow-sm);
}

.card + .card {
    margin-top: var(--s-4);
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-4);
}

.card__title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--fw-semibold);
    color: var(--text);
    margin: 0;
}

.card__subtitle {
    font-size: var(--text-sm);
    color: var(--text-mute);
    margin: var(--s-1) 0 0;
}

.card__action {
    flex-shrink: 0;
}

/* =====================================================
   Button (substituto de .btn / .admin-btn)
   ===================================================== */
.btn-v3 {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: 0 var(--s-4);
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--line-strong);
    background: var(--bg-raised);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--t-fast) var(--ease-out),
                border-color var(--t-fast) var(--ease-out),
                color var(--t-fast) var(--ease-out);
    line-height: 1;
}

.btn-v3:hover {
    background: var(--bg-hover);
    border-color: var(--line-strong);
}

.btn-v3:disabled,
.btn-v3[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-v3--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
}

.btn-v3--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-v3--ok {
    background: var(--ok-soft);
    border-color: transparent;
    color: var(--ok);
}

.btn-v3--ok:hover {
    background: var(--ok);
    color: var(--text-on-accent);
}

.btn-v3--bad {
    background: var(--bad-soft);
    border-color: transparent;
    color: var(--bad);
}

.btn-v3--bad:hover {
    background: var(--bad);
    color: var(--text-on-accent);
}

.btn-v3--ghost {
    background: transparent;
    border-color: var(--line);
}

.btn-v3--ghost:hover {
    background: var(--bg-hover);
}

.btn-v3--lg {
    height: 44px;
    padding: 0 var(--s-5);
    font-size: var(--text-md);
}

.btn-v3--xl {
    height: 56px;
    padding: 0 var(--s-6);
    font-size: var(--text-md);
    font-weight: var(--fw-semibold);
}

.btn-v3--sm {
    height: 28px;
    padding: 0 var(--s-3);
    font-size: var(--text-xs);
}

@media (max-width: 767px) {
    .btn-v3 {
        height: 44px; /* hit target mobile */
    }
    .btn-v3--sm {
        height: 36px;
    }
}

/* =====================================================
   Input
   ===================================================== */
.input-v3 {
    display: inline-flex;
    width: 100%;
    height: 36px;
    padding: 0 var(--s-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    background: var(--bg-raised);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    transition: border-color var(--t-fast) var(--ease-out),
                box-shadow var(--t-fast) var(--ease-out);
    align-items: center;
}

.input-v3::placeholder {
    color: var(--text-faint);
}

.input-v3:focus-visible {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-v3:disabled {
    background: var(--bg-sunken);
    color: var(--text-faint);
    cursor: not-allowed;
}

@media (max-width: 767px) {
    .input-v3 {
        height: 44px;
        font-size: var(--text-md); /* evita zoom iOS */
    }
}

.field-label {
    display: block;
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s-1);
}

/* =====================================================
   KPI card
   ===================================================== */
.kpi {
    container-type: inline-size;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-4);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: var(--s-1);
    min-width: 0;
}

.kpi__label {
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-mute);
    font-weight: var(--fw-semibold);
    margin: 0;
}

.kpi__value {
    font-size: var(--text-2xl);
    font-weight: var(--fw-bold);
    color: var(--text);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
    margin: 0;
}

@container (min-width: 240px) {
    .kpi__value {
        font-size: var(--text-3xl);
    }
}

.kpi__delta {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    font-size: var(--text-xs);
    font-weight: var(--fw-medium);
    margin: 0;
}

.kpi__delta--up { color: var(--ok); }
.kpi__delta--down { color: var(--bad); }

.kpi__delta-arrow {
    font-size: 9px;
    line-height: 1;
}

.kpi__delta-caption {
    font-weight: var(--fw-regular);
}

.kpi__hint {
    margin-top: var(--s-2);
    color: var(--text-mute);
    font-size: var(--text-xs);
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

/* Tons */
.kpi--pix .kpi__value { color: var(--pix); }
.kpi--accent .kpi__value { color: var(--accent); }
.kpi--warn .kpi__value { color: var(--warn); }
.kpi--bad .kpi__value { color: var(--bad); }

/* Grid utilitário para KPIs em página */
.kpi-grid-v3 {
    display: grid;
    gap: var(--s-3);
    grid-template-columns: 1fr;
}

@media (min-width: 600px) {
    .kpi-grid-v3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .kpi-grid-v3 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* =====================================================
   Sparkline
   ===================================================== */
.sparkline {
    display: inline-block;
    vertical-align: middle;
    color: var(--accent);
}

.sparkline--ok { color: var(--ok); }
.sparkline--warn { color: var(--warn); }
.sparkline--bad { color: var(--bad); }
.sparkline--pix { color: var(--pix); }

/* =====================================================
   PixAmount
   ===================================================== */
.pix-amount {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    color: var(--pix);
    font-weight: var(--fw-semibold);
}

.pix-amount.is-strong {
    color: var(--pix);
    font-weight: var(--fw-bold);
}

.pix-amount__icon {
    color: var(--pix);
    flex-shrink: 0;
}

/* =====================================================
   StatusChip
   ===================================================== */
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: 2px var(--s-2);
    border-radius: var(--r-pill);
    font-size: var(--text-2xs);
    font-weight: var(--fw-semibold);
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-chip__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-chip--neutral { background: var(--bg-active); color: var(--text-mute); }
.status-chip--ok      { background: var(--ok-soft); color: var(--ok); }
.status-chip--warn    { background: var(--warn-soft); color: var(--warn); }
.status-chip--bad     { background: var(--bad-soft); color: var(--bad); }
.status-chip--info    { background: var(--info-soft); color: var(--info); }
.status-chip--accent  { background: var(--accent-soft); color: var(--accent); }
.status-chip--pix     { background: var(--pix-soft); color: var(--pix); }
.status-chip--terra   { background: var(--terra-soft); color: var(--terra); }

.status-chip.is-strong {
    color: var(--text-on-accent);
}
.status-chip.is-strong.status-chip--ok      { background: var(--ok); }
.status-chip.is-strong.status-chip--warn    { background: var(--warn); }
.status-chip.is-strong.status-chip--bad     { background: var(--bad); }
.status-chip.is-strong.status-chip--info    { background: var(--info); }
.status-chip.is-strong.status-chip--accent  { background: var(--accent); color: var(--accent-fg); }
.status-chip.is-strong.status-chip--pix     { background: var(--pix); }

/* =====================================================
   Hotkey badge
   ===================================================== */
.hotkey {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    font-size: var(--text-2xs);
    color: var(--text-mute);
}

.hotkey__key {
    background: var(--bg-active);
    color: var(--text-mute);
    border: 1px solid var(--line);
    padding: 1px 6px;
    border-radius: var(--r-xs);
    font-size: var(--text-2xs);
    font-weight: var(--fw-semibold);
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
}

.hotkey__label {
    font-weight: var(--fw-regular);
}

/* =====================================================
   Bottom sheet
   ===================================================== */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 12, 0.5);
    backdrop-filter: blur(2px);
    z-index: var(--z-overlay);
    border: none;
    cursor: pointer;
    animation: sheet-fade var(--t-fast) var(--ease-out);
}

@keyframes sheet-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sheet {
    position: fixed;
    z-index: calc(var(--z-overlay) + 1);
    background: var(--bg-raised);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: sheet-rise var(--t-base) var(--ease-out);
}

@keyframes sheet-rise {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (max-width: 767px) {
    .sheet {
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 90dvh;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

@media (min-width: 768px) {
    .sheet {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 92%;
        max-width: 480px;
        max-height: 80dvh;
        border-radius: var(--r-lg);
        animation: sheet-fade-down var(--t-fast) var(--ease-out);
    }

    @keyframes sheet-fade-down {
        from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
        to { opacity: 1; transform: translate(-50%, -50%); }
    }
}

.sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-4);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.sheet__title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--fw-semibold);
    color: var(--text);
    margin: 0;
}

.sheet__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--s-4);
    min-height: 0;
}

.sheet__footer {
    display: flex;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-4);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

/* =====================================================
   Accordion
   ===================================================== */
.accordion {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}

.accordion-item {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.accordion-item__summary {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-4);
    cursor: pointer;
    list-style: none;
    user-select: none;
    min-height: 48px;
}

.accordion-item__summary::-webkit-details-marker {
    display: none;
}

.accordion-item__title {
    flex: 1 1 auto;
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--fw-semibold);
    color: var(--text);
    min-width: 0;
}

.accordion-item__hint {
    font-size: var(--text-xs);
    flex-shrink: 0;
}

.accordion-item__chevron {
    color: var(--text-mute);
    flex-shrink: 0;
    transition: transform var(--t-fast) var(--ease-out);
}

.accordion-item[open] .accordion-item__chevron {
    transform: rotate(180deg);
}

.accordion-item__body {
    padding: 0 var(--s-4) var(--s-4);
    border-top: 1px solid var(--line);
    padding-top: var(--s-4);
}

/* Variante: mobile-only — em ≥768px, esconde resumo, mostra tudo aberto */
@media (min-width: 768px) {
    .accordion--mobile-only .accordion-item {
        border: none;
        background: transparent;
        border-radius: 0;
    }
    .accordion--mobile-only .accordion-item__summary {
        display: none;
    }
    .accordion--mobile-only .accordion-item__body {
        padding: 0;
        border-top: none;
    }
}

/* =====================================================
   Tabs
   ===================================================== */
.tabs {
    display: flex;
    gap: var(--s-2);
    border-bottom: 1px solid var(--line);
    margin-bottom: var(--s-5);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-1);
    background: transparent;
    border: none;
    color: var(--text-mute);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    min-height: 44px;
    transition: color var(--t-fast) var(--ease-out);
}

.tabs__tab:hover {
    color: var(--text);
}

.tabs__tab.is-active {
    color: var(--accent);
}

.tabs__tab.is-active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.tabs__count {
    background: var(--bg-active);
    color: var(--text-mute);
    padding: 1px var(--s-2);
    border-radius: var(--r-pill);
    font-size: var(--text-2xs);
}

.tabs__tab.is-active .tabs__count {
    background: var(--accent-soft);
    color: var(--accent);
}

/* =====================================================
   Sticky action bar (mobile)
   ===================================================== */
.sticky-actions {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-4);
    padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom));
    background: var(--bg-topbar);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    z-index: var(--z-sticky);
    margin: 0 calc(-1 * var(--s-4));
    margin-top: var(--s-5);
}

.sticky-actions > * {
    flex: 1 1 auto;
}

@media (min-width: 768px) {
    .sticky-actions {
        position: static;
        background: transparent;
        backdrop-filter: none;
        border-top: none;
        padding: 0;
        margin: 0;
    }
    .sticky-actions > * {
        flex: 0 1 auto;
    }
}

/* =====================================================
   States: loading / empty / error
   ===================================================== */
.state-block {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-7) var(--s-4);
    text-align: center;
    color: var(--text-mute);
}

.state-block__title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--fw-semibold);
    color: var(--text);
    margin: 0 0 var(--s-1);
}

.state-block--loading {
    background: var(--bg-sunken);
    animation: state-pulse 1.4s linear infinite;
}

@keyframes state-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
    .state-block--loading { animation: none; opacity: 0.85; }
}

.state-block--error {
    background: var(--bad-soft);
    border-color: var(--bad);
    color: var(--bad);
}
