/* ============================================================
   KhataPro — Premium Design System
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Design Tokens --- */
:root {
    --font: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Palette */
    --indigo: #6366f1;
    --indigo-dark: #4f46e5;
    --indigo-light: #a5b4fc;
    --cyan: #06b6d4;
    --emerald: #10b981;
    --emerald-dark: #059669;
    --rose: #f43f5e;
    --amber: #f59e0b;
    --violet: #8b5cf6;

    /* Light Theme */
    --bg: #f1f5f9;
    --bg-2: #e8eef5;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: rgba(99,102,241,0.15);
    --sidebar-active-text: #a5b4fc;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 20px 60px rgba(0,0,0,.12), 0 8px 20px rgba(0,0,0,.06);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --sidebar-width: 250px;
    --header-h: 72px;
    --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark {
    --bg: #0b0f1a;
    --bg-2: #111827;
    --surface: #161d2e;
    --surface-2: #1e2a3e;
    --sidebar-bg: #090d18;
    --sidebar-text: #64748b;
    --sidebar-active: rgba(99,102,241,0.2);
    --sidebar-active-text: #818cf8;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #475569;
    --border: #1e2a3e;
    --border-strong: #2d3f5a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow: 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg: 0 20px 60px rgba(0,0,0,.6);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; }

/* --- Layout --- */
#app-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 20px 12px;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .sidebar-footer .footer-copy,
.sidebar.collapsed .theme-switch-row { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px; }
.sidebar.collapsed .brand-icon { margin: 0 auto; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 24px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    margin-bottom: 16px;
}
.brand-icon {
    width: 40px; height: 40px;
    flex-shrink: 0;
    border-radius: 10px;
    overflow: hidden;
}
.brand-icon svg { display: block; width: 100%; height: 100%; }
.brand-text { overflow: hidden; white-space: nowrap; transition: var(--transition); }
.brand-name {
    display: block;
    font-weight: 700;
    font-size: 1rem;
    color: #f1f5f9;
    line-height: 1.2;
}
.brand-tagline {
    font-size: 0.7rem;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: .08em;
}

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; }
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 10px; }

.nav-group-label {
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: .1em;
    color: var(--sidebar-text);
    padding: 6px 10px 4px;
    transition: var(--transition);
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition);
    margin-bottom: 2px;
    position: relative;
    white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #e2e8f0; }
.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-text);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--indigo);
    border-radius: 0 4px 4px 0;
}
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; display: flex; }
.nav-icon svg { width: 100%; height: 100%; }
.nav-label { flex: 1; transition: var(--transition); }
.nav-badge {
    background: var(--indigo);
    color: white;
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 20px;
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
    transition: var(--transition);
}
.nav-badge.danger { background: var(--rose); }
.nav-badge:empty { display: none; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.06);
    padding-top: 16px;
    margin-top: 8px;
    overflow: hidden;
}
.theme-switch-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
    color: var(--sidebar-text);
    transition: var(--transition);
}
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(255,255,255,.15);
    border-radius: 20px;
    transition: var(--transition);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    left: 3px; top: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--indigo); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.footer-copy {
    font-size: 0.72rem;
    color: var(--sidebar-text);
    text-align: center;
    transition: var(--transition);
}

/* --- Sidebar Mobile Toggle --- */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 16px; left: 16px;
    z-index: 200;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    box-shadow: var(--shadow);
    color: var(--text);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: margin-left var(--transition);
    display: flex;
    flex-direction: column;
}
.main-content.sidebar-collapsed { margin-left: 68px; }

.main-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(241,245,249,.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    transition: background var(--transition);
}
body.dark .main-header { background: rgba(11,15,26,.85); }

