/* ============================================================
   MyBimaSathi — Premium SaaS Design System
   ============================================================ */

:root {
    --primary:        #2563eb;
    --primary-hover:  #1d4ed8;
    --primary-light:  #3b82f6;
    --primary-dark:   #1e40af;
    --primary-50:     #eff6ff;
    --primary-100:    #dbeafe;
    --accent:         #6366f1;
    --success:        #10b981;
    --success-light:  #d1fae5;
    --warning:        #f59e0b;
    --warning-light:  #fef3c7;
    --danger:         #ef4444;
    --danger-light:   #fee2e2;
    --bg-body:        #f8fafc;
    --bg-card:        #ffffff;
    --bg-hover:       #f1f5f9;
    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-muted:     #94a3b8;
    --text-faint:     #cbd5e1;
    --border:         #e2e8f0;
    --border-light:   #f1f5f9;
    --radius-xs:      0.375rem;
    --radius-sm:      0.5rem;
    --radius:         0.75rem;
    --radius-lg:      1rem;
    --radius-xl:      1.25rem;
    --shadow-xs:      0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm:      0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow:         0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-md:      0 6px 16px -4px rgba(0,0,0,0.08), 0 2px 6px -2px rgba(0,0,0,0.04);
    --shadow-lg:      0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.03);
    --shadow-xl:      0 20px 40px -8px rgba(0,0,0,0.1);
    --transition:     0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast:0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width:  264px;
    --topbar-height:  64px;
}

/* ===== Base Reset & Typography ===== */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif !important;
    background: var(--bg-body) !important;
    color: var(--text-primary) !important;
    font-size: 14px !important;
    line-height: 1.65;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
}

h1:focus { outline: none; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-hover);
}

::selection {
    background: var(--primary-100);
    color: var(--primary-dark);
}

/* ===== Cards ===== */
.card {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-xs);
    background: var(--bg-card) !important;
    transition: box-shadow var(--transition), transform var(--transition);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-body {
    padding: 1.5rem !important;
}

.card-header-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.card-header-section h5,
.card-header-section .card-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-section-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

/* ===== KPI / Stat Cards ===== */
.kpi-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    padding: 1.5rem;
    background: var(--bg-card);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity var(--transition);
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--primary-100);
}

.kpi-card:hover::before {
    opacity: 1;
}

.kpi-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.kpi-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.kpi-icon-wrap.blue    { background: var(--primary-50); color: var(--primary); }
.kpi-icon-wrap.green   { background: var(--success-light); color: var(--success); }
.kpi-icon-wrap.amber   { background: var(--warning-light); color: var(--warning); }
.kpi-icon-wrap.red     { background: var(--danger-light); color: var(--danger); }
.kpi-icon-wrap.violet  { background: #ede9fe; color: #7c3aed; }

.kpi-icon {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    line-height: 1;
}

.kpi-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 0.25rem;
}

.kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: 0.625rem;
    padding: 0.2rem 0.5rem;
    border-radius: 50rem;
}

.kpi-trend.up   { background: var(--success-light); color: #059669; }
.kpi-trend.down { background: var(--danger-light); color: #dc2626; }
.kpi-trend.neutral { background: var(--bg-hover); color: var(--text-secondary); }

/* ===== Buttons ===== */
.btn {
    border-radius: var(--radius-sm) !important;
    font-weight: 500 !important;
    font-size: 0.8125rem;
    padding: 0.5rem 1rem;
    transition: all var(--transition-fast);
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    line-height: 1.4;
    cursor: pointer;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
}

.btn-outline-primary {
    color: var(--primary) !important;
    border-color: var(--border) !important;
    background: var(--bg-card) !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: var(--primary-50) !important;
    color: var(--primary-hover) !important;
    border-color: var(--primary) !important;
}

.btn-outline-secondary {
    color: var(--text-secondary) !important;
    border-color: var(--border) !important;
    background: var(--bg-card) !important;
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
    border-color: var(--text-muted) !important;
}

.btn-ghost {
    color: var(--text-secondary);
    border: none !important;
    background: transparent !important;
    padding: 0.4rem 0.75rem;
}

.btn-ghost:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary);
}

.btn-success {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: #fff !important;
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.2);
}

.btn-success:hover,
.btn-success:focus {
    background: #059669 !important;
    border-color: #059669 !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3) !important;
}

