/* ============================================
   基础样式和重置
============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%; /* 防止iOS缩放 */
    -webkit-tap-highlight-color: transparent; /* 移除移动端点击高亮 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    text-align: center;
    background-color: #f0f0f0;
    color: #333;
    line-height: 1.5;
    overflow-x: hidden; /* 防止横向滚动 */
    min-height: 100vh;
}

/* ============================================
   通用容器样式
============================================ */
.container, 
.auth-container,
.contacts-container,
.calendar-container {
    background: white;
    border-radius: 15px;
    padding: 25px 20px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
    margin: 20px auto;
    width: 100%;
    max-width: 95%;
    transition: all 0.3s ease;
}

/* ============================================
   主页面样式 (index.html)
============================================ */
/* 顶部导航区域 */
.user-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 15px 20px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#username-display {
    font-weight: 500;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
}

#logout-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

#logout-btn:hover {
    background: rgba(255,255,255,0.3);
}

#login-prompt {
    color: white;
    font-size: 0.9rem;
}

#login-prompt a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.5);
    padding-bottom: 1px;
}

/* 内容区域 */
.content-wrapper {
    padding-top: 80px; /* 为固定导航栏留出空间 */
    padding-bottom: 30px;
    padding-left: 15px;
    padding-right: 15px;
    min-height: calc(100vh - 60px);
}

h1 {
    color: #333;
    font-size: 1.8rem;
    margin-bottom: 15px;
    font-weight: 600;
}

.container p {
    color: #666;
    font-size: 1rem;
    margin-bottom: 25px;
    line-height: 1.6;
}

/* 签到按钮 */
#checkin-btn {
    background: linear-gradient(135deg, #4CAF50, #3d8b40);
    color: white;
    border: none;
    padding: 20px 40px;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    margin: 25px 0;
    width: 100%;
    max-width: 300px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    position: relative;
    overflow: hidden;
}

#checkin-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: 0.5s;
}

#checkin-btn:hover:before {
    left: 100%;
}

#checkin-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

#checkin-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(76, 175, 80, 0.3);
}

#checkin-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#checkin-btn:disabled:hover:before {
    left: -100%;
}

/* 状态区域 */
#status {
    margin: 30px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
    text-align: center;
}

#status p {
    font-size: 1.1rem;
    margin: 10px 0;
    color: #333;
}

#today-status {
    color: #4CAF50;
    font-weight: 600;
    font-size: 1.2rem;
}

#streak-days {
    color: #FF9800;
    font-weight: 600;
    font-size: 1.2rem;
}

/* 历史记录 */
#history {
    margin-top: 30px;
    text-align: left;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

#history h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3rem;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 10px;
}

#record-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

#record-list li {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease;
}

#record-list li:hover {
    background: #f8f9fa;
}

#record-list li:last-child {
    border-bottom: none;
}

/* 日历 */
.calendar-container {
    margin-top: 30px;
    background: white;
}

.calendar-container h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

#calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-top: 15px;
}

