/*
 * Dashboard de Cobrança — visual próprio (sem Tailwind, sem build pipeline).
 * Regras de layout/tipografia ficam aninhadas sob .gc-billing-dashboard para não vazar
 * para as outras telas do plugin (add_css do GLPI carrega este arquivo globalmente).
 * Os tokens (:root) e as classes .gc-badge* e .gc-kpi-* ficam fora do escopo de propósito:
 * também são usados na aba "Cobrança" do chamado (src/TicketCobranca.php) e na tela de
 * Serviços e Produtos (src/Catalogo.php).
 */

:root {
    --gc-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --gc-color-bg: #f8fafc;
    --gc-color-card-bg: #ffffff;
    --gc-color-border: #e2e8f0;
    --gc-color-text: #0f172a;
    --gc-color-text-muted: #64748b;
    --gc-radius-md: 10px;
    --gc-radius-lg: 14px;
    --gc-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --gc-shadow-md: 0 4px 14px rgba(15, 23, 42, .1);

    --gc-status-a-cobrar-bg: #fee2e2;
    --gc-status-a-cobrar-fg: #b91c1c;
    --gc-status-a-cobrar-border: #ef4444;
    --gc-status-orcamento-bg: #fef3c7;
    --gc-status-orcamento-fg: #92400e;
    --gc-status-coberto-bg: #dbeafe;
    --gc-status-coberto-fg: #1e40af;
    --gc-status-cobrado-bg: #d1fae5;
    --gc-status-cobrado-fg: #065f46;
    --gc-status-sem-vinculo-bg: #f1f5f9;
    --gc-status-sem-vinculo-fg: #475569;
    --gc-status-sem-cobranca-bg: #ede9fe;
    --gc-status-sem-cobranca-fg: #5b21b6;
    --gc-status-cobranca-externa-bg: #ccfbf1;
    --gc-status-cobranca-externa-fg: #115e59;
}

.gc-billing-dashboard {
    font-family: var(--gc-font-sans);
    color: var(--gc-color-text);
    background: var(--gc-color-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}

.gc-billing-dashboard * {
    box-sizing: border-box;
}

/* Header */

.gc-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.gc-page-header__title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gc-page-header__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--gc-radius-md);
    background: var(--gc-status-a-cobrar-bg);
    color: var(--gc-status-a-cobrar-fg);
    font-size: 1.25rem;
}

.gc-page-header__heading h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
    color: var(--gc-color-text);
}

.gc-page-header__heading p {
    margin: 2px 0 0;
    font-size: .85rem;
    color: var(--gc-color-text-muted);
}

.gc-help-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    padding: 8px 14px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--gc-color-text-muted);
    cursor: pointer;
    box-shadow: var(--gc-shadow-sm);
    transition: color .15s, border-color .15s;
}

.gc-help-btn:hover {
    color: var(--gc-color-text);
    border-color: #cbd5e1;
}

/* Help modal legend list */

.gc-help-modal-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: .85rem;
}

.gc-help-modal-list__item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.gc-help-modal-intro {
    font-size: .85rem;
    color: var(--gc-color-text-muted);
    margin-bottom: 14px;
}

/* KPI cards */

.gc-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (min-width: 640px) {
    .gc-kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .gc-kpi-grid {
        grid-template-columns: repeat(7, 1fr);
    }
}

.gc-kpi-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    box-shadow: var(--gc-shadow-sm);
    padding: 14px 16px;
    text-decoration: none !important;
    transition: transform .15s, box-shadow .15s, opacity .15s;
}

.gc-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--gc-shadow-md);
}

.gc-kpi-card--zero {
    opacity: .6;
}

.gc-kpi-card--zero:hover {
    opacity: .85;
}

.gc-kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
}

.gc-kpi-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--gc-color-text-muted);
}

.gc-kpi-meta {
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.3;
    opacity: .75;
}

.gc-kpi-card--a-cobrar {
    background: var(--gc-status-a-cobrar-bg);
    border-color: var(--gc-status-a-cobrar-border);
    box-shadow: 0 0 0 1px var(--gc-status-a-cobrar-border) inset;
    animation: gc-pulse-border 2.4s ease-in-out infinite;
}

.gc-kpi-card--a-cobrar .gc-kpi-value,
.gc-kpi-card--a-cobrar .gc-kpi-label {
    color: var(--gc-status-a-cobrar-fg);
}

@keyframes gc-pulse-border {
    0%, 100% { box-shadow: 0 0 0 1px var(--gc-status-a-cobrar-border) inset, 0 0 0 0 rgba(239, 68, 68, .35); }
    50% { box-shadow: 0 0 0 1px var(--gc-status-a-cobrar-border) inset, 0 0 0 6px rgba(239, 68, 68, 0); }
}

.gc-kpi-card--orcamento { background: var(--gc-status-orcamento-bg); }
.gc-kpi-card--orcamento .gc-kpi-value, .gc-kpi-card--orcamento .gc-kpi-label { color: var(--gc-status-orcamento-fg); }