.btn-outline-danger {
    color: var(--danger) !important;
    border-color: var(--border) !important;
    background: var(--bg-card) !important;
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
    background: var(--danger-light) !important;
    border-color: var(--danger) !important;
    color: #dc2626 !important;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus, .form-select:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
    border-color: var(--primary-light) !important;
    outline: none;
}

/* ===== Forms ===== */
.form-control, .form-select {
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--border) !important;
    padding: 0.5625rem 0.875rem !important;
    font-size: 0.875rem !important;
    color: var(--text-primary) !important;
    background: var(--bg-card) !important;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.form-control:hover, .form-select:hover {
    border-color: var(--text-muted) !important;
}

.form-control::placeholder {
    color: var(--text-muted) !important;
}

.form-label {
    font-weight: 500 !important;
    font-size: 0.8125rem !important;
    color: var(--text-secondary) !important;
    margin-bottom: 0.375rem;
    letter-spacing: 0.01em;
}

.form-helper {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* ===== Tables ===== */
.table {
    font-size: 0.8125rem;
    margin: 0;
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--primary-50);
    --bs-table-striped-bg: transparent;
}

.table thead {
    background: var(--bg-body);
}

.table > thead > tr > th,
.table th {
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    text-transform: uppercase;
    font-size: 0.6875rem !important;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border) !important;
    border-top: none !important;
    padding: 0.75rem 1rem !important;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-body) !important;
}

.table > tbody > tr > td,
.table td {
    padding: 0.75rem 1rem !important;
    vertical-align: middle !important;
    border-color: var(--border-light) !important;
    color: var(--text-primary);
}

.table > tbody > tr,
.table tbody tr {
    transition: background var(--transition-fast);
}

.table > tbody > tr:hover,
.table tbody tr:hover {
    background: var(--primary-50) !important;
}

.table tbody tr:last-child td {
    border-bottom: none !important;
}

.table-actions {
    display: flex;
    gap: 0.375rem;
    justify-content: flex-end;
}

