:root {
    --primary-color: #20c997; /* Mint Green */
    --primary-dark: #1aa179;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --danger-color: #dc3545;
    --success-color: #28a745;
    --border-color: #e9ecef;
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
    --table-header-bg: #f8f9fa;
    --hover-bg: #f0fdf9;
    --modal-bg: white;
    --input-bg: #fff;
    --input-border: #ddd;
    --record-submit-bg: linear-gradient(135deg, #20c997 0%, #1aa179 100%);
    --tab-inactive-bg: #f1f3f5;
    --tab-active-bg: #e6fcf5;
}

[data-theme="dark"] {
    --primary-color: #20c997;
    --primary-dark: #1aa179;
    --text-color: #e9ecef;
    --text-light: #adb5bd;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --danger-color: #ff6b6b;
    --success-color: #51cf66;
    --border-color: #2d2d2d;
    --shadow: 0 4px 6px rgba(0,0,0,0.3);
    --table-header-bg: #252525;
    --hover-bg: #2d2d2d;
    --modal-bg: #1e1e1e;
    --input-bg: #2d2d2d;
    --input-border: #404040;
    --record-submit-bg: linear-gradient(135deg, #1aa179 0%, #128260 100%);
    --tab-inactive-bg: #252525;
    --tab-active-bg: #122c24;
}

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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
    height: 100vh;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 250px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: background-color 0.3s, border-color 0.3s;
    height: 100%;
    overflow-y: auto;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    height: 100%;
}

/* Sidebar */
.logo {
    padding: 0 20px 20px;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
}

.nav-links {
    list-style: none;
    margin-top: 20px;
    flex: 1;
}

.nav-links li {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-light);
}

.nav-links li:hover, .nav-links li.active {
    background-color: var(--hover-bg);
    color: var(--primary-color);
    border-right: 3px solid var(--primary-color);
}

.nav-links li i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    padding: 0 20px 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer div {
    padding: 12px 0;
    cursor: pointer;
    color: var(--text-light);
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.sidebar-footer div:hover {
    color: var(--primary-color);
}

.sidebar-footer div i, .sidebar-footer div span {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

/* Header */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.header-bar h2 {
    font-size: 1.5rem;
}

.header-bar .actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Accounts Grid */
.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.account-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s;
    border: 1px solid transparent;
}

.account-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
    border-color: var(--primary-color);
}

.account-card h3 {
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.account-card .meta {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 15px;
}

.account-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item.income { color: var(--success-color); }
.stat-item.expense { color: var(--danger-color); }
.stat-item.balance { color: var(--text-color); font-weight: bold; }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    transition: background-color 0.3s;
}

.card h3 {
    margin-bottom: 20px;
    font-size: 1.1rem;
    color: var(--text-color);
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s;
    background-color: var(--input-bg);
    color: var(--text-color);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(32, 201, 151, 0.15);
}

.form-row {
    display: flex;
    gap: 20px;
    align-items: flex-end;
}

.form-group.half {
    flex: 1;
}

/* Pill Style Radio Group */
.radio-group {
    display: flex;
    background: var(--bg-color);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    margin-bottom: 0;
    height: 48px;
}

.radio-label {
    flex: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 0.95rem;
    color: var(--text-light);
    border: none;
    margin: 0;
    font-weight: 500;
    /* shireli */
    text-align: center;
    margin-bottom: unset !important;
    line-height: 40px;
}

.radio-label input {
    display: none;
}

.radio-label:hover {
    color: var(--text-color);
    background: transparent;
}

.radio-label:has(input:checked) {
    background: var(--card-bg);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: none;
}

.radio-label.income:has(input:checked) {
    color: var(--success-color);
}

.radio-label.expense:has(input:checked) {
    color: var(--danger-color);
}

/* Buttons */
.btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { 
    background: var(--record-submit-bg); 
    color: white; 
    box-shadow: 0 4px 10px rgba(32, 201, 151, 0.3);
}

