/* =============================================
   LIC Agent CRM — Mobile-First Stylesheet
   ============================================= */

:root {
    --primary:        #1a56db;
    --primary-dark:   #1e429f;
    --primary-light:  #dbeafe;
    --primary-xlight: #eff6ff;
    --success:        #059669;
    --success-light:  #d1fae5;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --orange:         #ea580c;
    --orange-light:   #fff7ed;
    --gray-50:        #f9fafb;
    --gray-100:       #f3f4f6;
    --gray-200:       #e5e7eb;
    --gray-400:       #9ca3af;
    --gray-500:       #6b7280;
    --gray-700:       #374151;
    --gray-900:       #111827;
    --white:          #ffffff;
    --border:         #e5e7eb;
    --radius-sm:      6px;
    --radius:         10px;
    --radius-lg:      14px;
    --shadow-sm:      0 1px 2px rgba(0,0,0,.06);
    --shadow:         0 1px 4px rgba(0,0,0,.10);
    --shadow-md:      0 4px 12px rgba(0,0,0,.12);
    --nav-h:          64px;
    --header-h:       56px;
    --transition:     .18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-50);
    min-height: 100vh;
    padding-top: var(--header-h);
    padding-bottom: calc(var(--nav-h) + 12px);
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: 1rem; }

/* ── Top Header ── */
.top-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--primary);
    color: var(--white);
    z-index: 100;
    box-shadow: 0 2px 8px rgba(26,86,219,.25);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 16px;
    max-width: 1200px;
    margin: 0 auto;
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.brand-shield {
    width: 32px; height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.brand-name { font-size: 1.125rem; font-weight: 700; letter-spacing: .5px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
    display: flex; flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}
.user-chip-name { font-size: .8rem; font-weight: 600; }
.user-chip-role { font-size: .68rem; opacity: .8; text-transform: capitalize; }
.logout-btn {
    width: 34px; height: 34px;
    background: rgba(255,255,255,.15);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--white);
    transition: background var(--transition);
}
.logout-btn:hover { background: rgba(255,255,255,.28); color: var(--white); }

/* ── Main Content ── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 16px 12px 8px; }

/* ── Bottom Navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--white);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    color: var(--gray-400);
    transition: color var(--transition);
    padding: 6px 2px;
    min-width: 0;
}
.bottom-nav-item:hover { color: var(--primary); }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active .nav-icon { background: var(--primary-xlight); border-radius: 8px; }
.nav-icon {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition);
    padding: 3px;
}
.nav-icon svg { width: 20px; height: 20px; }
.nav-label { font-size: .65rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--gray-900); }
.page-subtitle { font-size: .82rem; color: var(--gray-500); margin-top: 2px; }

/* ── Cards ── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.card-title { font-size: .95rem; font-weight: 600; color: var(--gray-700); margin-bottom: 12px; }
.card + .card { margin-top: 12px; }

/* ── Stat Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-sm);
}
.stat-card.green  { border-left-color: var(--success); }
.stat-card.yellow { border-left-color: var(--warning); }
.stat-card.orange { border-left-color: var(--orange); }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.blue   { border-left-color: var(--primary); }
.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1;
    margin-bottom: 4px;
}
.stat-label { font-size: .75rem; color: var(--gray-500); font-weight: 500; line-height: 1.3; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.2;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary   { background: var(--primary);  color: var(--white); }
.btn-primary:hover:not(:disabled)   { background: var(--primary-dark); color: var(--white); }
.btn-success   { background: var(--success);  color: var(--white); }
.btn-success:hover:not(:disabled)   { background: #047857; color: var(--white); }
.btn-danger    { background: var(--danger);   color: var(--white); }
.btn-danger:hover:not(:disabled)    { background: #b91c1c; color: var(--white); }
.btn-warning   { background: var(--warning);  color: var(--white); }
.btn-warning:hover:not(:disabled)   { background: #b45309; color: var(--white); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); color: var(--gray-700); }
.btn-outline   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover:not(:disabled)   { background: var(--primary-light); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 13px 28px; font-size: 1rem; }
.btn-block { display: flex; width: 100%; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; gap: 12px; }
label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 5px;
}
label .req { color: var(--danger); margin-left: 2px; }
.form-control {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-900);
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-control::placeholder { color: var(--gray-400); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .75rem; color: var(--gray-500); margin-top: 4px; }
.form-error { font-size: .75rem; color: var(--danger); margin-top: 4px; }
.form-section { margin-bottom: 20px; }
.form-section-title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--gray-500);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ── Login Page ── */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: 0;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo {
    text-align: center;
    margin-bottom: 24px;
}
.login-logo-icon {
    width: 64px; height: 64px;
    background: var(--primary);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 12px;
    box-shadow: 0 4px 16px rgba(26,86,219,.35);
}
.login-logo-icon svg { width: 32px; height: 32px; color: var(--white); fill: var(--white); }
.login-logo h1 { font-size: 1.5rem; font-weight: 800; color: var(--gray-900); }
.login-logo p  { font-size: .85rem; color: var(--gray-500); margin-top: 4px; }
.remember-row  { display: flex; align-items: center; gap: 8px; }
.remember-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.remember-row label { font-size: .85rem; font-weight: 400; color: var(--gray-600); cursor: pointer; margin: 0; }
.login-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: .875rem;
    margin-bottom: 16px;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }
