/* ===================== TOKENS ===================== */
:root {
    --brand-primary: #005b8f;
    --brand-primary-strong: #004a75;
    --brand-secondary: #008a4b;
    --brand-secondary-strong: #006b3a;
    --brand-accent: #c21c22;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --surface-3: #e4e8ee;

    --border: #e2e6ec;
    --border-strong: #cfd5de;

    --text: #1c222e;
    --text-muted: #556070;
    --text-subtle: #5c6675;

    --primary: var(--brand-primary);
    --primary-hover: var(--brand-primary-strong);
    --primary-soft: rgba(0, 91, 143, 0.08);
    --primary-contrast: #ffffff;

    --star: #f5b400;
    --focus-ring: 0 0 0 3px rgba(0, 91, 143, 0.35);

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-sm: 0 2px 6px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 8px 22px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 24px 48px rgba(16, 24, 40, 0.14);

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-pill: 999px;

    --fs-xs: clamp(0.72rem, 0.75rem + 0.15vw, 0.8rem);
    --fs-sm: clamp(0.82rem, 0.82rem + 0.2vw, 0.92rem);
    --fs-md: clamp(0.92rem, 0.9rem + 0.25vw, 1rem);
    --fs-lg: clamp(1.05rem, 1rem + 0.5vw, 1.25rem);
    --fs-xl: clamp(1.25rem, 1.1rem + 1vw, 1.7rem);

    --sp-1: clamp(0.25rem, 0.4vw, 0.4rem);
    --sp-2: clamp(0.5rem, 0.8vw, 0.75rem);
    --sp-3: clamp(0.75rem, 1.2vw, 1.1rem);
    --sp-4: clamp(1rem, 1.8vw, 1.5rem);
    --sp-5: clamp(1.5rem, 2.6vw, 2.25rem);

    --container-pad: clamp(1rem, 2.5vw, 2rem);
    --header-logo-h: clamp(2rem, 4.2vw, 3.5rem);
    --touch-min: 2.75rem;

    /* Fonte mono para códigos */
    --font-mono: 'SF Mono', 'Cascadia Code', 'Menlo', 'Monaco', 'Consolas',
        'Liberation Mono', 'Courier New', monospace;
}

[data-theme="dark"] {
    --bg: #0f1319;
    --surface: #171c24;
    --surface-2: #1d232c;
    --surface-3: #262d38;
    --border: #2a313c;
    --border-strong: #3a4250;

    --text: #e7ecf3;
    --text-muted: #aab4c3;
    --text-subtle: #7d8798;

    --primary: #5cb3ff;
    --primary-hover: #82c5ff;
    --primary-soft: rgba(92, 179, 255, 0.12);
    --primary-contrast: #0b1118;

    --brand-secondary: #4caf76;
    --brand-secondary-strong: #3f9463;
    --brand-accent: #ff6b70;

    --star: #ffd54f;
    --focus-ring: 0 0 0 3px rgba(92, 179, 255, 0.45);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 26px 50px rgba(0, 0, 0, 0.6);
}

/* ===================== RESET / BASE ===================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    margin: 0;
    font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    overflow-x: hidden;
    transition: background-color .25s ease, color .25s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img,
svg {
    max-width: 100%;
    display: block;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color .18s ease;
}

a:hover {
    color: var(--primary-hover);
}

button {
    font: inherit;
    touch-action: manipulation;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--r-sm);
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

.container {
    width: 100%;
    max-width: min(1320px, 94vw);
    margin-inline: auto;
    padding-inline: var(--container-pad);
}

/* ===================== MAIN ===================== */
.main-container {
    padding-block: var(--sp-4) var(--sp-5);
    flex: 1 1 auto;
    width: 100%;
}

.section-title1 {
    font-size: clamp(1.35rem, 3.5vw, 1.75rem);
    font-weight: 800;
    color: var(--text);
    letter-spacing: -.01em;
}

/* ===================== TABLE CARD ===================== */
.table-card,
.card#table {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}

