/* 天賜集團財務管理系統 - 手機版樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1a5632;
    --primary-light: #2d7a4a;
    --primary-dark: #0f3d20;
    --secondary-color: #c9a961;
    --accent-color: #e8d5a3;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-light: #999999;
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* 頁面切換 */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* ========== 登錄頁面 ========== */
#login-page {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 50%, var(--primary-light) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#login-page.active {
    display: flex;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

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

.logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.logo svg {
    color: white;
}

.login-header h1 {
    color: white;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 2px;
}

.login-header h2 {
    color: var(--accent-color);
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 8px;
}

.subtitle {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    letter-spacing: 1px;
}

.login-form {
    background: white;
    border-radius: var(--radius);
    padding: 30px 24px;
    box-shadow: var(--shadow-lg);
}

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

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

.form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 16px;
    transition: all 0.3s ease;
    background: var(--bg-primary);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(26, 86, 50, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 2px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 86, 50, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.error-message {
    color: var(--danger-color);
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
    min-height: 20px;
}

.login-footer {
    text-align: center;
    margin-top: 30px;
}

.login-footer p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
}

/* ========== 主應用頁面 ========== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left, .header-right {
    display: flex;
    align-items: center;
}

.header-title {
    flex: 1;
    text-align: center;
}

.header-title h1 {
    color: white;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* 側邊菜單 */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: white;
    z-index: 200;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    left: 0;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
}

.menu-overlay.show {
    display: block;
}

.menu-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    padding: 30px 20px;
    color: white;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 50px;
    height: 50px;
    background: var(--secondary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-dark);
}

.user-details .user-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.user-details .user-role {
    font-size: 12px;
    opacity: 0.8;
}

.menu-list {
    flex: 1;
    list-style: none;
    padding: 10px 0;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 15px;
}

.menu-item:hover {
    background: var(--bg-primary);
}

.menu-item.active {
    background: rgba(26, 86, 50, 0.1);
    color: var(--primary-color);
    border-left: 4px solid var(--primary-color);
}

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

.menu-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    color: var(--danger-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

/* 內容區域 */
.app-content {
    padding-top: 60px;
    min-height: 100vh;
}

.content-page {
    display: none;
    padding: 16px;
}

.content-page.active {
    display: block;
}

/* 摘要卡片 */
.summary-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.3s ease;
}

.summary-card:active {
    transform: scale(0.98);
}

.summary-card .card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.summary-card.balance .card-icon {
    background: rgba(26, 86, 50, 0.1);
    color: var(--primary-color);
}

.summary-card.income .card-icon {
    background: rgba(40, 167, 69, 0.1);
    color: var(--success-color);
}

.summary-card.expense .card-icon {
    background: rgba(220, 53, 69, 0.1);
    color: var(--danger-color);
}

.summary-card.pending .card-icon {
    background: rgba(255, 193, 7, 0.1);
    color: var(--warning-color);
}

.card-info {
    flex: 1;
    min-width: 0;
}

.card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.card-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 區塊 */
.section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.section-header .section-title {
    margin-bottom: 0;
}

.badge {
    background: rgba(26, 86, 50, 0.1);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

/* 圖表容器 */
.chart-container {
    position: relative;
    height: 200px;
    margin-top: 12px;
}

/* 公司列表 */
.company-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.company-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.company-item:hover {
    background: rgba(26, 86, 50, 0.05);
}

.company-info {
    flex: 1;
    min-width: 0;
}

.company-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.company-account {
    font-size: 12px;
    color: var(--text-light);
}

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

.balance-amount {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary-color);
}

.balance-label {
    font-size: 11px;
    color: var(--text-light);
}