.gc-kpi-card--coberto { background: var(--gc-status-coberto-bg); }
.gc-kpi-card--coberto .gc-kpi-value, .gc-kpi-card--coberto .gc-kpi-label { color: var(--gc-status-coberto-fg); }

.gc-kpi-card--cobrado { background: var(--gc-status-cobrado-bg); }
.gc-kpi-card--cobrado .gc-kpi-value, .gc-kpi-card--cobrado .gc-kpi-label { color: var(--gc-status-cobrado-fg); }

.gc-kpi-card--sem-vinculo { background: var(--gc-status-sem-vinculo-bg); }
.gc-kpi-card--sem-vinculo .gc-kpi-value, .gc-kpi-card--sem-vinculo .gc-kpi-label { color: var(--gc-status-sem-vinculo-fg); }

.gc-kpi-card--sem-cobranca { background: var(--gc-status-sem-cobranca-bg); }
.gc-kpi-card--sem-cobranca .gc-kpi-value, .gc-kpi-card--sem-cobranca .gc-kpi-label { color: var(--gc-status-sem-cobranca-fg); }

.gc-kpi-card--cobranca-externa { background: var(--gc-status-cobranca-externa-bg); }
.gc-kpi-card--cobranca-externa .gc-kpi-value, .gc-kpi-card--cobranca-externa .gc-kpi-label { color: var(--gc-status-cobranca-externa-fg); }

/* KPI grid variant for a fixed 4-card row (Catalogo's sync-status cards).
   Explicit breakpoints instead of auto-fit: auto-fit's column count depends on
   available container width, which collapses to 1 column too easily once the
   GLPI sidebar/content chrome eats into it. A fixed card count doesn't need
   that flexibility — mirror .gc-kpi-grid's own breakpoint approach instead. */
.gc-kpi-grid--auto {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (min-width: 640px) {
    .gc-kpi-grid--auto {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Sync-status modifiers (src/Catalogo.php) — reuse the same billing-status
   tokens by meaning (ok=green, stale=amber, never-synced=neutral), not name. */
.gc-kpi-card--sync-ok { background: var(--gc-status-cobrado-bg); }
.gc-kpi-card--sync-ok .gc-kpi-value, .gc-kpi-card--sync-ok .gc-kpi-label { color: var(--gc-status-cobrado-fg); }

.gc-kpi-card--sync-stale { background: var(--gc-status-orcamento-bg); }
.gc-kpi-card--sync-stale .gc-kpi-value, .gc-kpi-card--sync-stale .gc-kpi-label { color: var(--gc-status-orcamento-fg); }

.gc-kpi-card--sync-never { background: var(--gc-status-sem-vinculo-bg); }
.gc-kpi-card--sync-never .gc-kpi-value, .gc-kpi-card--sync-never .gc-kpi-label { color: var(--gc-status-sem-vinculo-fg); }

/* View tabs (Serviços/Produtos switcher, src/Catalogo.php) — GLPI's native
   .nav-pills renders the active pill at ~4% background opacity in this theme,
   which reads as plain colored text with no tab affordance. Segmented-control
   treatment instead, kept neutral so it doesn't compete with the amber CTAs
   (Sincronizar Agora, Pesquisar) that already own that accent color. */
.gc-view-tabs {
    display: inline-flex;
    gap: 2px;
    background: var(--gc-color-bg);
    border: 1px solid var(--gc-color-border);
    padding: 3px;
    border-radius: var(--gc-radius-md);
}

.gc-view-tabs .nav-link {
    border-radius: calc(var(--gc-radius-md) - 3px);
    font-weight: 600;
    color: var(--gc-color-text-muted);
    transition: background-color .15s, color .15s, box-shadow .15s;
}

.gc-view-tabs .nav-link:hover {
    color: var(--gc-color-text);
}

.gc-view-tabs .nav-link.active {
    background: var(--gc-color-card-bg);
    color: var(--gc-color-text);
    box-shadow: var(--gc-shadow-sm);
}

/* Filter bar */

.gc-filter-card {
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    box-shadow: var(--gc-shadow-sm);
    padding: 16px 18px;
    margin-bottom: 20px;
}

.gc-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.gc-filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.gc-filter-field label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--gc-color-text-muted);
    text-transform: uppercase;
    letter-spacing: .02em;
}

.gc-filter-field input[type="date"],
.gc-filter-field input[type="search"],
.gc-filter-field select {
    border: 1px solid var(--gc-color-border);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: .85rem;
    background: #fff;
    width: 100%;
}

.gc-filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    font-weight: 500;
    color: var(--gc-color-text);
    white-space: nowrap;
}

.gc-filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    grid-column: 1 / -1;
    justify-content: flex-end;
    padding-top: 4px;
    border-top: 1px solid var(--gc-color-border);
    margin-top: 8px;
}

.gc-clear-filters-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--gc-color-border);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: .82rem;
    color: var(--gc-color-text-muted);
    text-decoration: none;
}

.gc-clear-filters-btn:hover {
    color: var(--gc-color-text);
    border-color: #cbd5e1;
}