.header-left h1 {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}
.header-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- Global Search --- */
.search-bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    color: var(--text-muted);
    transition: border var(--transition), box-shadow var(--transition);
    width: 260px;
}
.search-bar:focus-within {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.search-bar input {
    border: none;
    background: transparent;
    font-size: 0.9rem;
    color: var(--text);
    outline: none;
    width: 100%;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
}
.search-dropdown.hidden { display: none; }
.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.88rem;
}
.search-result-item:hover { background: var(--bg); }
.search-result-item .result-icon { width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.search-result-item .result-name { font-weight: 600; }
.search-result-item .result-sub { color: var(--text-muted); font-size: 0.8rem; }

#view-container { padding: 24px 28px; flex: 1; }
@keyframes fadeSlideIn { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }
#view-container > * { animation: fadeSlideIn .35s ease; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: var(--indigo);
    color: white;
    box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.btn-primary:hover { background: var(--indigo-dark); box-shadow: 0 6px 18px rgba(99,102,241,.4); }
.btn-success {
    background: var(--emerald);
    color: white;
    box-shadow: 0 4px 12px rgba(16,185,129,.3);
}
.btn-success:hover { background: var(--emerald-dark); }
.btn-danger {
    background: var(--rose);
    color: white;
    box-shadow: 0 4px 12px rgba(244,63,94,.3);
}
.btn-danger:hover { background: #e11d48; }
.btn-outline {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-outline:hover { border-color: var(--indigo); color: var(--indigo); background: rgba(99,102,241,.05); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon-only { padding: 8px; }
.w-full { width: 100%; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    transition: border var(--transition), box-shadow var(--transition), background var(--transition);
    margin-bottom: 20px;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   DASHBOARD
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 22px;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
    cursor: default;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: .06;
    background: var(--stat-color, var(--indigo));
}
.stat-card-glow {
    position: absolute;
    top: -20px; right: -20px;
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--stat-color, var(--indigo));
    opacity: .12;
    filter: blur(20px);
}
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--stat-color, var(--indigo));
    color: white;
    margin-bottom: 16px;
}
.stat-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1.1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stat-change { font-size: 0.78rem; color: var(--text-muted); }
.stat-change.up { color: var(--emerald); }
.stat-change.down { color: var(--rose); }

/* Dashboard quick actions */
.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.quick-action-card {
    flex: 1;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}
.quick-action-card:hover { border-color: var(--indigo); color: var(--indigo); background: rgba(99,102,241,.04); transform: translateY(-2px); box-shadow: var(--shadow); }
.quick-action-card svg { color: var(--indigo); }
.qa-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    background: rgba(99,102,241,.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.quick-action-card:hover .qa-icon { background: var(--indigo); color: white; }

/* Recent Transactions Table */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    transition: background var(--transition);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-2); }
.data-table tr.clickable { cursor: pointer; }
.amount-credit { color: var(--rose); font-weight: 600; font-family: var(--font-mono); }
.amount-payment { color: var(--emerald); font-weight: 600; font-family: var(--font-mono); }
.amount-neutral { color: var(--text-muted); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
}
.badge-success { background: rgba(16,185,129,.12); color: var(--emerald); }
.badge-danger { background: rgba(244,63,94,.12); color: var(--rose); }
.badge-warning { background: rgba(245,158,11,.12); color: var(--amber); }
.badge-info { background: rgba(6,182,212,.12); color: var(--cyan); }
.badge-neutral { background: var(--bg-2); color: var(--text-muted); }

/* ============================================================
   CUSTOMER LIST
   ============================================================ */
.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.toolbar-search {
    flex: 1;
    min-width: 200px;
    position: relative;
    display: flex;
    align-items: center;
}
.toolbar-search svg {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}
.toolbar-search input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition), box-shadow var(--transition);
}
.toolbar-search input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.toolbar select {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
}

.customer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.customer-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.customer-card:hover {
    border-color: var(--indigo);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}