.card-header.bg-primary,
.table-card-header {
    background-color: var(--primary) !important;
    color: var(--primary-contrast) !important;
    padding: var(--sp-3) var(--sp-4);
    border: none;
    border-radius: 0;
}

.card-header.bg-primary h1,
.card-header.bg-primary h2,
.card-header.bg-primary h5,
.card-header.bg-primary .card-title-h {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: .01em;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: inherit;
    line-height: 1.2;
}

.card-body {
    padding: var(--sp-3) var(--sp-4);
    background-color: var(--surface);
}

/* Search bar */
.input-group {
    display: flex;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    transition: border-color .18s, box-shadow .18s;
    width: 100%;
}

.input-group:focus-within {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.input-group-text {
    background-color: var(--surface-2);
    color: var(--text-muted);
    border: none;
    padding: 0 .85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.input-group-text.bg-primary {
    background-color: var(--primary) !important;
    color: #fff !important;
}

.form-control {
    border: none;
    padding: .7rem 1rem;
    font-size: var(--fs-sm);
    color: var(--text);
    background-color: transparent;
    min-height: var(--touch-min);
    width: 100%;
    outline: none;
}

.form-control:focus {
    outline: none;
    box-shadow: none;
}

.form-control::placeholder {
    color: var(--text-subtle);
}

/* =========================================================
   ==================== TABELA RENOVADA ====================
   ========================================================= */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: var(--border-strong);
    border-radius: 9999px;
    transition: background-color .2s;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-subtle);
}

/* ---------- Tabela base ---------- */
.table {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    --bs-table-bg: transparent;
    --bs-table-hover-bg: transparent;
}

/* ---------- CABEÇALHO ---------- */
.table thead th {
    background-color: var(--surface-2);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 0.6rem 1.5rem;
    border-bottom: 2px solid var(--primary);
    vertical-align: middle;
    white-space: nowrap;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 2;
    line-height: 1.2;
}

.table thead th:last-child {
    text-align: center;
    padding-inline: 1rem;
}

/* ---------- LINHAS ---------- */
.table tbody td {
    padding: 0.8rem 1.2rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
    color: var(--text);
    line-height: 1.45;
    position: relative;
    transition: background-color .15s ease;
}

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

/* Coluna principal (Nome / Logradouro / E-mail) */
.table tbody td:first-child {
    font-weight: 600;
    color: var(--text);
    padding-left: 1.75rem;
    position: relative;
    max-width: 34rem;
    word-break: break-word;
}

/* Barra lateral animada */
.table tbody td:first-child::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 60%;
    background-color: var(--primary);
    border-radius: 0 3px 3px 0;
    transform: translateY(-50%) scaleY(0);
    transform-origin: center;
    transition: transform .2s cubic-bezier(0.4, 0, 0.2, 1);
}

.table tbody tr:hover td:first-child::before {
    transform: translateY(-50%) scaleY(1);
}

/* Coluna secundária (Bairro / Local) */
.table tbody td:nth-child(2) {
    color: var(--text-muted);
    font-size: 1rem;
}

/* Coluna código (CEP / Telefone / Ramal) — fonte mono */
.table tbody td:nth-child(3) {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.table tbody td:nth-child(3) a {
    color: inherit;
    text-decoration: none;
    transition: color .15s ease;
}

.table tbody td:nth-child(3) a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Coluna de ações */
.table tbody td:last-child {
    text-align: center;
    padding-inline: 1rem;
    white-space: nowrap;
}

/* Hover da linha */
.table-hover tbody tr {
    transition: background-color .15s ease;
}

.table-hover tbody tr:hover {
    background-color: var(--primary-soft);
}

/* Realce sutil para colunas vazias */
.table tbody td:empty::after {
    content: '—';
    color: var(--text-subtle);
    opacity: 0.5;
}

/* ---------- BOTÕES DE AÇÃO (sort / copy / star) ---------- */
.sort-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-subtle);
    padding: 0;
    margin-left: 0.5rem;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color .18s, color .18s, border-color .18s, transform .18s;
    vertical-align: middle;
}

.sort-btn:hover {
    background-color: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
    transform: scale(1.08);
}

