﻿:root {
    --bg: #14101f;
    --bg-accent: radial-gradient(120% 120% at 50% 0%, rgba(138, 43, 226, 0.25) 0%, rgba(22, 18, 33, 0.92) 55%, rgba(20, 16, 31, 1) 100%);
    --surface: rgba(27, 21, 41, 0.95);
    --surface-soft: rgba(27, 21, 41, 0.75);
    --primary: #8a2be2;
    --secondary: #00bfff;
    --danger: #dc2626;
    --text: #f8f9ff;
    --text-muted: #9aa0b7;
    --border: rgba(148, 163, 184, 0.32);
    --shadow: 0 24px 48px -28px rgba(8, 6, 18, 0.88);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Inter", Arial, sans-serif;
    background: var(--bg);
    background-image: var(--bg-accent);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(35% 35% at 10% 10%, rgba(0, 191, 255, 0.12) 0%, rgba(20, 16, 31, 0) 70%),
        radial-gradient(30% 30% at 90% 0%, rgba(138, 43, 226, 0.18) 0%, rgba(20, 16, 31, 0) 65%);
    mix-blend-mode: lighten;
    z-index: 0;
}

.app-header,
.layout,
.card,
.table-wrapper {
    position: relative;
    z-index: 1;
}

.app-header {
    text-align: center;
    padding: 3rem 1.5rem 1.5rem;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(2rem, 2.6vw, 2.6rem);
    letter-spacing: 0.05em;
}

.app-header p {
    margin: 0.75rem auto 0;
    color: var(--text-muted);
    max-width: 640px;
}

.layout {
    width: 100%;
    max-width: 1380px;
    margin: 0 auto;
    padding: 0 1.25rem 3rem;
    display: grid;
    gap: 2.5rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.75rem;
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    width: 100%;
}

.card h2 {
    margin: 0 0 1.5rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.1rem 1.4rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

label input,
label select,
label textarea {
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(20, 16, 31, 0.75);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

label input:focus,
label select:focus,
label textarea:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(0, 191, 255, 0.18);
    transform: translateY(-1px);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.form-actions {
    margin-top: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
}

button {
    border: none;
    border-radius: 10px;
    padding: 0.65rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, filter 0.18s ease;
}

button:hover {
    transform: translateY(-1px);
}

button.primary {
    background: linear-gradient(135deg, var(--primary), #9b5ffe);
    color: #fff;
    box-shadow: 0 18px 32px -22px rgba(138, 43, 226, 0.85);
}

button.secondary {
    background: rgba(148, 163, 184, 0.18);
    color: var(--text);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

button.secondary:hover {
    filter: brightness(1.05);
}

button.danger {
    background: linear-gradient(135deg, #ef4444, var(--danger));
    color: #fff;
    box-shadow: 0 15px 28px -24px rgba(220, 38, 38, 0.9);
}

/* ---------------------- Seção de contatos ---------------------- */
[hidden] {
    display: none !important;
}

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

.contacts-card h2 {
    margin: 0;
}

.contacts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.contacts-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.sort-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.controls-label {
    font-size: 0.85rem;
    color: rgba(248, 249, 255, 0.72);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chip-group {
    display: inline-flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chip-button {
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(148, 163, 184, 0.1);
    border-radius: 999px;
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.chip-button:hover {
    transform: translateY(-1px);
}

.chip-button.active {
    background: rgba(0, 191, 255, 0.2);
    border-color: rgba(0, 191, 255, 0.6);
    color: #e3f8ff;
}

.contacts-toolbar .secondary.active {
    background: rgba(148, 163, 184, 0.22);
    border-color: rgba(148, 163, 184, 0.45);
}

.filters-panel {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    background: var(--surface-soft);
    backdrop-filter: blur(10px);
    display: grid;
    gap: 0.85rem;
}

.filters-group {
    display: grid;
    gap: 0.35rem;
}

.contacts-toolbar .bulk-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    font-size: 0.85rem;
}

.contacts-toolbar .bulk-actions button {
    padding: 0.45rem 1rem;
}

.contacts-card .table-wrapper {
    overflow-x: auto;
    border-radius: calc(var(--radius) - 6px);
    border: 1px solid rgba(148, 163, 184, 0.12);
}

.contacts-card #contacts-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: rgba(20, 16, 31, 0.55);
}

.contacts-card #contacts-table thead {
    background: rgba(138, 43, 226, 0.08);
    backdrop-filter: blur(6px);
}

.contacts-card #contacts-table th,
.contacts-card #contacts-table td {
    padding: 0.85rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    text-align: left;
    vertical-align: top;
    font-size: 0.9rem;
}

.contacts-card #contacts-table th {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.75rem;
    color: rgba(248, 249, 255, 0.78);
}

.contacts-card #contacts-table tbody tr:hover {
    background: rgba(0, 191, 255, 0.06);
}

.contacts-card #contacts-table th.actions-col {
    width: 120px;
}

.contacts-card #contacts-table td.actions {
    white-space: nowrap;
    position: relative;
}

