/* ============================================
   EMI Tracker – Main Stylesheet
   Premium dark-sidebar, card-based UI
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
    --sidebar-w: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99,102,241,0.25);
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.1);
    --transition: all 0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--sidebar-border);
    transition: transform 0.3s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.brand-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800; color: #fff;
    box-shadow: 0 0 16px var(--accent-glow);
}

.brand-name { display: block; font-weight: 700; color: #f1f5f9; font-size: 15px; }
.brand-sub  { display: block; font-size: 10px; color: #475569; letter-spacing: .5px; }

.sidebar-nav { padding: 16px 12px; flex: 1; }

.nav-section-label {
    font-size: 10px; font-weight: 600; letter-spacing: 1px;
    color: #475569; padding: 12px 10px 6px; text-transform: uppercase;
}

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: #94a3b8; font-size: 13px; font-weight: 500;
    transition: var(--transition); margin-bottom: 2px;
    position: relative;
}

.nav-item:hover { background: #1e293b; color: #e2e8f0; }
.nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.1));
    color: #a5b4fc;
    border-left: 3px solid var(--accent);
}

.badge-count {
    margin-left: auto;
    background: var(--warning); color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 2px 7px; border-radius: 20px; min-width: 20px; text-align: center;
}
.badge-count.badge-red { background: var(--danger); }

.sidebar-footer {
    padding: 16px; border-top: 1px solid var(--sidebar-border);
    display: flex; align-items: center; gap: 10px;
}

.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
}

.user-name  { display: block; font-size: 13px; color: #e2e8f0; font-weight: 600; }
.user-role  { display: block; font-size: 10px; color: #64748b; }
.user-details { flex: 1; }

.logout-btn {
    color: #475569; padding: 6px;
    border-radius: 6px; transition: var(--transition);
}
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
    box-shadow: 0 1px 0 var(--border);
}

.sidebar-toggle { 
    display: none; 
    background: none; 
    border: none; 
    cursor: pointer; 
    color: var(--text-muted); 
    padding: 12px; 
    margin-left: -12px;
    border-radius: 8px;
}
.sidebar-toggle:active { background: var(--bg); }
.topbar-date { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

/* ── Page Content ── */
.page-content { padding: 28px 28px; flex: 1; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

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

.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 22px; }

/* ── Stat Cards ── */
.dashboard-section-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-section-label::after {
    content: '';
    height: 1px;
    flex: 1;
    background: var(--border);
}

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

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 18px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--accent); }

.stat-icon {
    width: 56px; height: 56px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; flex-shrink: 0;
    transition: var(--transition);
}

.stat-card:hover .stat-icon { transform: scale(1.1) rotate(-5deg); }

.stat-icon.indigo  { background: rgba(99,102,241,0.1);  color: var(--accent); }
.stat-icon.green   { background: rgba(16,185,129,0.1);  color: var(--success); }
.stat-icon.amber   { background: rgba(245,158,11,0.1);  color: var(--warning); }
.stat-icon.red     { background: rgba(239,68,68,0.1);   color: var(--danger); }
.stat-icon.blue    { background: rgba(59,130,246,0.1);  color: var(--info); }
.stat-icon.purple  { background: rgba(139,92,246,0.1);  color: #8b5cf6; }

.stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }

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

th {
    padding: 12px 16px; text-align: left;
    font-size: 11px; font-weight: 600; letter-spacing: .5px;
    text-transform: uppercase; color: var(--text-muted);
    background: var(--surface2); border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 13px 16px; border-bottom: 1px solid var(--border);
    font-size: 13.5px; color: var(--text); vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; letter-spacing: .3px;
}

.badge-due      { background: rgba(59,130,246,0.1);  color: var(--info); }
.badge-received { background: rgba(16,185,129,0.1);  color: var(--success); }
.badge-partial  { background: rgba(245,158,11,0.1);  color: var(--warning); }
.badge-overdue  { background: rgba(239,68,68,0.1);   color: var(--danger); }
.badge-active   { background: rgba(16,185,129,0.1);  color: var(--success); }
.badge-completed{ background: rgba(99,102,241,0.1);  color: var(--accent); }
.badge-defaulted{ background: rgba(239,68,68,0.1);   color: var(--danger); }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 18px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    border: none; transition: var(--transition); white-space: nowrap;
    font-family: inherit; text-align: center;
}

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px var(--accent-glow); }

.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }

.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

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

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 8px; }