.sort-btn.sorted-asc {
    background-color: var(--brand-secondary);
    color: #fff;
    border-color: var(--brand-secondary);
}

.sort-btn.sorted-desc {
    background-color: var(--brand-accent);
    color: #fff;
    border-color: var(--brand-accent);
}

.sort-btn i {
    font-size: 0.75rem;
}

.favorite-header-star {
    color: var(--star) !important;
    font-size: 1rem;
}

/* Copy */
.copy-btn,
.copy-button {
    background-color: transparent;
    color: var(--text-subtle);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 0;
    cursor: pointer;
    transition: background-color .18s, color .18s, border-color .18s, transform .18s;
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.copy-btn:hover,
.copy-button:hover {
    background-color: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
    transform: scale(1.08);
}

.copy-btn.btn-success,
.copy-button.btn-success {
    background-color: var(--brand-secondary) !important;
    color: #fff !important;
    border-color: var(--brand-secondary) !important;
}

/* Star (favorito) */
.star-button,
.favorite-star {
    background: transparent;
    border: 1px solid var(--border);
    padding: 0;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-subtle);
    transition: color .18s, transform .18s, background-color .18s, border-color .18s;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.star-button:hover,
.favorite-star:hover {
    color: var(--star);
    border-color: var(--star);
    background-color: rgba(245, 180, 0, 0.08);
    transform: scale(1.08);
}

.star-button.favorited,
.favorite-star.active {
    color: var(--star);
    border-color: var(--star);
    background-color: rgba(245, 180, 0, 0.10);
}

/* ---------- SEM RESULTADOS ---------- */
#no-results td {
    padding: var(--sp-5) var(--sp-3);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    background-color: var(--surface-2);
    border-radius: var(--r-md);
    font-style: italic;
}

/* ===================== HELP BUTTON ===================== */
.help-btn {
    position: fixed;
    bottom: clamp(1rem, 4vh, 2rem);
    right: clamp(.75rem, 1.5vw, 1.5rem);
    width: clamp(2.75rem, 4vw, 3.5rem);
    height: clamp(2.75rem, 4vw, 3.5rem);
    border-radius: 50%;
    background-color: var(--brand-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 1050;
    text-decoration: none;
    transition: transform .25s, background-color .25s;
}

.help-btn svg {
    width: 55%;
    height: 55%;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.help-btn:hover {
    transform: scale(1.08) rotate(8deg);
    background-color: var(--primary);
    color: var(--primary-contrast);
}

.form-label {
    font-weight: 600;
    font-size: var(--fs-sm);
    color: var(--text);
    margin-bottom: .4rem;
    display: block;
}

.form-select {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: .65rem .9rem;
    font-size: var(--fs-sm);
    min-height: var(--touch-min);
    width: 100%;
}

.form-select:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    outline: none;
}

.alert {
    border-radius: var(--r-md);
    padding: .85rem 1rem;
    font-size: var(--fs-sm);
    border: 1px solid var(--border);
}

.alert-info {
    background-color: var(--primary-soft);
    border-color: var(--primary);
    color: var(--text);
}

.alert-light {
    background-color: var(--surface-2);
    color: var(--text);
}

.btn-secondary {
    background-color: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    font-weight: 600;
    padding: .55rem 1.1rem;
    min-height: var(--touch-min);
    transition: background-color .18s, border-color .18s;
}

.btn-secondary:hover {
    background-color: var(--surface-3);
    color: var(--text);
}

/* =========================================================
   ==================== RESPONSIVO =========================
   ========================================================= */
@media (max-width: 767px) {

    /* Esconde o cabeçalho */
    #myTable thead {
        display: none;
    }

    /* Cada linha vira um card */
    #myTable,
    #myTable tbody,
    #myTable tr,
    #myTable td {
        display: block;
        width: 100% !important;
    }

    #myTable tbody {
        padding: var(--sp-3);
        background-color: var(--surface-2);
    }

    #myTable tbody tr {
        background-color: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        margin-bottom: var(--sp-3);
        padding: var(--sp-3) var(--sp-4);
        box-shadow: var(--shadow-xs);
        transition: box-shadow .2s ease, transform .2s ease, border-left-color .2s ease;
    }

    #myTable tbody tr:last-child {
        margin-bottom: 0;
    }

    #myTable tbody tr:hover {
        box-shadow: var(--shadow-sm);
        transform: translateY(-2px);
        border-left-color: var(--brand-secondary);
    }

    /* Cada célula: label em cima, valor embaixo */
    #myTable tbody td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
        padding: 0.55rem 0;
        border-bottom: 1px dashed var(--border);
        font-size: var(--fs-sm);
        text-align: left;
        position: static;
    }

    #myTable tbody td::before {
        content: none !important;
    }

    #myTable tbody td:first-child {
        padding-left: 0;
        font-size: var(--fs-md);
        font-weight: 700;
        color: var(--primary);
    }

    #myTable tbody td:last-child {
        border-bottom: none;
        padding-top: var(--sp-3);
        align-items: flex-end;
        flex-direction: row;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    /* Rótulo da coluna em cima */
    #myTable tbody td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        display: block;
        width: 100%;
        font-weight: 700;
        color: var(--text-subtle);
        font-size: 0.66rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        margin-bottom: 0.15rem;
    }

    #no-results td {
        display: block;
        text-align: center;
        padding: var(--sp-5) var(--sp-3);
    }

    #no-results td::before {
        content: none;
    }

    /* Ações no rodapé do card */
    #myTable tbody td:last-child .copy-btn,
    #myTable tbody td:last-child .star-button,
    #myTable tbody td:last-child .copy-button {
        width: 2.5rem;
        height: 2.5rem;
    }

    .main-container {
        padding-block: var(--sp-3) var(--sp-4);
    }

    .card-body {
        padding: var(--sp-3) !important;
    }

    .card-header.bg-primary {
        padding: var(--sp-3) var(--sp-4);
    }

    .section-title1 {
        font-size: clamp(1.2rem, 5vw, 1.5rem);
    }
}