.customer-card-top { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.customer-avatar {
    width: 52px; height: 52px;
    border-radius: 14px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--indigo), var(--cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
    flex-shrink: 0;
    border: 2px solid var(--border);
}
.customer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.customer-info { flex: 1; min-width: 0; }
.customer-name { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-phone { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.customer-card-balance {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.customer-card-balance .bal-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.customer-card-balance .bal-amount { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bal-positive { color: var(--rose); }
.bal-negative { color: var(--emerald); }
.bal-zero { color: var(--text-muted); }

.tag-vip { position: absolute; top: 14px; right: 14px; }

/* ============================================================
   CUSTOMER DETAIL
   ============================================================ */
.detail-header-card {
    background: linear-gradient(135deg, var(--indigo), var(--cyan));
    border-radius: var(--radius-xl);
    padding: 28px;
    color: white;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.detail-header-card::after {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
}
.detail-header-top { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; }
.detail-avatar {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 800;
    border: 3px solid rgba(255,255,255,.3);
    overflow: hidden;
    flex-shrink: 0;
}
.detail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.detail-customer-name { font-size: 1.5rem; font-weight: 800; }
.detail-customer-phone { opacity: .8; font-size: 0.9rem; margin-top: 2px; }
.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.detail-stat { background: rgba(255,255,255,.12); border-radius: var(--radius); padding: 14px; text-align: center; backdrop-filter: blur(8px); }
.detail-stat-label { font-size: 0.7rem; opacity: .75; text-transform: uppercase; letter-spacing: .06em; }
.detail-stat-value { font-size: 1.3rem; font-weight: 800; margin-top: 2px; }

.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }

/* ============================================================
   ANALYTICS
   ============================================================ */
.chart-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
}
.chart-title { font-weight: 700; font-size: 1rem; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
canvas { max-height: 300px; }

/* ============================================================
   FORMS & MODALS
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.open { display: flex; }
@keyframes modalIn { from { opacity:0; transform: scale(.94) translateY(16px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 100%;
    max-width: 520px;
    position: relative;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    animation: modalIn .3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 92vh;
    overflow-y: auto;
}
.modal-content::-webkit-scrollbar { width: 4px; }
.modal-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.modal-close-btn {
    position: absolute;
    top: 20px; right: 20px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close-btn:hover { background: var(--rose); color: white; border-color: var(--rose); }
.modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}
.modal-icon-wrap {
    width: 48px; height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.modal-header h2 { font-size: 1.3rem; font-weight: 700; }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition), box-shadow var(--transition);
    resize: vertical;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
    background: var(--surface);
}
.form-group small { display: block; margin-top: 5px; font-size: 0.78rem; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Avatar Upload */
.avatar-upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding: 20px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    transition: border var(--transition);
}
.avatar-upload-zone:hover { border-color: var(--indigo); }
.avatar-preview-wrap {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--bg-2);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 2px solid var(--border);
}
.avatar-preview-wrap img { width: 100%; height: 100%; object-fit: cover; }
.upload-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-2);
    border: 1px solid var(--border);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    transition: all var(--transition);
}
.upload-label:hover { background: var(--indigo); color: white; border-color: var(--indigo); }

/* Transaction type tabs */
.transaction-type-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
    margin-bottom: 20px;
}
.type-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
}
.type-tab.active[data-type="credit"] { background: var(--rose); color: white; box-shadow: 0 4px 12px rgba(244,63,94,.3); }
.type-tab.active[data-type="payment"] { background: var(--emerald); color: white; box-shadow: 0 4px 12px rgba(16,185,129,.3); }
.type-tab:not(.active):hover { background: var(--border); color: var(--text); }

/* Large amount input */
.amount-display-group {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, rgba(99,102,241,.05), rgba(6,182,212,.05));
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 18px;
    transition: border var(--transition);
}
.amount-display-group:focus-within { border-color: var(--indigo); }
.currency-display {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-muted);
    margin-right: 8px;
    font-family: var(--font-mono);
}
.amount-input-large {
    flex: 1;
    border: none !important;
    background: transparent !important;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text);
    outline: none !important;
    font-family: var(--font-mono);
}
.amount-input-large::placeholder { color: var(--border-strong); }

/* Confirm Dialog */
.confirm-modal-content { max-width: 380px; text-align: center; }
.confirm-icon { margin: 0 auto 16px; display: flex; justify-content: center; }
.confirm-modal-content h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; }
.confirm-modal-content p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .btn { flex: 1; }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}
.settings-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   REMINDERS VIEW
   ============================================================ */