.badge-blue   { background: var(--primary-light); color: var(--primary-dark); }
.badge-yellow { background: var(--warning-light); color: #92400e; }
.badge-orange { background: var(--orange-light);  color: #9a3412; }
.badge-green  { background: var(--success-light); color: #065f46; }
.badge-red    { background: var(--danger-light);  color: #991b1b; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--white); font-size: .875rem; }
thead th {
    background: var(--gray-50);
    color: var(--gray-700);
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tel-link { color: var(--primary); font-weight: 500; }
.tel-link:hover { text-decoration: underline; }

/* ── Search / Filter Bar ── */
.filter-bar {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px;
    margin-bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-end;
}
.filter-bar .form-group { margin: 0; flex: 1; min-width: 140px; }
.filter-bar .btn { margin-top: 0; align-self: flex-end; }
.search-input-wrap { position: relative; flex: 2; min-width: 200px; }
.search-input-wrap input { padding-left: 36px; }
.search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--gray-400); pointer-events: none;
}
.search-icon svg { width: 16px; height: 16px; }

/* ── Pagination ── */
.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 16px; justify-content: center; }
.page-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px;
    padding: 0 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .82rem; font-weight: 600;
    color: var(--gray-700);
    background: var(--white);
    transition: all var(--transition);
}
.page-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: var(--white); }

/* ── Policy Detail ── */
.policy-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.info-item {}
.info-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-500); font-weight: 600; margin-bottom: 2px; }
.info-value { font-size: .9rem; color: var(--gray-900); font-weight: 500; }
.info-value a { color: var(--primary); }

/* ── Call History ── */
.call-log-list { display: flex; flex-direction: column; gap: 10px; }
.call-log-item {
    background: var(--gray-50);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    border-left: 3px solid var(--primary);
}
.call-log-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.call-log-date { font-size: .75rem; color: var(--gray-500); }
.call-log-agent { font-size: .75rem; font-weight: 600; color: var(--gray-700); }
.call-log-comment { font-size: .85rem; color: var(--gray-700); }
.call-log-followup { font-size: .75rem; color: var(--warning); font-weight: 600; margin-top: 4px; }

/* ── Assignment Cards (Field Agent) ── */
.assignment-grid { display: flex; flex-direction: column; gap: 12px; }
.assignment-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary);
}
.assignment-card.visited { border-left-color: var(--success); }
.assignment-card.unsuccessful { border-left-color: var(--danger); }
.assignment-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.assignment-name { font-size: 1.05rem; font-weight: 700; color: var(--gray-900); }
.assignment-policy { font-size: .78rem; color: var(--gray-500); margin-top: 2px; }
.assignment-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.assignment-detail {}
.ad-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-400); font-weight: 600; }
.ad-value { font-size: .85rem; color: var(--gray-700); font-weight: 500; }
.assignment-notes { font-size: .82rem; color: var(--gray-600); background: var(--gray-50); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 12px; border-left: 2px solid var(--border); }
.phone-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--primary-xlight);
    color: var(--primary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 600;
}
.phone-btn svg { width: 14px; height: 14px; }

