/* ============================================================
   SMS Marketing Platform - Styles
   ============================================================ */

:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-light: #EFF6FF;
    --surface: #FFFFFF;
    --bg: #F8FAFC;
    --border: #E2E8F0;
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --success: #10B981;
    --success-light: #ECFDF5;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --radius-card: 12px;
    --radius-input: 8px;
    --radius-btn: 8px;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-modal: 0 20px 60px rgba(0,0,0,0.15);
    --transition: 150ms ease;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Login Screen
   ============================================================ */

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg) 50%, var(--surface) 100%);
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 28px;
}

/* ============================================================
   Layout
   ============================================================ */

.main-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-input);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    margin-right: auto;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-name {
    font-weight: 500;
    font-size: 13px;
}

.page-content {
    flex: 1;
    padding: 24px;
}

/* ============================================================
   Forms
   ============================================================ */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--danger-light);
    border-radius: var(--radius-input);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-btn);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    padding: 6px;
    border-radius: 6px;
}

/* ============================================================
   Cards
   ============================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ============================================================
   Stats Cards
   ============================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    box-shadow: var(--shadow-card);
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

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

/* ============================================================
   Tables
   ============================================================ */

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

table tbody tr:hover {
    background: var(--primary-light);
}

table tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}

table tbody tr:nth-child(even):hover {
    background: var(--primary-light);
}

/* ============================================================
   Badges
   ============================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-yellow { background: var(--warning-light); color: var(--warning); }
.badge-gray { background: var(--bg); color: var(--text-secondary); }
.badge-orange { background: #FFF7ED; color: #C2410C; }

/* ============================================================
   Extension management
   ============================================================ */
.stat-mini {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    min-width: 96px;
}
.stat-mini .stat-num { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-mini .stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ============================================================
   Pagination
   ============================================================ */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.pagination-info {
    font-size: 13px;
    color: var(--text-secondary);
}

.pagination-buttons {
    display: flex;
    gap: 4px;
}

.pagination-buttons button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.pagination-buttons button:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.pagination-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-buttons button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 150ms ease;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    animation: scaleIn 150ms ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Toast
   ============================================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 12px 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 200ms ease;
    min-width: 280px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

/* ============================================================
   Toolbar
   ============================================================ */

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar .search-input {
    flex: 1;
    min-width: 200px;
    max-width: 320px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.toolbar .search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.toolbar select {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: var(--surface);
}

/* ============================================================
   Chart placeholder
   ============================================================ */

.chart-container {
    padding: 20px;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 160px;
    padding-top: 20px;
}

.bar-chart .bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
    justify-content: flex-end;
}

.bar-chart .bar {
    width: 100%;
    max-width: 40px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 300ms ease;
}

.bar-chart .bar-label {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.bar-chart .bar-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================================
   Send SMS Page
   ============================================================ */

.send-options {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.send-options .tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
}

.send-options .tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.phone-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    min-height: 44px;
    cursor: text;
    margin-top: 8px;
}

.phone-add-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.phone-add-row input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    font-size: 16px; /* prevent iOS zoom */
    background: #fff;
    color: var(--text-primary);
}
.phone-add-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.phone-add-row .btn-sm {
    padding: 0 16px;
    white-space: nowrap;
    flex-shrink: 0;
}

.phone-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px;
}

.phone-tag button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}

.preview-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 16px;
    margin: 16px 0;
}

