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

html {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    min-height: 100%;
}

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --warning: #f59e0b;
    --purple: #8b5cf6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 260px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.login-box h2 {
    text-align: center;
    margin-bottom: 24px;
    color: var(--gray-800);
}

/* Form */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    opacity: 0.8;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 12px; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 0.85rem;
    opacity: 0.8;
}

.nav-menu {
    list-style: none;
    padding: 16px 0;
    flex: 1;
}

.nav-menu li a {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    gap: 12px;
}

.nav-menu li a:hover,
.nav-menu li a.active {
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-menu li a .icon {
    font-size: 1.2rem;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer p {
    margin-bottom: 12px;
    font-size: 0.9rem;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    min-height: 100vh;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page h1 {
    margin-bottom: 24px;
    font-size: 24px;
    color: var(--gray-800);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: var(--gray-100);
}

.stat-card.income .stat-icon { background: rgba(16,185,129,0.1); color: var(--success); }
.stat-card.expense .stat-icon { background: rgba(239,68,68,0.1); color: var(--danger); }
.stat-card.shared .stat-icon { background: rgba(139,92,246,0.1); color: var(--purple); }
.stat-card.balance .stat-icon { background: rgba(102,126,234,0.1); color: var(--primary); }

.stat-info h3 {
    font-size: 12px;
    color: var(--gray-500);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.stat-info p {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-800);
}

/* Card */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 20px;
    overflow: hidden;
}

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

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Table */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

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

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--gray-600);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-income { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-expense { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-telegram { background: rgba(0,136,204,0.1); color: #0088cc; }
.badge-web { background: rgba(139,92,246,0.1); color: var(--purple); }

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    background: white;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

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

.modal-header h2 {
    font-size: 18px;
}

.modal-body {
    padding: 20px;
}

.close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--gray-400);
    padding: 4px 8px;
    line-height: 1;
}

/* Invoice Link */
.invoice-link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

/* Telegram Info */
.telegram-info {
    background: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 100%);
    border-left: 4px solid #0ea5e9;
    padding: 20px;
    border-radius: 12px;
}

.telegram-info h3 {
    color: #0369a1;
    margin-bottom: 12px;
}

.telegram-info code {
    background: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
}

.telegram-info ul {
    margin: 12px 0;
    padding-left: 20px;
}

.telegram-info li {
    margin-bottom: 8px;
}

/* Action buttons */
.action-btns {
    display: flex;
    gap: 6px;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 150;
    padding: 0 16px;
    align-items: center;
    justify-content: center;
}

.mobile-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-weight: 600;
    font-size: 18px;
}

/* Bottom Navigation */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    border-top: 1px solid var(--gray-200);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 8px 0;
}

.bottom-nav-item .icon {
    font-size: 22px;
    line-height: 1;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item:active {
    background: var(--gray-50);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: var(--gray-800);
    color: white;
    border-radius: 10px;
    z-index: 2000;
    font-size: 14px;
    animation: toastIn 0.2s ease-out;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-400);
}

/* ========== MOBILE RESPONSIVE ========== */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }

    .mobile-header {
        display: flex;
    }

    .sidebar {
        display: none !important;
    }

    .bottom-nav {
        display: flex;
    }

    #main-app {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 66px 16px 76px 16px;
        min-height: auto;
    }

    .page h1 {
        font-size: 18px;
        text-align: center;
        margin-bottom: 16px;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
        gap: 12px;
        border-radius: 12px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
        border-radius: 10px;
        flex-shrink: 0;
    }

    .stat-info h3 {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .stat-info p {
        font-size: 15px;
    }

    /* Cards */
    .card {
        border-radius: 12px;
        margin-bottom: 16px;
    }

    .card-header {
        padding: 14px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .card-header h3 {
        text-align: center;
    }

    .card-header .btn {
        width: 100%;
        justify-content: center;
    }

    .card-body {
        padding: 0;
    }

    /* Table */
    .table-responsive {
        margin: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        font-size: 12px;
        min-width: 500px;
    }

    .data-table th,
    .data-table td {
        padding: 12px 10px;
    }

    .data-table th:first-child,
    .data-table td:first-child {
        padding-left: 16px;
    }

    .data-table .btn-sm {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Toolbar - Filters */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 16px;
    }

    .toolbar .btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
    }

    .filters {
        width: 100%;
        background: white;
        padding: 12px;
        border-radius: 10px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    }

    .filters input,
    .filters select {
        flex: 1;
        min-width: 0;
        padding: 12px;
        font-size: 14px;
        border: 1px solid var(--gray-200);
    }

    .filters input[type="date"] {
        text-align: center;
    }

    /* Modal */
    .modal.show {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
    }

    .modal-header {
        padding: 16px;
        border-radius: 16px 16px 0 0;
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
    }

    .modal-body {
        padding: 16px;
        padding-bottom: 32px;
    }

    /* Telegram Info */
    .telegram-info {
        padding: 16px;
        font-size: 14px;
    }

    .telegram-info h3 {
        font-size: 16px;
    }

    /* Toast */
    .toast {
        bottom: 76px;
        left: 16px;
        right: 16px;
        text-align: center;
    }

    /* Login */
    .login-box {
        padding: 28px 24px;
        margin: 16px;
        border-radius: 20px;
    }

    .login-box h2 {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .stat-info p {
        font-size: 14px;
    }

    .data-table {
        min-width: 450px;
    }
}