.phones {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.muted {
    color: var(--text-muted);
}

.actions-wrapper {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}

.whatsapp-wrapper {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}

.actions-toggle {
    background: rgba(148, 163, 184, 0.08);
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: var(--text);
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.whatsapp-toggle {
    background: rgba(37, 211, 102, 0.06);
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    border: 1px solid #25D366;
    color: #25D366;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.actions-toggle:hover {
    transform: translateY(-1px);
}

.actions-wrapper.open .actions-toggle {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.whatsapp-wrapper.open .whatsapp-toggle {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.actions-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: rgba(27, 21, 41, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    box-shadow: 0 12px 24px -12px rgba(10, 8, 18, 0.8);
    display: flex;
    flex-direction: column;
    min-width: 160px;
    z-index: 10;
}

.whatsapp-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: rgba(27, 21, 41, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    box-shadow: 0 12px 24px -12px rgba(10, 8, 18, 0.8);
    display: flex;
    flex-direction: column;
    min-width: 160px;
    z-index: 10;
}

.actions-menu button {
    background: transparent;
    border: none;
    padding: 0.6rem 0.85rem;
    text-align: left;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.actions-menu button:hover {
    background: rgba(0, 191, 255, 0.12);
}

.actions-menu button[data-action="delete"] {
    color: #fca5a5;
}

.actions-menu button[data-action="delete"]:hover {
    background: rgba(239, 68, 68, 0.18);
}

.empty {
    text-align: center;
    color: rgba(154, 160, 183, 0.75);
    padding: 2.5rem 1rem;
    font-style: italic;
}

/* ---------------------- Modal de edição e detalhes ---------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 31, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(1rem, 4vw, 2rem);
    z-index: 999;
}

.modal-window {
    /* maior largura para visualização retangular */
    width: min(1100px, 96vw);
    max-height: min(92vh, 100%);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 28px 48px -22px rgba(8, 6, 14, 0.95);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalEnter 0.3s ease-out;
}

@keyframes modalEnter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.28), rgba(0, 191, 255, 0.18));
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.modal-header h2 {
    font-size: 1.2rem;
    margin: 0;
}

.modal-close {
    /* tornar botão redondo com X central e branco */
    background: rgba(20, 16, 31, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #ffffff;
    font-size: 1.05rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.12s ease, transform 0.12s ease, background 0.12s ease;
}

.modal-close:hover {
    filter: brightness(1.08);
    transform: translateY(-2px);
    background: rgba(20,16,31,0.75);
}

.modal-content {
    padding: 1.25rem;
    overflow-y: auto;
    scrollbar-width: thin;
}

.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: rgba(138, 43, 226, 0.45);
    border-radius: 999px;
}

.modal {
    background: var(--surface);
    /* aumentar para layout retangular predominante em desktop */
    width: min(1100px, 96vw);
    max-height: min(92vh, 100%);
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 28px 48px -22px rgba(8, 6, 14, 0.95);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalEnter 0.3s ease-out;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.28), rgba(0, 191, 255, 0.18));
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(90vh - 4rem);
}

.edit-form {
    display: grid;
    gap: 1.1rem;
}

/* ---------------------- Modal de detalhes ---------------------- */
body.pip-open {
    overflow: hidden;
    overscroll-behavior: contain;
}

.pip-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 31, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(1rem, 4vw, 2.5rem);
    z-index: 999;
}

.pip-window {
    /* janela de detalhe/edição maior para mostrar mais campos em layout retangular */
    width: min(1100px, 96vw);
    max-height: min(88vh, 92vh);
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 28px 48px -22px rgba(8, 6, 14, 0.95);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(16px);
}

/* --- High-contrast styles for 'Ver' modal (pip-view) --- */
.pip-window.pip-view {
    /* ensure the modal surface remains dark */
    background: var(--surface);
}

.pip-window.pip-view .pip-title,
.pip-window.pip-view label {
    color: var(--text);
}

.pip-window.pip-view input[readonly],
.pip-window.pip-view textarea[readonly] {
    background: transparent;
    color: var(--text);
    border-color: rgba(148,163,184,0.14);
}