.btn-danger { background: var(--danger-color); color: white; }
.btn-secondary { background: var(--border-color); color: var(--text-color); }
.btn-sm { padding: 8px 15px; font-size: 0.9rem; }

.full-width { width: 100%; }

.input-group {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: var(--bg-color);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    width: 46px;
    cursor: pointer;
    color: var(--primary-color);
    transition: all 0.2s;
}
.btn-icon:hover { 
    background: var(--hover-bg); 
    border-color: var(--primary-color);
}

/* Stats Container */
.stats-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.summary-cards {
    display: grid;
    /* 自适应卡片数量，方便新增“目标金额”等卡片 */
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 36px;
}

.mini-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    text-align: center;
    transition: background-color 0.3s;
}

.mini-card span { font-size: 0.9rem; color: var(--text-light); }
.mini-card h3 { font-size: 1.5rem; margin-top: 5px; }
.mini-card.income h3 { color: var(--success-color); }
.mini-card.expense h3 { color: var(--danger-color); }
.mini-card.target h3 { color: var(--primary-color); }

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

.table {
    width: 100%;
    border-collapse: collapse;
    /* min-width: 600px; */
}

.table th, .table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

.table th {
    background-color: var(--table-header-bg);
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tr:hover {
    background-color: var(--hover-bg);
}

.text-right { text-align: right; }

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

.action-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.action-btn:hover { 
    color: var(--danger-color); 
    background: rgba(220, 53, 69, 0.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    padding: 20px;
}

/* 重要提示类弹窗始终在所有弹窗之上（如：新增员工失败时的提示框） */
#modal-alert,
#modal-confirm,
#modal-delete-auth {
    z-index: 1100;
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 30px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    position: relative;
    color: var(--text-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-height: 90vh;
    overflow-y: auto;
}

.close {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.2s;
}
.close:hover { color: var(--text-color); }

.voice-status {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--primary-color);
    text-align: center;
    min-height: 20px;
}

/* Badge/Tag */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
}

.badge.admin { background: var(--danger-color); }
.badge.employee { background: var(--success-color); }

