@import url('https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg:           #f0f2f5;
    --card:         #ffffff;
    --text:         #2d3748;
    --muted:        #718096;
    --border:       #e2e8f0;
    --green:        #38a169;
    --green-light:  #c6f6d5;
    --red:          #e53e3e;
    --blue:         #3182ce;
    --blue-light:   #bee3f8;
    --orange:       #dd6b20;
    --purple:       #805ad5;
    --purple-light: #e9d8fd;
    --shadow:       0 2px 8px rgba(0,0,0,0.08);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.12);
    --radius:       12px;
    --whatsapp:     #25d366;
    --whatsapp-dark:#128c7e;
}

[data-theme="dark"] {
    --bg:           #111113;
    --card:         #1a1a1e;
    --text:         #e4e4e7;
    --muted:        #a1a1aa;
    --border:       rgba(255,255,255,0.1);
    --green:        #4ade80;
    --green-light:  rgba(74,222,128,0.18);
    --red:          #f87171;
    --blue:         #60a5fa;
    --blue-light:   rgba(96,165,250,0.18);
    --orange:       #fb923c;
    --purple:       #c084fc;
    --purple-light: rgba(192,132,252,0.18);
    --shadow:       0 2px 8px rgba(0,0,0,0.35);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.5);
    --whatsapp:     #25d366;
    --whatsapp-dark:#128c7e;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

/* ── Embedded mode ───────────────────────────── */
body.embedded .page-header { display: none; }
body.embedded { min-height: auto; }
body.embedded .main { padding-top: 20px; }

/* ── Page Header ─────────────────────────────── */
.page-header {
    background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    color: white;
    padding: 20px 28px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.header-brand h1 {
    font-family: 'Kaushan Script', cursive;
    font-size: 2rem;
    letter-spacing: 1px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    line-height: 1;
}

.header-brand p {
    font-size: 0.7rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    opacity: 0.55;
    margin-top: 4px;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-header {
    background: rgba(255,255,255,0.12);
    color: white;
    border: 1px solid rgba(255,255,255,0.25);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
    font-family: inherit;
}
.btn-header:hover { background: rgba(255,255,255,0.22); }

/* ── Main ─────────────────────────────────────── */
.main {
    max-width: 1260px;
    margin: 0 auto;
    padding: 28px 24px;
}

/* ── Top bar ─────────────────────────────────── */
.top-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    align-items: center;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 220px;
}
.search-wrapper::before {
    content: '🔍';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--purple); }

.client-count {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

.btn-import {
    background: var(--green);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
}
.btn-import:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-export {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
}
.btn-export:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-new {
    background: var(--purple);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
}
.btn-new:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── Client List ─────────────────────────────── */
.client-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.client-row {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.15s;
}
.client-row:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.client-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--purple-light);
    color: var(--purple);
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.client-info {
    flex: 1;
    min-width: 0;
}

.client-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.client-details {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 3px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
}

.client-detail-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.client-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: center;
}

.btn-whatsapp {
    background: var(--whatsapp);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 9px 16px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
    text-decoration: none;
    white-space: nowrap;
}
.btn-whatsapp:hover { background: var(--whatsapp-dark); transform: scale(1.03); }

.btn-icon {
    background: var(--purple-light);
    color: var(--purple);
    border: none;
    border-radius: 10px;
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}
.btn-icon:hover { transform: scale(1.1); }

.btn-icon.danger {
    background: rgba(229,62,62,0.12);
    color: var(--red);
}
.btn-icon.danger:hover { background: var(--red); color: white; }

/* ── Empty state ─────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.95rem; margin-bottom: 16px; }

/* ── Modal base ──────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.45);
    width: min(520px, 100%);
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1rem;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.7;
    padding: 0 4px;
}
.modal-close:hover { opacity: 1; }

/* ── View modal ──────────────────────────────── */
.modal-body {
    padding: 20px;
}

.modal-field {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.modal-field:last-child { border-bottom: none; }

.modal-field-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.modal-field-label {
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted);
    min-width: 90px;
}

.modal-field-value {
    flex: 1;
    word-break: break-word;
}

.modal-field-value a {
    color: var(--blue);
    text-decoration: none;
}
.modal-field-value a:hover { text-decoration: underline; }

.modal-actions {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.modal-actions .btn-whatsapp {
    padding: 11px 24px;
    font-size: 0.9rem;
    border-radius: 12px;
}

.btn-call {
    background: var(--blue-light);
    color: var(--blue);
    border: none;
    border-radius: 12px;
    padding: 11px 24px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-call:hover { background: var(--blue); color: white; }

.btn-edit-modal {
    background: var(--purple-light);
    color: var(--purple);
    border: none;
    border-radius: 12px;
    padding: 11px 24px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: background 0.2s;
}
.btn-edit-modal:hover { background: var(--purple); color: white; }

/* ── Form modal ──────────────────────────────── */
.form-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 180px;
}

.form-group.full { min-width: 100%; }

.form-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted);
}

