:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --accent: #06b6d4;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --success: #16a34a;
    --success-light: #dcfce7;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

.icon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

/* Topbar */
.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
}

.brand-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
}

.menu-toggle:hover { background: var(--bg); }

.navmenu {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    max-width: 80vw;
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 64px 16px 16px;
    box-shadow: 2px 0 24px rgba(15, 23, 42, 0.18);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 30;
}

.navmenu.open { transform: translateX(0); }

.navmenu-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
}

.navmenu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    opacity: 0;
    transform: translateX(-16px);
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.15s ease, color 0.15s ease;
    transition-delay: 0s;
}

.navmenu.open a {
    opacity: 1;
    transform: translateX(0);
}

.navmenu.open a:nth-child(2) { transition-delay: 0.05s; }
.navmenu.open a:nth-child(3) { transition-delay: 0.1s; }
.navmenu.open a:nth-child(4) { transition-delay: 0.15s; }
.navmenu.open a:nth-child(5) { transition-delay: 0.2s; }
.navmenu.open a:nth-child(6) { transition-delay: 0.25s; }

.navmenu a:hover { background: var(--primary-light); color: var(--primary); }

.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 20;
}

.nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

@media (min-width: 700px) {
    .menu-toggle { display: none; }
    .topbar-inner { flex-wrap: nowrap; }
    .navmenu-close { display: none; }
    .nav-backdrop { display: none; }
    .navmenu {
        position: static;
        height: auto;
        width: auto;
        max-width: none;
        flex-direction: row;
        gap: 2px;
        padding: 0;
        box-shadow: none;
        transform: none;
        transition: none;
    }
    .navmenu a {
        opacity: 1;
        transform: none;
        transition-delay: 0s !important;
        padding: 8px 12px;
        font-size: 0.92rem;
    }
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
h1, h2, h3 { margin-top: 0; color: var(--text); }

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    flex-shrink: 0;
}

.stat-icon.danger { background: var(--danger-light); color: var(--danger); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.primary { background: var(--primary-light); color: var(--primary); }

.stat-label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.stat-sub {
    color: var(--muted);
    font-size: 0.8rem;
}

/* Forms */
.form-group { margin-bottom: 14px; }

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 4px; }

.phone-input {
    display: flex;
    align-items: stretch;
}

.phone-prefix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    background: var(--bg);
    color: var(--muted);
    font-size: 1rem;
}

.phone-input input {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.password-wrapper {
    position: relative;
}

.password-wrapper input {
    padding-right: 42px;
}

.password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
}

.password-toggle:hover { color: var(--text); }
.password-toggle .icon-hide { display: none; }
.password-toggle.revealed .icon-show { display: none; }
.password-toggle.revealed .icon-hide { display: inline-block; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); filter: brightness(1.05); }
.btn:active { transform: translateY(0); }

.btn-danger { background: linear-gradient(135deg, var(--danger), #b91c1c); }
.btn-success { background: linear-gradient(135deg, var(--success), #15803d); }
.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}
.btn-secondary:hover { background: var(--bg); }
.btn-whatsapp { background: linear-gradient(135deg, #25d366, #1da851); }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Lists / Tables */
.client-list { list-style: none; padding: 0; margin: 0; }

.client-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

@media (min-width: 640px) {
    .client-item {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.client-item:last-child { border-bottom: none; }

.client-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.client-row > div {
    min-width: 0;
}

.client-row .client-name,
.client-row strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

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

.client-name {
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1rem;
    padding: 0;
    text-align: left;
}

.client-name:hover { color: var(--primary); }

.client-meta { color: var(--muted); font-size: 0.85rem; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-success { background: var(--success-light); color: var(--success); }

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 28px 0 10px;
    font-size: 1.05rem;
    font-weight: 700;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.confirm-box {
    max-width: 380px;
    text-align: center;
}

.confirm-box p {
    font-size: 1rem;
    margin: 8px 0 20px;
}

.confirm-actions {
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 100px;
}

.modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--muted);
}

.flash {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-weight: 500;
}

.flash-success { background: var(--success-light); color: #166534; }
.flash-error { background: var(--danger-light); color: #991b1b; }

.text-muted { color: var(--muted); }
.mt-2 { margin-top: 16px; }
.footer { text-align: center; padding: 24px 16px; color: var(--muted); font-size: 0.85rem; }
.footer a { color: var(--muted); text-decoration: none; font-weight: 700; }
.footer a:hover { color: inherit; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
