:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --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;
    --bg: #ffffff;
    --bg-secondary: #f9fafb;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 240px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a5f;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #3b1c1c;
    --success: #22c55e;
    --success-light: #1a3a1a;
    --warning: #f59e0b;
    --warning-light: #3a2e0b;
    --gray-50: #1a1a2e;
    --gray-100: #1e1e36;
    --gray-200: #2d2d4a;
    --gray-300: #4a4a6a;
    --gray-400: #6b6b8a;
    --gray-500: #8b8baa;
    --gray-600: #a0a0bb;
    --gray-700: #c0c0d0;
    --gray-800: #e0e0e8;
    --gray-900: #f0f0f5;
    --bg: #0f0f23;
    --bg-secondary: #1a1a2e;
    --text: #e0e0e8;
    --text-secondary: #a0a0bb;
    --border: #2d2d4a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background var(--transition), color var(--transition);
}

input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
}

a { color: var(--primary); text-decoration: none; }

/* Login */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--gray-900) 0%, var(--bg) 50%, var(--gray-800) 100%);
}

.login-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-top: 12px;
}

.login-header p {
    color: var(--text-secondary);
    margin-top: 4px;
}

.login-logo {
    color: var(--primary);
}

.login-form .form-group {
    margin-bottom: 16px;
}

.btn-full {
    width: 100%;
    margin-top: 8px;
}

.form-error {
    color: var(--danger);
    font-size: 14px;
    margin-bottom: 12px;
    padding: 8px;
    background: var(--danger-light);
    border-radius: var(--radius);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--gray-100);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover { background: var(--gray-200); }

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover { background: var(--gray-100); }

.btn-icon svg { display: block; }

/* Form elements */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 16px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea { resize: vertical; min-height: 60px; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 10;
    transition: transform var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.sidebar-logo { color: var(--primary); }

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--text);
}

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

.nav-item svg { flex-shrink: 0; }

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

.user-info {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.page { animation: fadeIn 0.3s ease; }

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

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

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.summary-card .sc-title {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.summary-card .sc-value {
    font-size: 28px;
    font-weight: 700;
}

.summary-card .sc-sub {
    font-size: 12px;
    margin-top: 4px;
}

.sc-income .sc-value { color: var(--success); }
.sc-expense .sc-value { color: var(--danger); }
.sc-balance .sc-value { color: var(--primary); }
.sc-receivable .sc-value { color: var(--warning); }
.sc-payable .sc-value { color: var(--danger); }
.sc-count .sc-value { color: var(--text); }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    min-height: 300px;
}

.chart-card canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 250px;
}

/* Period Selector */
.period-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.period-btn:hover {
    background: var(--gray-100);
    color: var(--text);
}

.period-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.custom-period {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-period input {
    width: auto;
    padding: 4px 8px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

/* Tables */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

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

.table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--gray-50);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.table th:hover { color: var(--text); }

.table td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: var(--gray-50); }

.table .actions {
    display: flex;
    gap: 6px;
}

.table .badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-active {
    background: var(--success-light);
    color: var(--success);
}

.badge-inactive {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-pending {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-paid {
    background: var(--success-light);
    color: var(--success);
}

/* Search bar */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.search-bar input { flex: 1; }

.search-bar select { width: auto; min-width: 180px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--text-secondary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

.modal-lg { max-width: 680px; }
.modal-sm { max-width: 400px; }

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

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--text);
}

.modal-body { padding: 20px; }

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Transaction type selector */
.transaction-type-selector {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.radio-card {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg);
}

.radio-card:hover { border-color: var(--gray-400); }

.radio-card.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.radio-card input[type="radio"] {
    display: none;
}

.radio-card .radio-label {
    font-weight: 500;
    font-size: 15px;
}

.radio-group {
    display: flex;
    gap: 12px;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    z-index: 200;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.toast-success {
    background: var(--success);
    color: white;
}

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

.toast-info {
    background: var(--primary);
    color: white;
}

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Theme icons */
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: block; }

/* Recent list */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.recent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.recent-item:last-child { border-bottom: none; }

.recent-item .ri-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.recent-item .ri-name {
    font-size: 14px;
    font-weight: 500;
}

.recent-item .ri-sub {
    font-size: 12px;
    color: var(--text-secondary);
}

.recent-item .ri-amount {
    font-weight: 600;
    font-size: 14px;
}

.ri-income { color: var(--success); }
.ri-expense { color: var(--danger); }

/* Category manager */
.category-manager .form-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.category-manager .form-row input { flex: 1; }
.category-manager .form-row select { width: auto; }

.contact-cat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
}

.contact-cat-item .cat-name {
    font-size: 14px;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        max-width: 100vw;
        padding: 16px;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .period-selector {
        width: 100%;
    }

    .search-bar {
        flex-direction: column;
    }

    .search-bar select { width: 100%; }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 24px;
    }
}

/* Hamburger menu for mobile */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}