.form-label .required {
    color: var(--red);
    margin-left: 2px;
}

.form-input, .form-textarea, .form-select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}
.form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--purple); }

.form-textarea {
    resize: vertical;
    min-height: 72px;
}

.form-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.btn-cancel {
    background: none;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}
.btn-cancel:hover { background: var(--bg); }

.btn-save {
    background: var(--purple);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 22px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}
.btn-save:hover { opacity: 0.88; }

.btn-delete-form {
    background: rgba(229,62,62,0.1);
    color: var(--red);
    border: 1px solid rgba(229,62,62,0.3);
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
    margin-right: auto;
}
.btn-delete-form:hover { background: var(--red); color: white; border-color: var(--red); }

/* ── Theme toggle ────────────────────────────── */
.btn-theme-r {
    position: fixed;
    bottom: 22px;
    right: 22px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 999;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.btn-theme-r:hover { transform: scale(1.1); }
.btn-theme-r::after { content: '🌓'; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
    .page-header { padding: 10px 12px; }
    .main { padding: 16px 12px; }
    .header-brand h1 { font-size: 1.3rem; }
    .header-brand p { font-size: 0.6rem; letter-spacing: 2px; }
    .client-row { padding: 12px 12px; gap: 10px; flex-wrap: wrap; }
    .client-actions { width: 100%; justify-content: flex-end; }
    .btn-whatsapp { flex: 1; justify-content: center; }
}

@media (max-width: 480px) {
    .page-header { padding: 8px 10px; }
    .header-brand h1 { font-size: 1.1rem; }
    .header-brand p { display: none; }
    .top-bar { flex-direction: column; }
    .search-wrapper { min-width: 100%; }
    .btn-import { width: 100%; justify-content: center; }
    .btn-export { width: 100%; justify-content: center; }
    .btn-new { width: 100%; justify-content: center; }
    .form-group { min-width: 100%; }
}

/* ── Import VCF Modal ────────────────────────── */

.vcf-file-input { display: none; }

.btn-choose-file-label {
    background: var(--purple);
    color: white;
    border-radius: 10px;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    transition: opacity 0.2s, transform 0.1s;
    margin-top: 10px;
    -webkit-tap-highlight-color: transparent;
}
.btn-choose-file-label:hover { opacity: 0.88; }
.btn-choose-file-label:active { transform: scale(0.97); opacity: 0.8; }

.import-modal-box {
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.45);
    width: min(680px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.vcf-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin: 20px;
}
.vcf-dropzone.dragover {
    border-color: var(--purple);
    background: var(--purple-light);
}
.vcf-dropzone-icon { font-size: 2.4rem; margin-bottom: 10px; }
.vcf-dropzone-title { font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
.vcf-dropzone-sub { font-size: 0.82rem; color: var(--muted); }
.vcf-dropzone input[type=file] { display: none; }

.btn-choose-file {
    background: var(--purple);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.import-preview {
    margin: 0 20px 4px;
    display: none;
}
.import-preview.visible { display: block; }

.import-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}
.import-preview-title {
    font-weight: 700;
    font-size: 0.9rem;
}
.import-preview-stats {
    font-size: 0.78rem;
    color: var(--muted);
}
.import-select-all {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.vcf-contact-list {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.vcf-contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    transition: background 0.15s;
}
.vcf-contact-item:last-child { border-bottom: none; }
.vcf-contact-item:hover { background: var(--bg); }
.vcf-contact-item.duplicate { opacity: 0.5; }

.vcf-contact-item input[type=checkbox] {
    accent-color: var(--purple);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
}

.vcf-contact-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--purple-light);
    color: var(--purple);
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}
.vcf-contact-item.duplicate .vcf-contact-avatar {
    background: var(--border);
    color: var(--muted);
}

.vcf-contact-info { flex: 1; min-width: 0; }
.vcf-contact-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vcf-contact-phone { font-size: 0.76rem; color: var(--muted); margin-top: 1px; }

.vcf-badge-dup {
    font-size: 0.68rem;
    background: rgba(221,107,32,0.15);
    color: var(--orange);
    border-radius: 6px;
    padding: 2px 7px;
    font-weight: 700;
    white-space: nowrap;
}

.import-result-bar {
    margin: 8px 20px 20px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: none;
}
.import-result-bar.success {
    display: block;
    background: var(--green-light);
    color: var(--green);
}
.import-result-bar.error {
    display: block;
    background: rgba(229,62,62,0.12);
    color: var(--red);
}

.btn-import-confirm {
    background: var(--green);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 22px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}
.btn-import-confirm:hover { opacity: 0.88; }
.btn-import-confirm:disabled { opacity: 0.4; cursor: default; }