.pip-window.pip-view textarea[readonly] {
    min-height: 120px;
}

.pip-window.pip-view .pip-content {
    /* keep scroll behavior but ensure text is readable */
    color: var(--text);
}

.pip-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.1rem;
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.28), rgba(0, 191, 255, 0.18));
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.pip-title {
    font-size: 1rem;
    font-weight: 700;
    margin-right: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pip-close {
    /* round close button with white X centered */
    background: rgba(20, 16, 31, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #ffffff;
    font-size: 1.05rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.12s ease, transform 0.12s ease, background 0.12s ease;
}

.pip-close:hover {
    filter: brightness(1.08);
    transform: translateY(-2px);
    background: rgba(20,16,31,0.75);
}

.pip-content {
    padding: 1.1rem 1.2rem 1.3rem;
    overflow-y: auto;
    scrollbar-width: thin;
}

.pip-content::-webkit-scrollbar {
    width: 6px;
}

.pip-content::-webkit-scrollbar-thumb {
    background: rgba(138, 43, 226, 0.45);
    border-radius: 999px;
}

.pip-details {
    display: grid;
    gap: 0.8rem;
}

.pip-details dt {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(154, 160, 183, 0.75);
}

.pip-details dd {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text);
    white-space: pre-wrap;
}

/* ---------------------- Responsividade geral ---------------------- */
@media (max-width: 900px) {
    .layout {
        padding: 0 1rem 2.5rem;
        gap: 1.75rem;
    }

    .card {
        padding: 1.5rem;
    }

    .grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem 1.25rem;
    }

    .contacts-card #contacts-table {
        min-width: 100%;
    }

    .contacts-card #contacts-table td.actions {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 2.25rem 1rem 1rem;
    }

    .app-header h1 {
        font-size: 1.85rem;
    }

    .layout {
        padding: 0 0.85rem 2.25rem;
    }

    .grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .card {
        padding: 1.25rem;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions button {
        width: 100%;
    }

    .contacts-toolbar {
        gap: 0.5rem;
    }
}

/* ---------------------- Collapsible novo contato + FAB ---------------------- */
.collapsible {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 360ms cubic-bezier(.25,.8,.25,1), opacity 260ms ease;
}
.collapsible.expanded {
    /* large max-height to allow content to expand smoothly */
    max-height: 2200px;
    opacity: 1;
}

.fab {
    position: fixed;
    right: 20px;
    bottom: 28px;
    z-index: 1200;
    background: linear-gradient(135deg, var(--primary), #9b5ffe);
    color: #fff;
    border: none;
    padding: 0.85rem 1.05rem;
    border-radius: 999px;
    box-shadow: 0 12px 28px -10px rgba(8,6,18,0.9);
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.fab:hover {
    transform: translateY(-3px);
}
.fab:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(0,191,255,0.14);
}

@media (min-width: 900px) {
    /* On larger screens place it near the header top-right instead */
    .fab {
        right: 40px;
        bottom: auto;
        top: 18px;
    }
}

/* When the FAB is inside the header, display it inline below the paragraph */
.app-header .fab {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 1rem;
    box-shadow: none;
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
}

/* Ensure header button has good focus outline */
.app-header .fab:focus {
    outline: none;
    box-shadow: 0 0 0 6px rgba(0,191,255,0.08);
}



.form-last-contact label {
    max-width: 240px;
}

.form-row {
    margin-top: 1rem;
}

.form-event label,
.form-channel label,
.form-last-contact label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-width: 260px;
}

.form-event input,
.form-channel select,
.form-last-contact input {
    width: 100%;
}

.form-notes textarea {
    min-height: 140px;
}

/* Pagination Styles */
.pagination-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    margin-top: 1rem;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    gap: 1rem;
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-btn {
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: rgba(148, 163, 184, 0.18);
    transform: translateY(-1px);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pagination-page-btn {
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    text-align: center;
}

.pagination-page-btn:hover {
    background: rgba(148, 163, 184, 0.18);
    transform: translateY(-1px);
}

.pagination-page-btn.active {
    background: rgba(0, 191, 255, 0.2);
    border-color: rgba(0, 191, 255, 0.6);
    color: #e3f8ff;
}

.pagination-ellipsis {
    color: var(--text-muted);
    padding: 0.4rem 0.2rem;
    font-size: 0.85rem;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.pagination-size select {
    background: rgba(27, 21, 41, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .pagination-wrapper {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .pagination-controls {
        justify-content: center;
    }
    
    .pagination-info,
    .pagination-size {
        text-align: center;
    }
}