/* Mobile Responsive - Enhanced */
@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
    }

    /* Dashboard 卡片跨列在移动端会导致布局异常，强制重置为单列 */
    #view-dashboard .card[style*="grid-column"],
    #view-dashboard .card.summary-wrapper {
        grid-column: auto !important;
        width: 100%;
    }

    /* Dashboard 图表高度适配手机 */
    #view-dashboard .chart-wrapper {
        height: 240px !important;
    }

    /* Dashboard 区块之间的间距与满宽 */
    #view-dashboard .dashboard-grid {
        width: 100%;
        gap: 15px;
    }

    #view-dashboard .card {
        width: 100%;
        margin-bottom: 0;
    }

    /* Dashboard 表格在手机端保持横向滚动（避免被卡片化表格样式影响可读性） */
    #view-dashboard .table thead {
        display: table-header-group !important;
    }

    #view-dashboard .table tbody tr {
        display: table-row !important;
        background: transparent;
        border: none;
        border-radius: 0;
        margin-bottom: 0;
        padding: 0;
        box-shadow: none;
    }

    #view-dashboard .table td {
        display: table-cell !important;
        padding: 12px 10px;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
    }

    #view-dashboard .table td::before {
        content: none !important;
    }

    #view-dashboard .table-responsive {
        overflow-x: auto !important;
    }

    #view-dashboard .table {
        min-width: 520px;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        padding: 10px 15px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        height: 60px; /* Fixed header height */
        flex-shrink: 0;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--card-bg);
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }

    .logo { 
        padding: 0; 
        border: none; 
        margin-bottom: 0;
        font-size: 1.2rem;
        cursor: pointer; /* Make logo clickable */
        user-select: none; /* Prevent text selection */
        z-index: 102; /* Above other elements */
        position: relative;
        -webkit-tap-highlight-color: rgba(32, 201, 151, 0.2); /* Visual feedback on tap */
        transition: opacity 0.2s ease;
    }
    
    .logo:active {
        opacity: 0.7;
    }

    /* Mobile Hamburger Menu */
    .mobile-menu-toggle {
        display: block;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--primary-color);
        padding: 12px; /* Increase touch target */
        margin-right: -12px; /* Align with padding */
        z-index: 102; /* Above sidebar content */
        position: relative;
        -webkit-tap-highlight-color: rgba(32, 201, 151, 0.2); /* Visual feedback on tap */
        touch-action: manipulation; /* Optimize for touch */
        transition: transform 0.2s ease, opacity 0.2s ease;
    }
    
    .mobile-menu-toggle:active {
        transform: scale(0.95);
        opacity: 0.7;
    }

    /* Mobile Sidebar Drawer */
    .nav-links {
        position: absolute;
        top: 60px;
        left: 0;
        width: 100%;
        background: var(--card-bg);
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        padding: 10px 0;
        margin-top: 0;
        display: none;
        flex-direction: column;
        z-index: 101;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transition: opacity 0.2s ease;
        opacity: 0;
    }
    
    .nav-links.show {
        display: flex !important;
        opacity: 1;
    }
    
    /* WeChat-specific: Pop-up dialog style */
    body.wechat-browser .nav-links {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0.9);
        width: 80%;
        max-width: 300px;
        max-height: 70vh;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        padding: 0;
        margin: 0;
        z-index: 1001;
        transition: transform 0.2s ease, opacity 0.2s ease;
        opacity: 0;
    }
    
    body.wechat-browser .nav-links.show {
        display: flex !important;
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    
    body.wechat-browser .nav-links li {
        border-bottom: 1px solid var(--border-color);
        border-left: none;
        border-right: none;
        -webkit-tap-highlight-color: rgba(32, 201, 151, 0.2);
        padding: 16px 20px;
    }
    
    body.wechat-browser .nav-links li:first-child {
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
    }
    
    body.wechat-browser .nav-links li:last-child {
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
        border-bottom: none;
    }
    
    body.wechat-browser .nav-links li:hover, 
    body.wechat-browser .nav-links li.active {
        border-left: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        background: var(--hover-bg);
    }
    
    body.wechat-browser .nav-links li:last-child:hover,
    body.wechat-browser .nav-links li:last-child.active {
        border-bottom: none;
    }
    
    /* Overlay */
    .mobile-menu-overlay {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        height: calc(100% - 60px);
        background: rgba(0,0,0,0.4);
        z-index: 100;
        -webkit-tap-highlight-color: transparent;
        transition: opacity 0.2s ease;
        opacity: 0;
    }
    
    .mobile-menu-overlay.show {
        display: block !important;
        opacity: 1;
    }
    
    /* WeChat-specific: Full screen overlay */
    body.wechat-browser .mobile-menu-overlay {
        top: 0;
        height: 100%;
        z-index: 1000;
        background: rgba(0,0,0,0.5);
    }
    
    body.wechat-browser .mobile-menu-overlay.show {
        display: block !important;
        opacity: 1;
    }

    .nav-links li { 
        padding: 16px 20px; 
        border-right: none; 
        border-bottom: 1px solid var(--border-color);
        border-top: none;
        font-size: 1rem;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(32, 201, 151, 0.2);
        min-height: 50px; /* Ensure minimum touch target size */
        display: flex;
        align-items: center;
    }
    
    .nav-links li:last-child {
        border-bottom: none;
    }
    
    .nav-links li:hover, .nav-links li.active { 
        border-right: none; 
        border-bottom: 1px solid var(--border-color);
        border-left: 4px solid var(--primary-color);
        background: var(--hover-bg);
    }
    
    .nav-links li:active {
        background: var(--hover-bg);
    }

    .sidebar-footer {
        display: none; /* Keep hidden, specific actions will be in menu */
    }
    
    /* User Info in Mobile */
    .user-info {
        display: none; /* Hide in header, show in menu if needed or just minimal */
    }

    /* Mobile Actions in Nav */
    .mobile-nav-footer {
        display: flex;
        justify-content: space-between;
        padding: 15px 20px;
        background: var(--hover-bg);
        border-top: 1px solid var(--border-color);
    }

    .main-content { 
        padding: 15px; 
        height: auto;
        min-height: calc(100vh - 60px);
    }

    .header-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        margin-bottom: 20px;
    }

    .header-bar h2 {
        font-size: 1.3rem;
    }

    .header-bar .actions {
        width: 100%;
    }

    .header-bar .actions .btn {
        flex: 1;
        min-width: 0;
    }

    .dashboard-grid { 
        grid-template-columns: 1fr;
        gap: 20px;
        display: flex;
        flex-direction: column;
    }
    
    .record-form-card {
        order: -1;
    }

    .accounts-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    /* 统计概览：手机端汇总卡片改为 2 列，更紧凑 */
    #view-dashboard .summary-cards { 
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px; 
    }
    
    /* 统计概览：移动端 mini-card 适配两列布局，改为上下排版 */
    #view-dashboard .mini-card { 
        padding: 14px; 
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: 6px;
        min-height: 74px;
    }

    #view-dashboard .mini-card h3 {
        font-size: 1.25rem;
        margin-top: 0;
        line-height: 1.1;
    }

    #view-dashboard .mini-card span {
        font-size: 0.85rem;
    }
    
    .mini-card h3 { 
        font-size: 1.2rem; 
        margin-top: 0;
    }
    
    .form-row { 
        flex-direction: row; /* Keep parallel on mobile */
        gap: 10px;
        align-items: flex-end;
    }
    
    .form-group.half {
        flex: 1;
        min-width: 0;
    }
    
    /* Compact radio group for mobile */
    .radio-group {
        padding: 2px;
        min-height: 42px;
    }
    
    .radio-label {
        padding: 0 5px;
        font-size: 0.9rem;
        line-height: 38px;
    }

    .card {
        padding: 15px;
    }

    /* Optimized Table for Mobile (Card View) */
    .table {
        min-width: auto; /* Remove min-width for mobile */
    }
    
    .table thead {
        display: none;
    }

    .table tbody tr {
        display: block;
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        margin-bottom: 15px;
        padding: 15px;
        box-shadow: var(--shadow);
    }

    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--hover-bg);
        padding: 10px 0;
        text-align: right;
        word-break: break-word; /* Prevent text overflow */
    }

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

    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-light);
        margin-right: 10px;
        flex-shrink: 0; /* Prevent label shrinking */
    }

    .table td.text-right {
        text-align: right;
    }
    
    /* Table wrapper should allow full width */
    .table-responsive {
        overflow-x: visible; /* Remove horizontal scroll for mobile cards */
    }
    
    /* Chart wrapper for mobile */
    .chart-wrapper {
        position: relative;
        height: 250px;
        width: 100%;
        overflow: hidden;
    }
    
    .chart-card {
        overflow: hidden; /* Ensure chart doesn't overflow */
    }

    /* Modal Adjustments */
    .modal-content {
        padding: 20px;
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: 85vh;
    }
    
    /* Modal Action Buttons */
    .modal-content .btn {
        margin-bottom: 10px; /* Spacing for stacked buttons */
        width: 100%;
    }
    
    .modal-content div[style*="display: flex"] {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        padding: 12px; /* Larger touch targets */
    }
}

/* Utilities */
.mobile-menu-toggle { display: none; }
.mobile-nav-footer { display: none; }
.mobile-only-item { display: none; }
.mobile-menu-overlay { display: none; }

@media (max-width: 768px) {
    .mobile-only-item {
        display: block !important;
    }
    
    /* Ensure sidebar footer is hidden on mobile */
    .sidebar-footer {
        display: none !important;
    }
    
    /* Ensure user-info is hidden on mobile */
    .user-info {
        display: none !important;
    }
}