.preview-box .preview-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.preview-box .preview-content {
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ============================================================
   Empty State
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

/* ============================================================
   Responsive
   ============================================================ */

/* Safe area for notched phones */
.topbar {
    padding-top: max(0px, env(safe-area-inset-top));
}
.sidebar-header {
    padding-top: max(16px, calc(env(safe-area-inset-top) + 12px));
}
.modal-content {
    max-height: calc(100vh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* Sidebar backdrop (mobile) */
body.sidebar-open {
    overflow: hidden;
}
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

@media (max-width: 768px) {
    .sidebar-backdrop {
        display: block;
    }
}

@media (max-width: 768px) {
    .main-layout {
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 82%;
        max-width: 300px;
        height: 100%;
        height: 100dvh;
        transform: translate3d(-100%, 0, 0);
        z-index: 1000;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        transition: transform 0.25s ease;
        will-change: transform;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        -webkit-transform: translate3d(-100%, 0, 0);
    }

    .sidebar.open {
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
        display: flex !important;
        visibility: visible !important;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .topbar {
        gap: 8px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .topbar-user {
        gap: 8px;
    }

    .topbar-username {
        display: none;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .page-header h1 {
        font-size: 20px;
    }

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

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

    .toolbar .search-input {
        max-width: 100%;
    }

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

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .pagination {
        flex-direction: column;
        gap: 12px;
    }

    .modal-content {
        width: calc(100% - 24px);
        max-height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        margin: 12px auto;
    }

    .modal-body {
        max-height: calc(100vh - 180px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }

    .btn {
        min-height: 44px;
    }

    /* Tables -> cards */
    .table-responsive table,
    table.data-table {
        display: block;
        width: 100%;
        border: 0;
    }

    .table-responsive thead,
    table.data-table thead {
        display: none;
    }

    .table-responsive tbody,
    table.data-table tbody {
        display: block;
    }

    .table-responsive tr,
    table.data-table tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 10px;
        box-shadow: var(--shadow-card);
    }

    .table-responsive td,
    table.data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        border: 0;
        padding: 8px 4px;
        text-align: right;
        white-space: normal;
    }

    .table-responsive td::before,
    table.data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
        padding-right: 12px;
    }

    .table-responsive td:first-child,
    table.data-table td:first-child {
        border-bottom: 1px solid var(--border);
        margin-bottom: 4px;
        font-weight: 600;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-content {
        padding: 16px;
    }
}

/* ============================================================
   Account / Team stats pages — filter bar & info tables
   ============================================================ */

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

.page-filter h1 {
    margin: 0;
    white-space: nowrap;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-row .form-control {
    width: auto;
    min-width: 150px;
    padding: 8px 10px;
}

.filter-sep {
    font-size: 13px;
    color: var(--text-secondary);
}

.stats-grid-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-bottom: 16px;
}

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

.header-badge {
    margin-left: auto;
}

.info-table {
    width: 100%;
    font-size: 13px;
    margin-top: 16px;
    border-collapse: collapse;
}

.info-table td {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

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

.info-label {
    color: var(--text-secondary);
    width: 45%;
}

.info-value {
    text-align: right;
    font-weight: 600;
    word-break: break-word;
}

@media (max-width: 768px) {
    .stats-grid-5 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 24px;
    }

    .card-header-wrap {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-badge {
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    .page-filter {
        flex-direction: column;
        align-items: stretch;
    }

    .page-filter h1 {
        font-size: 20px;
    }

    .filter-row {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        gap: 8px;
        align-items: center;
    }

    .filter-row-multi {
        grid-template-columns: 1fr;
    }

    .filter-row .form-control {
        width: 100%;
        min-width: 0;
    }

    .filter-row .btn {
        width: 100%;
    }

    .filter-sep {
        text-align: center;
    }

    .stats-grid-5 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stats-grid-5 .stat-card:last-child {
        grid-column: span 2;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .stat-card .stat-label {
        font-size: 11px;
    }

    .info-table,
    .info-table tbody,
    .info-table tr,
    .info-table td {
        display: block;
        width: 100%;
    }

    .info-table tr {
        padding: 10px 0;
        border-bottom: 1px solid var(--border);
    }

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

    .info-label {
        width: 100%;
        margin-bottom: 4px;
        font-size: 12px;
    }

    .info-value {
        text-align: left;
        font-size: 14px;
    }
}

/* ============================================================
   Utility
   ============================================================ */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.hidden { display: none !important; }

/* Checkbox list for contacts */
.contact-select-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
}

.contact-select-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}

.contact-select-item:hover {
    background: var(--primary-light);
}

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

.contact-select-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* File upload area */
.file-upload {
    border: 2px dashed var(--border);
    border-radius: var(--radius-input);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

.file-upload:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.file-upload p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
}

/* Config status indicator */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-secondary); }

/* Custom file input (Spanish label, avoids browser default language) */
.file-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.file-input-wrap:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.file-input-wrap input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.file-input-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #F1F5F9;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}
.file-input-wrap:hover .file-input-btn {
    background: #E2E8F0;
}
.file-input-name {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Mobile card tables ===== */
@media (max-width: 640px) {
    .table-wrap { overflow: visible !important; border-radius: 12px; }
    table.data-table,
    table.data-table thead,
    table.data-table tbody,
    table.data-table th,
    table.data-table td,
    table.data-table tr { display: block; }
    table.data-table thead { display: none; }
    table.data-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 10px;
        padding: 10px 12px;
        box-shadow: var(--shadow);
    }
    table.data-table tr:nth-child(even) { background: var(--surface); }
    table.data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        border: none;
        padding: 7px 0;
        text-align: right;
    }
    table.data-table td::before {
        content: attr(data-label);
        font-size: 12px;
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
        padding-right: 12px;
    }
    table.data-table td:empty { display: none; }
    table.data-table td .actions,
    table.data-table td .action-buttons {
        justify-content: flex-end;
        width: 100%;
    }
}

/* ===== Mobile modal & toolbar (small phones) ===== */
@media (max-width: 480px) {
    .modal-content { width: 94%; max-height: 92vh; padding: 18px; }
    .modal { align-items: flex-end; }
    .modal-content { border-radius: 16px 16px 0 0; animation: slideUp .25s ease; width: 100%; }
    .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
    .toolbar > input, .toolbar > select { width: 100% !important; min-width: 0; }
    .toolbar .btn { width: 100%; justify-content: center; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-card .value { font-size: 24px; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions .btn { width: 100%; }
    .pagination { flex-wrap: wrap; gap: 6px; }
    .toast { left: 12px; right: 12px; max-width: none; }
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Floating Action Button (quick send) ===== */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    box-shadow: 0 6px 16px rgba(37,99,235,0.35), 0 2px 6px rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 900;
    transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.fab:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 10px 22px rgba(37,99,235,0.4); }
.fab:active { transform: scale(0.95); }
.fab svg { width: 26px; height: 26px; }
.fab.hidden { display: none; }

/* Quick send bottom sheet */
.quick-send { display: none; }
.quick-send.open { display: flex; }
.quick-send .modal-content {
    width: 100%;
    max-width: 480px;
    max-height: 88vh;
    border-radius: 16px 16px 0 0;
    padding: 0;
    overflow: hidden;
    animation: slideUp .25s ease;
    align-self: flex-end;
}
.quick-send-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--light-blue);
}
.quick-send-header h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.quick-send-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.quick-send-body label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.quick-contact-row { display: flex; gap: 8px; }
.quick-contact-row input { flex: 1; min-width: 0; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 96px; overflow-y: auto; padding: 2px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--light-blue);
    color: var(--primary);
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
}
.chip button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}
.quick-contact-results {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 180px;
    overflow-y: auto;
    background: #fff;
}
.quick-contact-results li {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.quick-contact-results li:last-child { border-bottom: none; }
.quick-contact-results li:hover { background: var(--light-blue); }
.quick-contact-results .muted { color: var(--text-secondary); font-size: 12px; margin-left: 6px; }
.quick-meta { font-size: 12px; color: var(--text-secondary); display: flex; justify-content: space-between; }
.quick-send-footer { padding: 12px 18px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); display: flex; gap: 8px; }
.quick-send-footer .btn { flex: 1; justify-content: center; }

@media (min-width: 641px) {
    .quick-send { align-items: center; justify-content: center; }
    .quick-send .modal-content {
        align-self: center;
        border-radius: var(--radius-lg);
        max-height: 85vh;
    }
}

/* ============================================================
   Embedded bubble panel (#/quick-send-embed)
   ============================================================ */
html.embed, body.embed-body {
    margin: 0; padding: 0; height: 100%;
    background: #F8FAFC;
    font-family: 'Inter', system-ui, sans-serif;
}
.embed-shell {
    display: flex; flex-direction: column; min-height: 100vh;
    background: #FFFFFF;
}
.embed-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; background: #2563EB; color: #fff;
    position: sticky; top: 0; z-index: 5;
}
.embed-title { font-size: 16px; font-weight: 700; }
.embed-close {
    background: rgba(255,255,255,0.18); border: 0; color: #fff;
    width: 32px; height: 32px; border-radius: 50%; font-size: 22px;
    line-height: 1; cursor: pointer;
}
.embed-close:active { background: rgba(255,255,255,0.32); }
.embed-body-inner { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.embed-user { font-size: 13px; color: #64748B; }
.embed-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #1E293B; }
.embed-field input, .embed-field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid #E2E8F0;
    border-radius: 8px; font-size: 14px; font-family: inherit;
    box-sizing: border-box; background: #fff; color: #1E293B;
}
.embed-field input:focus, .embed-field textarea:focus {
    outline: none; border-color: #2563EB; box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.embed-input-row { display: flex; gap: 8px; }
.embed-input-row input { flex: 1; }
.quick-results {
    list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto;
    border: 1px solid #E2E8F0; border-radius: 8px; background: #fff;
}
.quick-results li {
    padding: 10px 12px; display: flex; justify-content: space-between;
    cursor: pointer; font-size: 13px; border-bottom: 1px solid #F1F5F9;
}
.quick-results li:last-child { border-bottom: 0; }
.quick-results li:hover { background: #EFF6FF; }
.quick-results .muted { color: #64748B; cursor: default; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE;
    padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.chip button {
    background: transparent; border: 0; color: #1D4ED8; cursor: pointer;
    font-size: 16px; line-height: 1; padding: 0;
}
.embed-counter { font-size: 12px; color: #64748B; text-align: right; }
.embed-form { padding: 24px 16px; display: flex; flex-direction: column; gap: 14px; }
.embed-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #1E293B; }
.embed-form input {
    padding: 10px 12px; border: 1px solid #E2E8F0; border-radius: 8px;
    font-size: 14px; font-family: inherit;
}
.embed-err { color: #EF4444; font-size: 13px; min-height: 18px; }
.w-full { width: 100%; }

/* Quick SMS in-app sheet */
.quick-sms-overlay { z-index: 1100; }
.quick-sms-sheet { max-width: 520px; width: 100%; }
.quick-sms-recipient { display: flex; gap: 8px; }
.quick-sms-recipient input { flex: 1; }
.quick-sms-contact-list {
    margin-top: 8px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; max-height: 220px; overflow-y: auto;
}
.quick-sms-contact-item {
    padding: 10px 12px; display: flex; justify-content: space-between;
    cursor: pointer; font-size: 14px; border-bottom: 1px solid #F1F5F9; gap: 12px;
}
.quick-sms-contact-item:last-child { border-bottom: none; }
.quick-sms-contact-item:hover,
.quick-sms-contact-item.hover { background: var(--light-blue); }
.quick-sms-contact-item .muted { color: var(--text-secondary); font-size: 13px; }

/* Ensure Agregar button is always visible on small screens (APK) */
.phone-add-row {
    flex-wrap: nowrap !important;
}
.phone-add-row input {
    min-width: 0;
    flex: 1 1 auto;
    width: 1% !important;
}
.phone-add-row .btn-sm {
    flex: 0 0 auto !important;
    min-width: 88px;
    height: 44px;
    padding: 0 16px !important;
    font-size: 15px !important;
    font-weight: 700;
    border-radius: 8px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: var(--primary) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 2px 6px rgba(37,99,235,0.25);
}
.phone-add-row .btn-sm:active {
    background: var(--primary-hover) !important;
}

/* Extensiones bulk upload */
.ext-upload-card {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}
.ext-dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    padding: 26px 16px;
    border: 2px dashed var(--border, #cbd5e1);
    border-radius: 10px;
    background: var(--light, #f8fafc);
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    text-align: center;
    transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.ext-dropzone:hover { border-color: var(--primary, #2563eb); color: var(--primary, #2563eb); }
.ext-dropzone.dragover {
    border-color: var(--primary, #2563eb);
    background: var(--light-blue, #eff6ff);
    color: var(--primary, #2563eb);
}
.ext-dropzone-inner { display: flex; flex-direction: column; align-items: center; }
.ext-dropzone i { stroke-width: 1.8; }
.ext-file-status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    border: 1px solid transparent;
}
.ext-status-uploading { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.ext-status-ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.ext-status-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.ext-manual {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: #fff;
}
.ext-manual summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--text, #1e293b);
    list-style: none;
}
.ext-manual summary::-webkit-details-marker { display: none; }
.ext-manual summary::before { content: "▸ "; color: var(--text-secondary, #64748b); }
.ext-manual[open] summary::before { content: "▾ "; }

/* Click-to-insert template variable chips */
.var-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}
.var-chips-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #64748B);
    margin-right: 2px;
}
button.var-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--primary, #2563EB);
    background: var(--light-blue-bg, #EFF6FF);
    border: 1px solid var(--border, #E2E8F0);
    border-radius: 999px;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, transform 80ms ease;
}
button.var-chip:hover {
    background: #DBEAFE;
    border-color: var(--primary, #2563EB);
}
button.var-chip:active {
    transform: translateY(1px);
}