.reminder-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    transition: all var(--transition);
}
.reminder-item:hover { border-color: var(--indigo); }
.reminder-item.overdue { border-color: var(--rose); background: rgba(244,63,94,.04); }
.reminder-priority-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.priority-high { background: var(--rose); }
.priority-medium { background: var(--amber); }
.priority-low { background: var(--emerald); }
.reminder-body { flex: 1; min-width: 0; }
.reminder-name { font-weight: 700; font-size: 0.9rem; }
.reminder-msg { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-due { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.reminder-due.overdue { color: var(--rose); }
.reminder-actions { display: flex; gap: 4px; }

/* ============================================================
   REPORTS VIEW
   ============================================================ */
.report-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 14px;
}
.report-card:hover { border-color: var(--indigo); box-shadow: var(--shadow); transform: translateX(4px); }
.report-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.report-info { flex: 1; }
.report-title { font-weight: 700; font-size: 1rem; }
.report-desc { font-size: 0.83rem; color: var(--text-muted); margin-top: 3px; }

/* ============================================================
   TRANSACTIONS VIEW
   ============================================================ */
.txn-filter-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.filter-chip {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
}
.filter-chip.active, .filter-chip:hover { border-color: var(--indigo); color: var(--indigo); background: rgba(99,102,241,.07); }
.filter-chip.credit.active { border-color: var(--rose); color: var(--rose); background: rgba(244,63,94,.07); }
.filter-chip.payment.active { border-color: var(--emerald); color: var(--emerald); background: rgba(16,185,129,.07); }

/* ============================================================
   TOAST
   ============================================================ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius);
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    pointer-events: all;
    min-width: 260px;
    max-width: 380px;
    animation: toastIn .35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes toastIn { from { opacity:0; transform: translateX(120%) scale(.8); } to { opacity:1; transform: translateX(0) scale(1); } }
.toast-out { animation: toastOut .25s ease forwards; }
@keyframes toastOut { to { opacity:0; transform: translateX(120%); } }
.toast.success { background: linear-gradient(135deg, var(--emerald), #047857); }
.toast.error { background: linear-gradient(135deg, var(--rose), #be123c); }
.toast.info { background: linear-gradient(135deg, var(--indigo), var(--violet)); }
.toast.warning { background: linear-gradient(135deg, var(--amber), #d97706); }
.toast-icon { flex-shrink: 0; }

/* ============================================================
   LOADING
   ============================================================ */
#loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}
#loading-overlay.active { display: flex; }
.loader-ring {
    width: 52px; height: 52px;
    border-radius: 50%;
    border: 4px solid rgba(99,102,241,.2);
    border-top-color: var(--indigo);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 40px;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 80px; height: 80px;
    border-radius: 20px;
    background: var(--bg-2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: var(--text-light);
}
.empty-state h3 { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 0.875rem; max-width: 300px; margin: 0 auto 20px; }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    .sidebar, .main-header, .detail-actions, #toast-container, #loading-overlay { display: none !important; }
    .main-content { margin-left: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    body { background: white; color: black; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .sidebar {
        width: 260px;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .sidebar-toggle { display: flex; }
    .main-header { padding: 0 16px 0 56px; }
    #view-container { padding: 16px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
    .customer-grid { grid-template-columns: 1fr; }
    .search-bar { width: 180px; }
    .detail-stats { grid-template-columns: 1fr 1fr; }
    .quick-actions { grid-template-columns: repeat(2, 1fr); display: grid; }
    .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .header-actions .btn span { display: none; }
    .modal-content { padding: 20px; }
    .detail-stats { grid-template-columns: 1fr; }
    .search-bar { display: none; }
}

/* ============================================================
   AI APPS PROMO BANNER (Sidebar)
   ============================================================ */
.ai-apps-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(99,102,241,.25), rgba(6,182,212,.25));
    border: 1px solid rgba(99,102,241,.35);
    text-decoration: none;
    margin-bottom: 14px;
    transition: all var(--transition);
    overflow: hidden;
    position: relative;
}
.ai-apps-banner::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(99,102,241,.15), rgba(6,182,212,.15));
    opacity: 0;
    transition: opacity var(--transition);
}
.ai-apps-banner:hover::before { opacity: 1; }
.ai-apps-banner:hover { border-color: rgba(99,102,241,.6); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(99,102,241,.2); }
.ai-apps-banner-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99,102,241,.4);
}
.ai-apps-banner-text { overflow: hidden; transition: var(--transition); }
.ai-apps-banner-title {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: #a5b4fc;
    white-space: nowrap;
}
.ai-apps-banner-sub {
    display: block;
    font-size: 0.68rem;
    color: rgba(148,163,184,.7);
    white-space: nowrap;
}
.sidebar.collapsed .ai-apps-banner-text { opacity: 0; width: 0; }
.sidebar.collapsed .ai-apps-banner { padding: 10px; justify-content: center; }