.day-cell {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.day-cell.signed {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border-color: #4CAF50;
    transform: scale(1.05);
}

.day-cell:active {
    transform: scale(0.95);
}

/* 数据说明 */
.data-note {
    margin-top: 30px;
    font-size: 0.85rem;
    color: #999;
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

/* ============================================
   认证页面样式 (login.html, register.html)
============================================ */
.auth-container {
    margin: 40px auto;
    padding: 30px 25px;
    max-width: 420px;
}

.auth-title {
    text-align: center;
    margin-bottom: 25px;
    color: #333;
    font-size: 1.8rem;
    font-weight: 600;
}

.auth-form input {
    width: 100%;
    padding: 16px;
    margin-bottom: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.auth-form input:focus {
    border-color: #4CAF50;
    background: white;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
    outline: none;
}

.auth-button {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.auth-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.auth-button:active {
    transform: translateY(0);
}

.auth-links {
    text-align: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.auth-links a {
    color: #4CAF50;
    text-decoration: none;
    font-weight: 500;
    margin: 0 8px;
    font-size: 0.95rem;
    display: inline-block;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.auth-links a:hover {
    background: #f0f9f0;
    color: #3d8b40;
}

/* 消息提示 */
.error-message,
.success-message {
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: none;
    font-size: 0.95rem;
    animation: slideDown 0.3s ease;
}

.error-message {
    background: #ffebee;
    color: #c62828;
    border-left: 4px solid #c62828;
}

.success-message {
    background: #e8f5e9;
    color: #2e7d32;
    border-left: 4px solid #2e7d32;
}

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

/* ============================================
   联系人管理样式
============================================ */
.contacts-container {
    margin: 25px auto;
    padding: 25px 20px;
}

.contacts-header {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.contacts-title {
    color: #333;
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.contacts-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.contacts-action-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    min-width: 140px;
    max-width: 200px;
}

.contacts-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.contacts-action-btn.secondary {
    background: linear-gradient(135deg, #6c757d, #5a6268);
}

.contacts-action-btn.secondary:hover {
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.contacts-table-container {
    overflow-x: auto;
    margin-top: 15px;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

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

.contacts-table th {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    font-size: 0.95rem;
}

.contacts-table td {
    padding: 15px 12px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: middle;
    font-size: 0.9rem;
}

.contacts-table tr:hover {
    background-color: #f8f9fa;
}

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

.contact-action-btn {
    padding: 8px 12px;
    font-size: 0.85rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 60px;
}

.contact-action-btn.edit {
    background: linear-gradient(135deg, #17a2b8, #138496);
    color: white;
}

.contact-action-btn.edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(23, 162, 184, 0.3);
}

.contact-action-btn.delete {
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white;
}

.contact-action-btn.delete:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.contact-action-btn.view {
    background: linear-gradient(135deg, #6c757d, #5a6268);
    color: white;
}

.contact-action-btn.view:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

.no-contacts {
    text-align: center;
    padding: 50px 20px;
    color: #6c757d;
    font-size: 1.1rem;
}

.no-contacts p {
    margin-top: 15px;
    color: #999;
    font-size: 0.95rem;
}

/* ============================================
   联系人模态框样式
============================================ */
.contact-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.contact-modal.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    border-radius: 15px 15px 0 0;
}

.modal-title {
    margin: 0;
    color: #333;
    font-size: 1.3rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #6c757d;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: #f8f9fa;
    color: #333;
}

.modal-body {
    padding: 25px 20px;
}

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

.contact-form-group label {
    display: block;
    margin-bottom: 8px;
    color: #495057;
    font-weight: 500;
    font-size: 0.95rem;
}

.contact-form-group input,
.contact-form-group textarea,
.contact-form-group select {
    width: 100%;
    padding: 14px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.contact-form-group input:focus,
.contact-form-group textarea:focus,
.contact-form-group select:focus {
    border-color: #4CAF50;
    background: white;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
    outline: none;
}

.contact-form-group textarea {
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 10;
    border-radius: 0 0 15px 15px;
}

.modal-btn {
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.modal-btn.primary {
    background: linear-gradient(135deg, #007bff, #0069d9);
    color: white;
}

.modal-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.modal-btn.secondary {
    background: linear-gradient(135deg, #6c757d, #5a6268);
    color: white;
}

.modal-btn.secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.modal-btn.danger {
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white;
}

.modal-btn.danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

/* ============================================
   加载状态
============================================ */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4CAF50;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   移动端特定优化
============================================ */

/* 小屏幕手机 (最大宽度: 480px) */
@media screen and (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .user-nav {
        padding: 12px 15px;
        height: 56px;
    }
    
    .content-wrapper {
        padding-top: 76px;
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        padding: 20px 15px;
        max-width: 100%;
        border-radius: 12px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    #checkin-btn {
        padding: 18px 30px;
        font-size: 1.1rem;
        max-width: 100%;
    }
    
    .contacts-action-btn {
        min-width: 120px;
        padding: 10px 15px;
    }
    
    .modal-content {
        margin: 0;
        max-height: 90vh;
    }
    
    .modal-btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .day-cell {
        height: 35px;
        font-size: 0.85rem;
    }
    
    .contact-action-btn {
        min-width: 50px;
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

/* 中等屏幕手机 (481px - 767px) */
@media screen and (min-width: 481px) and (max-width: 767px) {
    .content-wrapper {
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        padding: 25px 20px;
    }
    
    #checkin-btn {
        max-width: 280px;
    }
    
    .contacts-action-btn {
        min-width: 150px;
    }
}

/* 平板设备 (768px - 1024px) */
@media screen and (min-width: 768px) and (max-width: 1024px) {
    .content-wrapper {
        padding-left: 30px;
        padding-right: 30px;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        max-width: 90%;
    }
    
    #checkin-btn {
        max-width: 320px;
    }
    
    .contacts-header {
        flex-direction: row;
        align-items: center;
    }
    
    .contacts-actions {
        justify-content: flex-end;
    }
}

/* 桌面设备 (1025px及以上) */
@media screen and (min-width: 1025px) {
    .content-wrapper {
        padding-left: 40px;
        padding-right: 40px;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        max-width: 800px;
    }
    
    .auth-container {
        max-width: 450px;
    }
    
    #checkin-btn {
        max-width: 350px;
    }
}

/* ============================================
   特殊移动端优化
============================================ */

/* iOS Safari优化 */
@supports (-webkit-touch-callout: none) {
    .auth-form input,
    .contact-form-group input,
    .contact-form-group textarea,
    .contact-form-group select {
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    #checkin-btn,
    .auth-button,
    .contacts-action-btn,
    .modal-btn {
        cursor: pointer;
    }
}

/* 安卓Chrome优化 */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .auth-form input,
    .contact-form-group input,
    .contact-form-group textarea,
    .contact-form-group select {
        appearance: none;
        -webkit-appearance: none;
    }
}

/* 横屏模式优化 */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .user-nav {
        padding: 8px 15px;
        height: 50px;
    }
    
    .content-wrapper {
        padding-top: 70px;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        padding: 15px;
        margin: 10px auto;
    }
    
    .modal-content {
        max-height: 75vh;
    }
}

/* 高分辨率屏幕 */
@media screen and (min-width: 1200px) and (min-resolution: 2dppx) {
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* 打印样式 */
@media print {
    .user-nav,
    #checkin-btn,
    .contacts-actions,
    .contact-actions,
    .modal-footer {
        display: none !important;
    }
    
    .container, 
    .auth-container,
    .contacts-container,
    .calendar-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