/* 租金列表 */
.rent-list, .loan-list, .check-list, .br-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rent-item, .loan-item, .check-item, .br-item {
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.item-amount {
    font-size: 15px;
    font-weight: 700;
}

.item-amount.income {
    color: var(--success-color);
}

.item-amount.expense {
    color: var(--danger-color);
}

.item-details {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

/* 狀態標籤 */
.status-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-tag.valid {
    background: rgba(40, 167, 69, 0.1);
    color: var(--success-color);
}

.status-tag.expiring {
    background: rgba(255, 193, 7, 0.1);
    color: var(--warning-color);
}

.status-tag.expired {
    background: rgba(220, 53, 69, 0.1);
    color: var(--danger-color);
}

.status-tag.pending {
    background: rgba(23, 162, 184, 0.1);
    color: var(--info-color);
}

/* 報表標籤 */
.report-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.report-tab {
    flex: 1;
    padding: 10px;
    background: var(--bg-primary);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.report-tab.active {
    background: rgba(26, 86, 50, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 加載提示 */
.loading-text {
    text-align: center;
    color: var(--text-light);
    padding: 20px;
    font-size: 14px;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* 響應式設計 */
@media (max-width: 360px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }
    
    .header-title h1 {
        font-size: 16px;
    }
}

@media (min-width: 768px) {
    .summary-cards {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .app-content {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* 安全區域適配 */
@supports (padding: max(0px)) {
    .app-header {
        padding-top: max(16px, env(safe-area-inset-top));
        height: max(60px, calc(60px + env(safe-area-inset-top)));
    }
    
    .app-content {
        padding-top: max(60px, calc(60px + env(safe-area-inset-top)));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}


/* ===== 修復頁面切換問題 ===== */
.page {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

.page.active {
    display: block !important;
    z-index: 1 !important;
}

.login-container {
    height: 100vh !important;
    min-height: 100vh !important;
    overflow: hidden !important;
}


/* ===== 歡迎界面樣式 ===== */
.welcome-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1a5632 0%, #2d7a4a 50%, #c9a961 100%);
    position: relative;
    overflow: hidden;
}

.welcome-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: welcomeBgRotate 20s linear infinite;
}

@keyframes welcomeBgRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.welcome-content {
    text-align: center;
    color: white;
    position: relative;
    z-index: 1;
    animation: welcomeFadeIn 1s ease-out;
}

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

.welcome-icon {
    margin-bottom: 20px;
    animation: welcomeIconBounce 2s ease-in-out infinite;
}

@keyframes welcomeIconBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-title {
    font-size: 32px;
    font-weight: 300;
    margin-bottom: 8px;
    letter-spacing: 4px;
}

.welcome-name {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
    color: #ffd700;
}

.welcome-greeting {
    font-size: 16px;
    margin-bottom: 24px;
    opacity: 0.9;
}

.welcome-time {
    margin-bottom: 30px;
}

.welcome-date {
    font-size: 14px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.welcome-clock {
    font-size: 36px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.welcome-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.welcome-stat-item {
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px 20px;
    min-width: 100px;
    border: 1px solid rgba(255,255,255,0.2);
}

.welcome-stat-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.welcome-stat-value {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.welcome-stat-label {
    font-size: 12px;
    opacity: 0.8;
}

.welcome-enter-btn {
    background: white;
    color: #1a5632;
    border: none;
    padding: 14px 40px;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.welcome-enter-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.welcome-auto-hint {
    margin-top: 16px;
    font-size: 12px;
    opacity: 0.7;
}

/* ===== 用戶管理樣式 ===== */
.user-list {
    padding: 0;
}

.user-item {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.user-info {
    flex: 1;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a5632, #c9a961);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    margin-right: 12px;
}

.user-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.user-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-username {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 8px;
}

.user-details {
    font-size: 13px;
    color: var(--text-secondary);
}

.user-details span {
    margin-right: 16px;
}

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

.user-action-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-action-btn.edit {
    background: #e3f2fd;
    color: #1976d2;
}

.user-action-btn.reset {
    background: #fff3e0;
    color: #f57c00;
}

.user-action-btn.toggle {
    background: #f3e5f5;
    color: #7b1fa2;
}

.user-action-btn.delete {
    background: #ffebee;
    color: #d32f2f;
}

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.role-badge.admin {
    background: #ffebee;
    color: #c62828;
}

.role-badge.editor {
    background: #e3f2fd;
    color: #1565c0;
}

.role-badge.viewer {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.active {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-badge.inactive {
    background: #ffebee;
    color: #c62828;
}