.btn-whatsapp { background: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #128c7e; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

input[type=text], input[type=email], input[type=number], input[type=date],
input[type=tel], input[type=password], select, textarea {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit; font-size: 14px; color: var(--text);
    background: var(--surface); outline: none;
    transition: border-color .2s, box-shadow .2s;
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { resize: vertical; min-height: 90px; }
select { cursor: pointer; }

.form-hint { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* ── Search Bar ── */
.search-bar {
    position: relative; max-width: 340px;
}

.search-bar input {
    padding-left: 38px;
}

.search-bar svg {
    position: absolute; left: 11px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted); pointer-events: none;
}

/* ── Alerts ── */
.alert {
    padding: 12px 18px; border-radius: var(--radius-sm);
    margin-bottom: 20px; font-size: 13.5px; font-weight: 500;
    display: flex; align-items: center; gap: 10px;
    border-left: 4px solid transparent;
    animation: slideIn .3s ease;
}

.alert-success { background: rgba(16,185,129,0.1); color: #065f46; border-color: var(--success); }
.alert-error   { background: rgba(239,68,68,0.1);  color: #7f1d1d; border-color: var(--danger); }
.alert-warning { background: rgba(245,158,11,0.1); color: #78350f; border-color: var(--warning); }
.alert-info    { background: rgba(59,130,246,0.1); color: #1e3a5f; border-color: var(--info); }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    z-index: 1000; display: flex; align-items: center; justify-content: center;
    padding: 20px; opacity: 0; pointer-events: none; transition: opacity .25s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%; max-width: 520px;
    box-shadow: var(--shadow-md);
    transform: scale(0.95); transition: transform .25s;
    overflow: hidden;
}

.modal-overlay.open .modal { transform: scale(1); }

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

.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 22px; line-height: 1; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Progress Bar ── */
.progress-bar {
    height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 6px;
}
.progress-fill {
    height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6);
    border-radius: 99px; transition: width .4s ease;
}
.progress-fill.green { background: linear-gradient(90deg, var(--success), #34d399); }
.progress-fill.amber { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.progress-fill.red   { background: linear-gradient(90deg, var(--danger), #f87171); }

/* ── EMI Timeline ── */
.emi-timeline { display: flex; flex-direction: column; gap: 0; }

.emi-row {
    display: grid; grid-template-columns: 40px 1fr 140px 140px 120px 180px;
    align-items: center; gap: 12px;
    padding: 13px 18px; border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.emi-row:hover { background: var(--surface2); }
.emi-row:last-child { border-bottom: none; }

.emi-num {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg); border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: var(--text-muted);
    flex-shrink: 0;
}

.emi-num.received { border-color: var(--success); color: var(--success); background: rgba(16,185,129,0.08); }
.emi-num.partial  { border-color: var(--warning); color: var(--warning); background: rgba(245,158,11,0.08); }
.emi-num.overdue  { border-color: var(--danger);  color: var(--danger);  background: rgba(239,68,68,0.08); }

/* ── Auth pages ── */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}

.auth-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 44px 40px;
    width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.auth-logo {
    text-align: center; margin-bottom: 32px;
}

.auth-logo-icon {
    width: 60px; height: 60px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 800; color: #fff;
    box-shadow: 0 0 30px rgba(99,102,241,0.4);
    margin-bottom: 14px;
}

.auth-logo h1 { color: #f1f5f9; font-size: 22px; font-weight: 700; }
.auth-logo p  { color: #64748b; font-size: 13px; margin-top: 4px; }

.auth-card label { color: #94a3b8; }
.auth-card input { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); color: #f1f5f9; }
.auth-card input:focus { border-color: var(--accent); background: rgba(255,255,255,0.08); }
.auth-card input::placeholder { color: #475569; }

/* ── Responsive ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    backdrop-filter: blur(4px);
}
.sidebar-overlay.active { display: block; }

.sidebar-close {
    display: none;
    background: none; border: none; color: #64748b;
    padding: 8px; cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 100;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close { display: block; margin-left: auto; }
    .main-content {
        margin-left: 0;
    }
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .topbar { padding: 0 12px; }
    .topbar-date { display: none; }
    
    .page-content { padding: 16px 12px; }
    
    .stats-grid { grid-template-columns: 1fr; gap: 12px; }
    .stat-card { padding: 16px; }
    
    .form-grid { grid-template-columns: 1fr !important; gap: 16px; }
    .responsive-grid { grid-template-columns: 1fr !important; }
    
    .emi-row { 
        grid-template-columns: 1fr; 
        gap: 8px; 
        padding: 16px; 
        border-radius: 12px;
        margin-bottom: 10px;
        background: var(--surface2);
        border: 1px solid var(--border);
    }
    .emi-row > div { display: flex; justify-content: space-between; align-items: center; }
    .emi-row > div > div:first-child { font-size: 11px; }
    .emi-row .text-right { justify-content: flex-start !important; margin-top: 4px; }
    .emi-row .btn { width: 100%; justify-content: center; }
    
    .table-wrapper {
        margin: 0 -12px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .page-header .flex {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }
    .page-header .btn {
        width: 100%;
        justify-content: center;
    }
    
    .card-body { padding: 16px; }
    .dashboard-section-label { font-size: 11px; }
    
    .form-group.full { grid-column: auto; }
    
    /* Document previews on mobile */
    .doc-images { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .page-title { font-size: 18px; }
    .btn { padding: 8px 12px; font-size: 12px; }
    .stat-value { font-size: 20px; }
}

/* ── Utility ── */
.flex-responsive { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-bold    { font-weight: 700; }
.flex         { display: flex; align-items: center; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.gap-4        { gap: 16px; }
.mt-4         { margin-top: 16px; }
.mb-4         { margin-bottom: 16px; }
.text-right   { text-align: right; }
.empty-state  { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 52px; height: 52px; margin-bottom: 16px; opacity: .3; }
.empty-state h3 { font-size: 17px; margin-bottom: 8px; color: var(--text); }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab-btn {
    padding: 8px 18px; border-radius: 8px; border: none; cursor: pointer;
    font-size: 13px; font-weight: 500; background: transparent; color: var(--text-muted);
    transition: var(--transition); font-family: inherit;
}
.tab-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); font-weight: 600; }

/* ── Reports ── */
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.report-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px;
    display: flex; flex-direction: column; gap: 12px;
    transition: var(--transition); cursor: pointer;
    text-decoration: none;
}
.report-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--accent); }
.report-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}
.report-icon svg { width: 22px; height: 22px; }
.report-title { font-size: 14px; font-weight: 600; }
.report-desc  { font-size: 12px; color: var(--text-muted); }