/* Pending-before-period banner */

.gc-pending-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--gc-status-a-cobrar-bg);
    border: 1px solid var(--gc-status-a-cobrar-border);
    color: var(--gc-status-a-cobrar-fg);
    border-radius: var(--gc-radius-md);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: .88rem;
    font-weight: 600;
}

.gc-pending-banner i {
    font-size: 1.1rem;
}

.gc-pending-banner__link {
    margin-left: auto;
    color: inherit;
    text-decoration: underline;
    white-space: nowrap;
}

.gc-pending-banner__link:hover {
    text-decoration: none;
}

/* Batch action bar */

.gc-batch-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #0f172a;
    color: #fff;
    border-radius: var(--gc-radius-md);
    padding: 10px 16px;
    margin-bottom: 14px;
    position: sticky;
    top: 8px;
    z-index: 5;
    box-shadow: var(--gc-shadow-md);
}

.gc-batch-bar--visible {
    display: flex;
    flex-wrap: wrap;
}

.gc-batch-count {
    font-size: .85rem;
    font-weight: 600;
}

.gc-batch-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.gc-batch-action {
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: .8rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
}

.gc-batch-action--no-charge { background: var(--gc-status-sem-cobranca-fg); }
.gc-batch-action--external-charge { background: #0d9488; }

/* Revisão de Clientes (src/MatchingReview.php) */

.gc-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    box-shadow: var(--gc-shadow-sm);
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: .88rem;
    color: var(--gc-color-text);
}

.gc-info-bar__meta {
    color: var(--gc-color-text-muted);
    font-size: .85rem;
}

.gc-suggestions-dropdown {
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    box-shadow: var(--gc-shadow-md);
    overflow: hidden;
}

.gc-suggestions-row {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--gc-color-border);
    font-size: .85rem;
}

.gc-suggestions-row:last-child {
    border-bottom: none;
}

.gc-suggestions-row:hover,
.gc-suggestions-row:focus {
    background: var(--gc-color-bg);
}

.gc-suggestions-empty {
    padding: 8px 12px;
    color: var(--gc-color-text-muted);
    font-size: .85rem;
}

.gc-confirm-box {
    margin-top: 10px;
    padding: 12px;
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
}

.gc-confirm-box p {
    margin: 0 0 8px;
}

/* Table */

.gc-table-card {
    background: var(--gc-color-card-bg);
    border: 1px solid var(--gc-color-border);
    border-radius: var(--gc-radius-md);
    box-shadow: var(--gc-shadow-sm);
    overflow-x: auto;
}

.gc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.gc-table thead th {
    text-align: left;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .04em;
    font-weight: 700;
    color: var(--gc-color-text-muted);
    background: #f8fafc;
    padding: 10px 12px;
    border-bottom: 1px solid var(--gc-color-border);
    white-space: nowrap;
}

.gc-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.gc-table tbody tr:hover {
    background: #f8fafc;
}

.gc-table tbody tr:last-child td {
    border-bottom: none;
}

.gc-cell-title {
    display: inline-block;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.gc-cell-date {
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--gc-color-text-muted);
}

.gc-actions-cell {
    text-align: right;
    white-space: nowrap;
}

.gc-action-group {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.gc-kebab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--gc-color-text-muted);
    border-radius: 6px;
    cursor: pointer;
}

.gc-kebab-btn:hover {
    color: var(--gc-color-text);
    background: #f1f5f9;
}

/* Status badges — intencionalmente fora do escopo .gc-billing-dashboard,
   pois também são usadas em src/TicketCobranca.php (aba do chamado). */

.gc-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.6;
    white-space: nowrap;
}

.gc-badge--dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.gc-badge--a-cobrar {
    background: #fee2e2;
    color: #b91c1c;
}

.gc-badge--orcamento {
    background: #fef3c7;
    color: #92400e;
}

.gc-badge--coberto {
    background: #dbeafe;
    color: #1e40af;
}

.gc-badge--cobrado {
    background: #d1fae5;
    color: #065f46;
}

.gc-badge--sem-vinculo {
    background: #f1f5f9;
    color: #475569;
}

.gc-badge--sem-cobranca {
    background: #ede9fe;
    color: #5b21b6;
}

.gc-badge--cobranca-externa {
    background: #ccfbf1;
    color: #115e59;
}

.gc-badge--contrato {
    background: #dbeafe;
    color: #1e40af;
}

.gc-badge--avulso {
    background: #f1f5f9;
    color: #475569;
}

.gc-badge--produto {
    background: #fef3c7;
    color: #92400e;
}

.gc-badge--servico {
    background: #dbeafe;
    color: #1e40af;
}

.gc-badge--neutro {
    background: #f1f5f9;
    color: #64748b;
}

.gc-badge--pf {
    background: #fce7f3;
    color: #9d174d;
}

.gc-badge--pj {
    background: #e0e7ff;
    color: #3730a3;
}

.gc-badge--codigo {
    background: #f1f5f9;
    color: #475569;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 600;
}