/* ===== Badges / Pills ===== */
.badge {
    font-weight: 500 !important;
    padding: 0.25em 0.625em !important;
    border-radius: 50rem !important;
    font-size: 0.6875rem !important;
    letter-spacing: 0.02em;
    text-transform: capitalize;
    display: inline-flex !important;
    align-items: center;
    gap: 0.25rem;
    border: none !important;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge-new       { background: #dbeafe; color: #1d4ed8; }
.badge-new::before { background: #3b82f6; }
.badge-contacted { background: #fef3c7; color: #92400e; }
.badge-contacted::before { background: #f59e0b; }
.badge-interested{ background: #e0e7ff; color: #4338ca; }
.badge-interested::before { background: #6366f1; }
.badge-converted { background: #dcfce7; color: #166534; }
.badge-converted::before { background: #22c55e; }
.badge-lost      { background: #fce7f3; color: #9d174d; }
.badge-lost::before { background: #ec4899; }
.badge-active    { background: #dcfce7; color: #166534; }
.badge-active::before { background: #22c55e; }
.badge-lapsed    { background: #fee2e2; color: #991b1b; }
.badge-lapsed::before { background: #ef4444; }
.badge-cancelled { background: #f1f5f9; color: #475569; }
.badge-cancelled::before { background: #94a3b8; }
.badge-renewed   { background: #dbeafe; color: #1d4ed8; }
.badge-renewed::before { background: #3b82f6; }
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-pending::before { background: #f59e0b; }
.badge-partial   { background: #e0e7ff; color: #4338ca; }
.badge-partial::before { background: #6366f1; }
.badge-received  { background: #dcfce7; color: #166534; }
.badge-received::before { background: #22c55e; }

/* Countdown badges (no dot) */
.badge-countdown {
    font-weight: 600;
    font-size: 0.6875rem;
    padding: 0.2em 0.5em;
}

.badge-countdown::before { display: none; }

.badge-countdown.urgent { background: #fee2e2; color: #dc2626; }
.badge-countdown.soon   { background: #fef3c7; color: #d97706; }
.badge-countdown.ok     { background: #dcfce7; color: #16a34a; }

/* ===== Auth Pages ===== */
.auth-card {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.03);
    padding: 2.5rem 2.25rem 2rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    font-size: 2.75rem;
    margin-bottom: 0.75rem;
    line-height: 1;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin: 0;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0.5rem 0 0;
}

.auth-footer {
    text-align: center;
    border-top: 1px solid var(--border-light);
    padding-top: 1rem;
    margin-top: 1.75rem;
}

/* ===== Page Headers ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header-info {
    flex: 1;
    min-width: 0;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-weight: 400;
}

.page-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    align-items: end;
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}

.filter-bar .form-control,
.filter-bar .form-select {
    max-width: 220px;
    background: var(--bg-body);
    border-color: var(--border-light);
}

.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
    background: var(--bg-card);
}

/* ===== Empty States ===== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3.5rem;
    margin-bottom: 1.25rem;
    opacity: 0.4;
    line-height: 1;
}

.empty-state-text {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.empty-state-subtext {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

/* ===== Loading Skeleton ===== */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 40%, #f1f5f9 80%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.8s ease-in-out infinite;
    border-radius: var(--radius);
}

@keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text { height: 0.875rem; margin-bottom: 0.5rem; border-radius: var(--radius-xs); }
.skeleton-text.short { width: 60%; }
.skeleton-card { height: 120px; }

.skeleton-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.skeleton-row .skeleton {
    height: 2.5rem;
    flex: 1;
    border-radius: var(--radius-sm);
}

/* Skeleton for KPI cards */
.skeleton-kpi {
    height: 140px;
    border-radius: var(--radius-lg);
}

/* Skeleton for tables */
.skeleton-table {
    height: 280px;
    border-radius: var(--radius-lg);
}

/* ===== Status Dots ===== */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.4rem;
}

.status-dot-active  { background: var(--success); }
.status-dot-pending { background: var(--warning); }
.status-dot-danger  { background: var(--danger); }

/* ===== Timeline ===== */
.timeline-item {
    display: flex;
    gap: 0.875rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition-fast);
}

.timeline-item:last-child {
    border-bottom: none;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 0.4rem;
    flex-shrink: 0;
    position: relative;
}

.timeline-dot::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 3px;
    width: 2px;
    height: calc(100% + 12px);
    background: var(--border-light);
}

.timeline-item:last-child .timeline-dot::after {
    display: none;
}

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-text {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
}

.timeline-meta {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.timeline-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

/* ===== Detail / Key-Value Rows ===== */
.detail-grid {
    display: grid;
    gap: 0;
}

.detail-row {
    display: flex;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.8125rem;
    gap: 1rem;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-muted);
    font-weight: 500;
    min-width: 140px;
    flex-shrink: 0;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== Follow-up Timeline ===== */
.followup-item {
    position: relative;
    padding-left: 1.5rem;
    padding-bottom: 1rem;
    margin-left: 0.25rem;
    border-left: 2px solid var(--border);
}

.followup-item:last-child {
    border-left-color: transparent;
}

.followup-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 0.2rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 0 2px var(--primary-100);
}

/* ===== Validation ===== */
.valid.modified:not([type=checkbox]) {
    outline: none;
    border-color: var(--success);
}

.invalid {
    outline: none;
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.validation-message {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* ===== Error Boundary ===== */
.blazor-error-boundary {
    background: var(--danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: var(--radius);
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* ===== Utilities ===== */
.text-primary-brand { color: var(--primary) !important; }
.bg-primary-brand   { background: var(--primary) !important; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-sm  { font-size: 0.8125rem; }
.fs-xs  { font-size: 0.6875rem; }
.fs-lg  { font-size: 1.125rem; }
.gap-3  { gap: 0.75rem; }
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Form Sticky Footer ===== */
.form-sticky-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    margin: 1.5rem -1.5rem -1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    z-index: 10;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 50rem; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeIn 0.3s ease forwards;
}

/* ===== Misc ===== */
.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

/* ===== Commission summary card ===== */
.commission-summary-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-xs);
    transition: all var(--transition);
}

.commission-summary-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.commission-summary-month {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid var(--border-light);
}

.commission-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.commission-summary-item label {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.125rem;
}

.commission-summary-item .amount {
    font-size: 1rem;
    font-weight: 700;
}

.commission-summary-item .amount.expected { color: var(--text-primary); }
.commission-summary-item .amount.received { color: var(--success); }
.commission-summary-item .amount.pending  { color: var(--warning); }