/* ============================================================
   FLOATING AI APPS BUTTON
   ============================================================ */
.floating-ai-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    color: white;
    text-decoration: none;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: 0 8px 28px rgba(99,102,241,.45);
    transition: all var(--transition);
    white-space: nowrap;
}
.floating-ai-btn:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 14px 36px rgba(99,102,241,.55);
}
.floating-ai-btn:active { transform: translateY(0) scale(.98); }
.floating-ai-pulse {
    position: absolute;
    inset: -3px;
    border-radius: 50px;
    border: 2px solid rgba(99,102,241,.5);
    animation: pulse-ring 2s ease-out infinite;
    pointer-events: none;
}
@keyframes pulse-ring {
    0%   { transform: scale(1);    opacity: .8; }
    70%  { transform: scale(1.12); opacity: 0; }
    100% { transform: scale(1.12); opacity: 0; }
}

/* On desktop (sidebar visible), hide the floating button to avoid duplicate */
@media (min-width: 769px) {
    .floating-ai-btn { display: none; }
}

/* ============================================================
   MOBILE FIXES — Full Responsiveness
   ============================================================ */

/* ── Overlay when mobile sidebar is open ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ── Base mobile layout ── */
@media (max-width: 768px) {
    :root { --header-h: 60px; }

    /* Sidebar: off-canvas */
    .sidebar {
        width: 270px !important;
        transform: translateX(-100%);
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 200;
        transition: transform var(--transition);
        padding: 16px 10px;
    }
    .sidebar.mobile-open { transform: translateX(0) !important; }

    /* Main content: full width */
    .main-content { margin-left: 0 !important; width: 100%; }

    /* Sidebar toggle button */
    .sidebar-toggle {
        display: flex !important;
        position: fixed;
        top: 12px; left: 12px;
        z-index: 150;
        padding: 9px;
        border-radius: 10px;
        background: var(--surface);
        border: 1px solid var(--border);
        box-shadow: var(--shadow);
        color: var(--text);
        align-items: center;
        justify-content: center;
    }

    /* Header */
    .main-header {
        padding: 0 12px 0 54px;
        height: var(--header-h);
        gap: 8px;
    }
    .header-left h1 { font-size: 1.1rem; }
    .header-date { display: none; }

    /* Search bar — compact on mobile */
    .search-bar { width: auto; flex: 1; min-width: 0; }
    .search-bar input { font-size: 0.82rem; }

    /* Header action buttons */
    .header-actions { gap: 6px; }
    .header-actions .btn span { display: none; }
    .header-actions .btn { padding: 8px 10px; }
    .header-actions .btn svg { width: 18px; height: 18px; }

    /* View container */
    #view-container { padding: 12px 12px 100px; }

    /* Stat cards: 2 col on mobile */
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-value { font-size: 1.4rem; }
    .stat-icon { width: 36px; height: 36px; border-radius: 10px; margin-bottom: 10px; }
    .stat-card { padding: 16px 14px; }

    /* Quick actions: 3 col on mobile */
    .quick-actions {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .quick-action-card {
        padding: 14px 8px;
        font-size: 0.72rem;
        gap: 6px;
        min-width: unset;
    }
    .qa-icon { width: 34px; height: 34px; border-radius: 8px; }
    .qa-icon svg { width: 18px; height: 18px; }

    /* Cards */
    .card { padding: 16px; border-radius: 14px; }
    .card-header { margin-bottom: 14px; }
    .card-title { font-size: 0.9rem; }

    /* Customer grid: 1 col */
    .customer-grid { grid-template-columns: 1fr; gap: 10px; }
    .customer-card { padding: 16px; }

    /* Toolbar */
    .toolbar { flex-wrap: wrap; gap: 8px; }
    .toolbar-search { min-width: 100%; order: -1; }
    .toolbar select { flex: 1; font-size: 0.8rem; padding: 8px 10px; }

    /* Detail header */
    .detail-header-card { padding: 20px 16px; border-radius: 16px; }
    .detail-header-top { gap: 14px; }
    .detail-avatar { width: 56px; height: 56px; border-radius: 14px; }
    .detail-customer-name { font-size: 1.2rem; }
    .detail-stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .detail-stat { padding: 10px 8px; }
    .detail-stat-value { font-size: 1rem; }
    .detail-stat-label { font-size: 0.65rem; }

    /* Detail actions: wrap nicely */
    .detail-actions { gap: 8px; }
    .detail-actions .btn { flex: 1; min-width: calc(50% - 4px); font-size: 0.78rem; padding: 9px 8px; }
    .detail-actions .btn svg { width: 14px; height: 14px; }

    /* Tables: horizontal scroll */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { min-width: 560px; }
    .data-table th, .data-table td { padding: 10px 10px; font-size: 0.8rem; }

    /* Transaction filter bar */
    .txn-filter-bar { gap: 6px; }
    .filter-chip { font-size: 0.75rem; padding: 5px 12px; }

    /* Modals */
    .modal { padding: 12px; align-items: flex-end; }
    .modal-content {
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        padding: 24px 20px 32px;
        animation: modalSlideUp .3s cubic-bezier(0.34, 1.56, 0.64, 1);
        max-height: 92vh;
    }
    @keyframes modalSlideUp {
        from { opacity:0; transform: translateY(60px); }
        to   { opacity:1; transform: translateY(0); }
    }
    .modal-close-btn { top: 16px; right: 16px; }
    .modal-header { margin-bottom: 18px; }
    .modal-header h2 { font-size: 1.1rem; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .amount-input-large { font-size: 1.6rem; }
    .currency-display { font-size: 1.6rem; }
    .transaction-type-tabs { margin-bottom: 14px; }
    .type-tab { font-size: 0.8rem; padding: 9px 6px; }

    /* Reports */
    .report-card { padding: 16px; }
    .report-icon { width: 44px; height: 44px; border-radius: 10px; }
    .report-title { font-size: 0.9rem; }

    /* Settings grid */
    .settings-grid { grid-template-columns: 1fr; gap: 14px; }

    /* Analytics charts */
    .chart-grid { grid-template-columns: 1fr; gap: 14px; }
    .chart-card { padding: 16px; }

    /* Reminders */
    .reminder-item { padding: 12px; gap: 10px; }
    .reminder-due { font-size: 0.72rem; }

    /* Back button */
    #back-to-customers { margin-bottom: 10px; }

    /* Toast */
    #toast-container { top: auto; bottom: 80px; right: 12px; left: 12px; }
    .toast { min-width: unset; max-width: 100%; font-size: 0.82rem; padding: 10px 14px; }

    /* Floating AI button adjustments on mobile */
    .floating-ai-btn {
        bottom: 16px;
        right: 16px;
        padding: 10px 16px;
        font-size: 0.8rem;
        box-shadow: 0 6px 22px rgba(99,102,241,.5);
    }
}

/* ── Extra small phones ── */
@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .detail-stats { grid-template-columns: 1fr 1fr; }
    .detail-actions .btn { font-size: 0.72rem; padding: 8px 6px; }
    .main-header { padding: 0 10px 0 50px; }
    .header-actions .btn { padding: 7px 9px; }
    .search-bar { display: none; }
    .card { padding: 14px; }
    .stat-value { font-size: 1.25rem; }
    .data-table { min-width: 480px; }
}

/* ── Landscape phones ── */
@media (max-width: 768px) and (orientation: landscape) {
    .modal { align-items: center; }
    .modal-content { border-radius: 16px; max-height: 88vh; }
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
}


/* Ensure the link container aligns items in a row */
.nav-link {
    display: flex;
    align-items: center;
    gap: 15px; /* adjust spacing between icon and text */
    text-decoration: none;
    padding: 10px 20px;
    color: #ffffff; /* Use your theme color variable here */
}

/* Ensure the icon is the correct size */
.nav-icon svg {
    width: 20px;
    height: 20px;
}