:root {
    --bg-page: #F1F5F9;
    --bg-card: #FFFFFF;
    --text-primary: #1E293B;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --accent-blue: #1A458B;
    --accent-teal: #22B8B8;
    --accent-purple: #7C3AED;
    --accent-orange: #F97316;
    --accent-green: #22C55E;
    --accent-silver: #94A3B8;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-page: #283447;
    --bg-card: #1E293B;
    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --border: #334155;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-page);
}

h1 { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); margin: 0 0 0.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 600; color: var(--text-secondary); margin: 0 0 1rem; }
h3 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); margin: 0 0 0.5rem; }
p { margin: 0 0 0.75rem; color: var(--text-secondary); }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
}

.auth-container {
    background: var(--bg-card);
    padding: 1.5rem 3rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.auth-container h1 { text-align: center; margin-bottom: 1rem; }
.auth-container h2 { text-align: center; color: var(--text-muted); }

.auth-form .form-group { margin-bottom: 1.25rem; }
.auth-form label { display: block; margin-bottom: 0.35rem; font-weight: 600; color: var(--text-primary); }

.auth-form input {
    width: 100%;
    padding: 0.65rem 1rem;
    padding-right: 2.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.auth-form .input-wrap { position: relative; }
.auth-form .input-wrap input { padding-right: 2.75rem; }

.auth-form .password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
}

.auth-form .password-toggle:hover { color: var(--accent-teal); }
.auth-form input:focus { outline: none; border-color: var(--accent-teal); }

.auth-form button[type="submit"] {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
    background: var(--accent-teal);
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.auth-form button[type="submit"]:hover { background: #1A9A9A; }
.auth-form a { display: block; margin-top: 1.25rem; text-align: center; color: var(--accent-teal); font-weight: 500; text-decoration: none; }
.auth-form a:hover { color: var(--accent-purple); }

.auth-logo {
    width: 100px;
    height: 100px;
    margin: 0.5rem auto;
    display: block;
}

.navbar {
    background: var(--accent-blue);
    color: #FFFFFF;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: #FFFFFF;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand img { height: 36px; width: auto; }

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.9);
    padding: 0.5rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.navbar-toggle:hover { color: #FFFFFF; }
.navbar-links { display: flex; align-items: center; gap: 0.25rem; }

.navbar a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.navbar a:hover { background: rgba(255,255,255,0.15); color: #FFFFFF; }
.navbar .nav-notifications { position: relative; }
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
}
.navbar a.active { background: var(--accent-teal); color: var(--text-primary); }

.main-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 64px);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}
@media (max-width: 768px) {
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header > div:first-child { width: 100%; }
    .page-header .btn { width: 100%; max-width: 100%; }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    margin-top: 1rem;
    width: 100%;
}
@media (max-width: 767px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
.stats-grid.stats-grid-sales {
    grid-template-columns: repeat(3, 1fr);
}
.dashboard-chart-wrap {
    margin-top: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    width: 100%;
    min-height: 320px;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-top: 4px solid var(--accent-teal);
}

.stat-card:nth-child(2) { border-top-color: var(--accent-orange); }
.stat-card:nth-child(3) { border-top-color: var(--accent-purple); }
.stat-card:nth-child(4) { border-top-color: var(--accent-green); }

.stat-card .value { font-size: 1.75rem; color: var(--text-primary); }
.stat-card .label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; margin-top: 0.25rem; }

.table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    overflow-y: visible;
}

.search-bar-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.search-input-wrap .search-input {
    width: 100%;
    padding: 0.65rem 2.25rem 0.65rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--bg-card);
    color: var(--text-primary);
}
.search-input-wrap .search-input:focus {
    outline: none;
    border-color: var(--accent-teal);
}
.search-clear {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.search-clear:hover {
    color: var(--text-primary);
}
.search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.65rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--bg-card);
    color: var(--text-primary);
}
.search-input:focus {
    outline: none;
    border-color: var(--accent-teal);
}

.table-container table { width: 100%; border-collapse: collapse; }
.table-container th, .table-container td { padding: 1rem 1.25rem; text-align: left; }
.table-container th {
    background: var(--border);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    text-transform: uppercase;
}

.table-container tr:hover td { background: var(--border); opacity: 0.9; }
.table-container tr { cursor: pointer; }

.empty-state { padding: 3rem 2rem; text-align: center; color: var(--text-muted); }
.empty-state .icon { margin-bottom: 1rem; }