/* ── Modals ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.modal-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
    width: 28px; height: 28px;
    border: none;
    background: var(--gray-100);
    border-radius: 6px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    color: var(--gray-500);
    transition: background var(--transition);
}
.modal-close:hover { background: var(--gray-200); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast Notifications ── */
#toast-container {
    position: fixed;
    top: calc(var(--header-h) + 8px);
    right: 12px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: calc(100vw - 24px);
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn .25s ease;
    max-width: 360px;
    width: 100%;
}
.toast-success { background: var(--success); color: var(--white); }
.toast-error   { background: var(--danger);  color: var(--white); }
.toast-warning { background: var(--warning); color: var(--white); }
.toast-info    { background: var(--primary); color: var(--white); }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 14px;
    border: 1px solid;
}
.alert-success { background: var(--success-light); color: #065f46; border-color: #6ee7b7; }
.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); border-color: #93c5fd; }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: .9rem; }

/* ── Section Divider ── */
.section-divider { margin: 20px 0; border: none; border-top: 1px solid var(--border); }

/* ── User Management ── */
.user-row-role {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
}
.role-superadmin  { background: #ede9fe; color: #5b21b6; }
.role-call_agent  { background: var(--primary-light); color: var(--primary-dark); }
.role-field_agent { background: var(--success-light); color: #065f46; }
.status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 5px;
}
.status-dot.active   { background: var(--success); }
.status-dot.inactive { background: var(--gray-400); }

/* ── Import Results ── */
.import-result-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.import-result-list li { font-size: .82rem; padding: 6px 10px; border-radius: var(--radius-sm); }
.import-ok   { background: var(--success-light); color: #065f46; }
.import-skip { background: var(--warning-light); color: #92400e; }
.import-err  { background: var(--danger-light);  color: #991b1b; }

/* ── Reports ── */
.report-table td, .report-table th { padding: 10px 16px; }

/* ── Overdue highlight ── */
.overdue-row td { background: #fff5f5; }
.overdue-badge { color: var(--danger); font-size: .7rem; font-weight: 700; }
.today-row td { background: #fffbeb; }

/* ── Responsive ── */
@media (min-width: 600px) {
    .main-content { padding: 20px 20px 8px; }
    .stats-grid   { grid-template-columns: repeat(3, 1fr); }
    .form-row-2   { grid-template-columns: 1fr 1fr; }
    .assignment-grid { display: grid; grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
    .stats-grid   { grid-template-columns: repeat(5, 1fr); }
    .assignment-grid { grid-template-columns: repeat(3, 1fr); }
    .bottom-nav   { display: none; }
    body { padding-bottom: 16px; }
    /* Desktop sidebar — simple top tabs approach */
    .top-header .header-inner { gap: 24px; }
    .desktop-nav {
        display: flex;
        gap: 4px;
        flex: 1;
    }
    .desktop-nav a {
        padding: 6px 14px;
        border-radius: var(--radius-sm);
        color: rgba(255,255,255,.8);
        font-size: .85rem;
        font-weight: 500;
        transition: all var(--transition);
    }
    .desktop-nav a:hover { background: rgba(255,255,255,.15); color: var(--white); }
    .desktop-nav a.active { background: rgba(255,255,255,.2); color: var(--white); font-weight: 700; }
}
@media (max-width: 899px) {
    .desktop-nav { display: none; }
}
@media (max-width: 480px) {
    .policy-info-grid { grid-template-columns: 1fr; }
    .assignment-details { grid-template-columns: 1fr; }
}

/* ── Loading spinner ── */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2.5px solid rgba(255,255,255,.4);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Misc utilities ── */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--gray-500); }
.text-small  { font-size: .8rem; }
.font-bold   { font-weight: 700; }
.d-flex   { display: flex; }
.gap-1    { gap: 8px; }
.gap-2    { gap: 12px; }
.flex-wrap{ flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full   { width: 100%; }

/* ── Section highlight for today followups ── */
.highlight-today { background: #fffbeb !important; }
.highlight-overdue { background: #fff5f5 !important; }
