/* 
 * 考勤解释系统 - CSS样式文件
 * 现代简洁的UI设计
 */

/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --success-light: #d1fae5;
    --warning-color: #f59e0b;
    --warning-light: #fef3c7;
    --error-color: #ef4444;
    --error-light: #fee2e2;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-hover: #f1f5f9;
    --bg-selected: #e0f2fe;
    --bg-success-light: #d1fae5;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 18px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

/* Main Content */
.main-content {
    padding: 32px 0;
    min-height: calc(100vh - 73px);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}

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

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

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.error-state.expired {
    background: linear-gradient(135deg, #fef3c7 0%, #fee2e2 100%);
}

.error-icon {
    color: var(--error-color);
    margin-bottom: 24px;
}

.error-state h2 {
    font-size: 24px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.error-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 400px;
}

.error-state .contact-hr {
    background: var(--primary-color);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.error-state .contact-hr:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* Submitted State */
.submitted-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.success-icon {
    color: var(--success-color);
    margin-bottom: 24px;
}

.submitted-state h2 {
    font-size: 24px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.submitted-state p {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.submitted-date {
    font-size: 14px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 8px 16px;
    border-radius: var(--radius-md);
}

/* Form Content */
.form-content {
    animation: fadeIn 0.3s ease;
}

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

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

.form-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.month-label {
    font-size: 16px;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 8px;
}

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

/* Warning Banner */
.warning-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--warning-light);
    color: #92400e;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    font-size: 14px;
}

.warning-banner svg {
    flex-shrink: 0;
}

/* Table Container */
.table-container {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 24px;
}

/* Attendance Table */
.attendance-table {
    width: 100%;
    border-collapse: collapse;
}

.attendance-table thead {
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
}

.attendance-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.attendance-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

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

.attendance-table tbody tr:hover {
    background: var(--bg-secondary);
}

/* Table Column Widths */
.col-date { width: 120px; }
.col-time { width: 100px; }
.col-error { width: 180px; }
.col-reason { min-width: 300px; }

/* Table Cell Styles */
.date-cell {
    font-weight: 600;
    color: var(--text-primary);
}

.time-cell {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 13px;
    color: var(--text-primary);
}

.time-cell.missing {
    color: var(--error-color);
    font-style: italic;
}

.error-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.error-badge.late {
    background: var(--warning-light);
    color: #92400e;
}

.error-badge.early {
    background: var(--warning-light);
    color: #92400e;
}

.error-badge.no-in,
.error-badge.no-out {
    background: var(--error-light);
    color: #dc2626;
}

.error-badge.absent {
    background: var(--error-light);
    color: #dc2626;
}

/* Reason Input */
.reason-cell {
    padding: 8px 0;
}

.reason-input {
    width: 100%;
    min-height: 60px;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: var(--transition);
    background: var(--bg-primary);
}

.reason-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.reason-input.error {
    border-color: var(--error-color);
    background: var(--error-light);
}

.reason-input:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.reason-input::placeholder {
    color: var(--text-muted);
}

.char-count-mini {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.char-count-mini.warning {
    color: var(--warning-color);
}

.char-count-mini.error {
    color: var(--error-color);
}

/* Form Footer */
.form-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary);
    padding: 20px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.char-count {
    font-size: 14px;
    color: var(--text-secondary);
}

.char-count span {
    font-weight: 600;
    color: var(--primary-color);
}

.actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

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

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

/* Modal for Image Preview */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 800px;
    max-height: 90vh;
    object-fit: contain;
    margin-top: 5%;
}

.modal .close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.modal .close:hover,
.modal .close:focus {
    color: #bbb;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
    }

    .form-header h1 {
        font-size: 22px;
    }

    .table-container {
        overflow-x: auto;
    }

    .attendance-table {
        min-width: 800px;
    }

    .form-footer {
        flex-direction: column;
        gap: 16px;
    }

    .char-count {
        order: 2;
    }

    .actions {
        order: 1;
        width: 100%;
    }

    .actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* Print Styles */
@media print {
    .header,
    .form-footer,
    .warning-banner {
        display: none;
    }

    .table-container {
        box-shadow: none;
    }

    .attendance-table td {
        border: 1px solid #ddd;
    }
}

/* New: Checkbox column */
.col-select {
    width: 40px;
    text-align: center;
}

.row-select {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* Row selection states */
#attendanceBody tr {
    transition: var(--transition);
}

#attendanceBody tr:hover {
    background: var(--bg-hover);
}

#attendanceBody tr.selected {
    background: var(--bg-selected);
}

#attendanceBody tr.filled {
    background: var(--bg-success-light);
}

#attendanceBody tr.filled.selected {
    background: var(--bg-success-light);
}

/* Small save button */
.btn-save {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
}

.col-action {
    width: 80px;
    text-align: center;
}

/* Success state for char count */
.char-count-mini.success {
    color: var(--success-color);
}

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

.stat-card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

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

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

.stat-count {
    font-size: 28px;
    font-weight: 700;
    display: block;
    color: var(--text-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-top: 4px;
}

.stat-card.late .stat-count { color: #f59e0b; }
.stat-card.early .stat-count { color: #8b5cf6; }
.stat-card.no-in .stat-count { color: #ef4444; }
.stat-card.no-out .stat-count { color: #ef4444; }
.stat-card.absent .stat-count { color: #dc2626; }

/* Error Sections */
.error-section {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    overflow: hidden;
    transition: var(--transition);
}

.error-section.filled {
    border-color: var(--success-color);
    background: var(--bg-success-light);
}

.section-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.section-icon {
    font-size: 20px;
}

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

.section-count {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.section-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

.section-content {
    padding: 20px;
}

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

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

.form-group select,
.form-group textarea,
.form-group input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-group select:focus,
.form-group textarea:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.selected-date {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.reason-section {
    margin-top: 16px;
}

.char-count-mini {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.char-count-mini.warning {
    color: var(--warning-color);
}

.char-count-mini.success {
    color: var(--success-color);
}

.error-section.filled .section-header {
    background: var(--success-light);
}

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-count {
        font-size: 24px;
    }
}

/* Reason Table Styles */
.reason-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-primary);
}

.reason-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

.reason-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

.reason-table tr {
    transition: var(--transition);
}

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

.reason-table tr.filled {
    background: var(--bg-success-light);
}

.reason-table tr.filled:hover {
    background: var(--success-light);
}

.col-date { width: 120px; }
.col-time { width: 100px; }
.col-reason { flex: 1; }
.col-status { width: 130px; text-align: center; }

.date-cell {
    font-weight: 500;
    color: var(--text-primary);
}

.time-cell {
    color: var(--text-secondary);
    font-family: monospace;
}

.reason-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
    min-height: 60px;
    transition: var(--transition);
}

.reason-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.reason-input.error {
    border-color: var(--error-color);
}

.char-count-mini {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.char-count-mini.warning {
    color: var(--warning-color);
}

.char-count-mini.success {
    color: var(--success-color);
}

.status-cell {
    text-align: center;
    vertical-align: middle;
}

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

.status-badge.pending {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

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

@media (max-width: 768px) {
    .reason-table {
        display: block;
        overflow-x: auto;
    }
    
    .col-date, .col-time, .col-status {
        width: auto;
    }
}