@media (max-width: 420px) {
    .site-header {
        padding-block: .55rem;
    }

    .logo {
        gap: .4rem;
    }

    .logo-prefix {
        font-size: .5rem;
        letter-spacing: .12em;
    }

    .logo-name {
        font-size: 1rem;
    }

    .header-accessibility {
        padding: .2rem;
        gap: .1rem;
    }

    .acc-btn {
        width: 2.25rem;
        height: 2.25rem;
    }

    .font-btn .letter-a {
        font-size: .72rem;
    }

    .font-btn .sign {
        font-size: .55rem;
    }

    .acc-divider {
        height: .85rem;
        margin-inline: .1rem;
    }
}

@media (hover: none) and (pointer: coarse) {
    .table-hover tbody tr:hover {
        background-color: transparent;
    }

    .table tbody tr:hover td:first-child::before {
        transform: translateY(-50%) scaleY(0);
    }

    .star-button:hover,
    .favorite-star:hover {
        transform: none;
        background-color: transparent;
    }
}

@media print {

    .help-btn,
    .sort-btn,
    .star-button,
    .copy-btn,
    .copy-button,
    .topbar,
    .header-accessibility {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
        min-height: auto;
        display: block;
    }

    .table thead th {
        background-color: #005b8f !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .site-footer {
        margin-top: 0;
    }
}

/* ===================== TOPBAR ===================== */
.topbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: nowrap;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-width: 0;
    overflow: hidden;
}

.topbar-back {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .8rem;
    border-radius: var(--r-pill);
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    font-size: var(--fs-sm);
    transition: background-color .18s, color .18s, border-color .18s, transform .18s;
    min-height: 2rem;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.topbar-back:hover {
    background-color: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}

.topbar-back i {
    font-size: .8rem;
}

@media (max-width: 480px) {
    .topbar-tag {
        display: none;
    }

    .topbar-back span {
        display: none;
    }

    .topbar-back {
        padding: .45rem;
        min-height: 2.25rem;
        min-width: 2.25rem;
        justify-content: center;
        gap: 0;
    }

    .topbar-back i {
        font-size: .9rem;
    }
}