.btn {
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary { background: var(--accent-blue); opacity: 0.95; color: #FFFFFF; }
.btn-primary:hover { background: #21509c; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-icon {
    padding: 0.35rem;
    min-width: auto;
    background: transparent;
    color: var(--text-secondary);
}
.btn-icon:hover { color: var(--accent-teal); }
.actions-cell { white-space: nowrap; }

.breadcrumb { margin-bottom: 1rem; font-size: 0.9rem; }
.breadcrumb a { color: var(--accent-teal); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--text-muted); margin: 0 0.35rem; }
.lead-detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.lead-detail-cards {
    display: grid;
    gap: 1.5rem;
    margin-top: 1.5rem;
}
@media (min-width: 992px) {
    .lead-detail-cards { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 991px) and (min-width: 768px) {
    .lead-detail-cards { grid-template-columns: 1fr 1fr; }
    .lead-card-internal { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
    .lead-detail-cards { grid-template-columns: 1fr; }
}
.lead-detail-card { height: fit-content; }
.detail-list { margin: 0; }
.detail-list dt { font-weight: 600; color: var(--text-muted); font-size: 0.85rem; margin-top: 0.75rem; }
.detail-list dd { margin: 0.25rem 0 0; }
.detail-list dd a[href^="tel:"], .detail-list dd a[href^="mailto:"], .table-container td a[href^="tel:"], .table-container td a[href^="mailto:"] { color: var(--accent-teal); text-decoration: none; }
.notification-title-link { color: var(--accent-teal); text-decoration: none; }
.notification-title-link:hover { text-decoration: underline; }
.detail-list dd a:hover, .table-container td a[href^="tel:"]:hover, .table-container td a[href^="mailto:"]:hover { text-decoration: underline; }
.detail-list dt:first-child { margin-top: 0; }
.notes-list { margin-top: 1rem; }
.note-item { padding: 0.75rem; background: var(--border); border-radius: var(--radius-sm); margin-bottom: 0.5rem; }
.note-item p { margin: 0 0 0.35rem; }
.note-item small { font-size: 0.8rem; color: var(--text-muted); }
.text-muted { color: var(--text-muted); margin: 0; }
.profile-form textarea { width: 100%; padding: 0.65rem 1rem; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; background: var(--bg-card); color: var(--text-primary); resize: vertical; }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 0.5rem;
}
.modal-header h3 { margin: 0; flex: 1; }
.modal-close-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.35rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close-icon:hover { color: var(--text-primary); }
.modal h3 { margin-bottom: 1.5rem; }
.modal .modal-header + * { margin-top: 0; }
.modal .modal-header ~ .modal-actions { margin-top: 1.5rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.modal-actions .btn { flex: 1; justify-content: center; text-align: center; }

.form-group select, .profile-form input, .profile-form select {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.profile-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    height: fit-content;
}

.avatar-initials {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--accent-teal);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
}

.role-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.role-badge.ADMIN { background: var(--accent-purple); color: #FFFFFF; }
.role-badge.SALES { background: var(--accent-orange); color: #FFFFFF; }

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--text-muted);
    color: #fff;
}
.status-badge.NEW { background: #3B82F6; color: #fff; }
.status-badge.CONTACTED { background: #8B5CF6; color: #fff; }
.status-badge.QUALIFIED { background: #22B8B8; color: #fff; }
.status-badge.PROPOSAL { background: #F59E0B; color: #fff; }
.status-badge.NEGOTIATION { background: #F97316; color: #fff; }
.status-badge.WON { background: #22C55E; color: #fff; }
.status-badge.LOST { background: #EF4444; color: #fff; }

#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    max-width: 400px;
    min-width: 300px;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s, transform 0.3s;
    border-left: 4px solid;
}

.toast-item.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-icon { flex-shrink: 0; font-size: 1.25rem; font-weight: 700; line-height: 1; }
.toast-body { flex: 1; }
.toast-body strong { display: block; margin-bottom: 0.15rem; }
.toast-body span { font-size: 0.9em; opacity: 0.95; }
.toast-success { background: #f0fdf4; color: #166534; border-left-color: #22c55e; }
.toast-success .toast-icon { color: #22c55e; }
.toast-error { background: #fef2f2; color: #991b1b; border-left-color: #ef4444; }
.toast-error .toast-icon { color: #ef4444; }
.toast-warning { background: #fffbeb; color: #92400e; border-left-color: #f59e0b; }
.toast-warning .toast-icon { color: #f59e0b; }

.profile-form .form-group {
    margin-bottom: 1.25rem;
}

.profile-form .form-row.two-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.profile-form textarea {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text-primary);
    resize: vertical;
    min-height: 80px;
}

.profile-form .input-wrap {
    position: relative;
}

.profile-form .input-wrap input {
    padding-right: 2.75rem;
}

.profile-form .password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
}

.profile-form .password-toggle:hover {
    color: var(--accent-teal);
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: rgba(255,255,255,0.9);
}

.navbar-drawer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-page);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.navbar-drawer-overlay.is-open {
    opacity: 1;
    visibility: visible;
}
.navbar-drawer {
    width: 100%;
    height: 100%;
    padding: 2rem;
    padding-left: 2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    transform: scale(0.95);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.navbar-drawer-overlay.is-open .navbar-drawer {
    transform: scale(1);
    opacity: 1;
}
.navbar-drawer-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-primary);
}
.navbar-drawer-close:hover { opacity: 0.8; }
.navbar-drawer-links {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
    max-width: 280px;
}
.navbar-drawer-links a,
.navbar-drawer-links .theme-toggle-drawer {
    color: var(--text-primary);
    text-decoration: none;
    padding: 0.75rem 0;
    border-radius: 0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    justify-content: flex-start;
    background: transparent;
}
.navbar-drawer-links a:hover,
.theme-toggle-drawer:hover {
    color: var(--accent-teal);
}
.navbar-drawer-links a.active {
    color: var(--accent-blue);
    background: transparent;
}
[data-theme="dark"] .navbar-drawer-links a.active {
    color: var(--accent-teal);
}
.navbar-drawer-links .nav-notifications { position: relative; }
.navbar-drawer-links .notification-badge {
    position: static;
    margin-left: 0.35rem;
}
.theme-toggle-drawer { font-size: 1rem; }

@media (max-width: 768px) {
    .navbar { padding: 0 1rem; }
    .navbar-toggle { display: flex; }
    .navbar-links { display: none; }
    .main-content { padding: 1rem; }
}

@media (min-width: 769px) {
    .navbar-drawer-overlay { display: none !important; }
}
