/* ========================================
   HK Data Downloader - Modern Dashboard Styles
   ======================================== */

/* CSS Variables */
:root {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #dbeafe;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #06b6d4;
    --bg-color: #f1f5f9;
    --sidebar-bg: #1e293b;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 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: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
}

/* ========================================
   Layout
   ======================================== */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 600;
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-item:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

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

.nav-item i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.schedule-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius);
}

.schedule-info i {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.schedule-text {
    display: flex;
    flex-direction: column;
}

.schedule-text small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.schedule-text span {
    font-weight: 600;
    font-size: 0.95rem;
}

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

/* Top Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.top-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

/* ========================================
   Stats Section
   ======================================== */

.stats-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.bg-blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.bg-green { background: linear-gradient(135deg, #10b981, #059669); }
.bg-purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.bg-orange { background: linear-gradient(135deg, #f59e0b, #d97706); }

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

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ========================================
   Content Sections
   ======================================== */

.content-section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

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

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-header h2 i {
    color: var(--primary-color);
}

.section-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ========================================
   Download Section
   ======================================== */

.download-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 20px;
}

.download-card {
    background: var(--bg-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.download-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

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

.download-header i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.download-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.download-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.date-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.date-range-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 1rem;
    z-index: 1;
}

.date-picker {
    width: 100%;
    padding: 12px 14px 12px 42px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--card-bg);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.range-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 8px;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

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

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

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

.btn-success:hover:not(:disabled) {
    background: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius);
    background: var(--bg-color);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-block {
    width: 100%;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

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

/* ========================================
   Search Box
   ======================================== */

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
}

.search-box input {
    padding: 10px 14px 10px 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.9rem;
    width: 240px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

/* ========================================
   Dates List
   ======================================== */

.dates-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
    min-height: 200px;
}

.date-item {
    background: var(--bg-color);
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.date-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.date-item.selected {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.date-item::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 12px;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.date-item.selected::before {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.date-item.selected::after {
    content: '✓';
    position: absolute;
    top: 12px;
    left: 16px;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
}

.date-text {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.date-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ========================================
   Bulk Actions
   ======================================== */

.bulk-actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-wrapper input {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.checkbox-wrapper input:checked + .checkmark {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-wrapper input:checked + .checkmark::after {
    content: '✓';
    color: white;
    font-size: 0.75rem;
}

.bulk-buttons {
    display: flex;
    gap: 12px;
}

/* ========================================
   Loading Spinner
   ======================================== */

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

.spinner {
    width: 40px;
    height: 40px;
    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); }
}

.empty {
    text-align: center;
    padding: 60px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

/* ========================================
   Progress Bar
   ======================================== */

.progress-container {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-top: 20px;
}

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

.progress-header span:first-child {
    font-weight: 500;
}

.progress-header span:last-child {
    color: var(--primary-color);
    font-weight: 600;
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--info-color));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ========================================
   Modal
   ======================================== */

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

.modal-content.settings-modal {
    max-width: 500px;
}

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

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h3 i {
    color: var(--primary-color);
}

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========================================
   Settings Modal
   ======================================== */

.settings-section {
    margin-bottom: 24px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-section h4 i {
    color: var(--primary-color);
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.time-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--card-bg);
    cursor: pointer;
    min-width: 80px;
}

.time-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.time-separator {
    font-weight: 600;
    color: var(--text-secondary);
}

.setting-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.workdays-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.day-checkbox {
    cursor: pointer;
}

.day-checkbox input {
    display: none;
}

.day-checkbox span {
    display: block;
    padding: 8px 14px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.day-checkbox input:checked + span {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.info-grid {
    display: grid;
    gap: 12px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius);
}

.info-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.info-value {
    font-weight: 500;
    font-size: 0.9rem;
}

/* ========================================
   File List
   ======================================== */

.file-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-color);
    border-radius: var(--radius);
    transition: background 0.2s ease;
}

.file-item:hover {
    background: var(--primary-light);
}

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

.file-info i {
    font-size: 1.25rem;
    color: var(--success-color);
}

.file-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.file-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.file-actions .btn {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* ========================================
   Footer
   ======================================== */

.app-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

/* ========================================
   Toast Notification
   ======================================== */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 24px;
    border-radius: var(--radius);
    color: white;
    font-weight: 500;
    z-index: 2000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
}

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

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

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

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

/* ========================================
   Flatpickr Customization
   ======================================== */

.flatpickr-calendar {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.flatpickr-day.selected {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.flatpickr-day.today {
    border-color: var(--primary-color);
}

.flatpickr-day:hover {
    background: var(--primary-light);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 1200px) {
    .stats-section {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: fixed;
        bottom: 0;
        top: auto;
        height: auto;
        flex-direction: row;
        z-index: 200;
    }
    
    .sidebar-header,
    .sidebar-footer {
        display: none;
    }
    
    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        padding: 8px;
        width: 100%;
    }
    
    .nav-item {
        flex-direction: column;
        padding: 8px 12px;
        font-size: 0.75rem;
        gap: 4px;
    }
    
    .nav-item span {
        font-size: 0.7rem;
    }
    
    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding-bottom: 80px;
    }
    
    .stats-section {
        grid-template-columns: 1fr;
    }
    
    .download-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }
    
    .search-box input {
        width: 100%;
    }
    
    .bulk-actions-bar {
        flex-direction: column;
        gap: 16px;
    }
    
    .bulk-buttons {
        width: 100%;
    }
    
    .bulk-buttons .btn {
        flex: 1;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --card-bg: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #334155;
    }
    
    .sidebar {
        background: #0f172a;
    }
}

/* ========================================
   Date Item Override - New Layout
   ======================================== */

.dates-list {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.date-item {
    flex-direction: row;
    align-items: flex-start;
    padding: 16px;
}

.date-item::before,
.date-item.selected::before,
.date-item.selected::after {
    display: none;
}

.date-checkbox {
    flex-shrink: 0;
    margin-top: 2px;
}

.date-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.date-content {
    flex: 1;
    cursor: pointer;
}

.date-text {
    font-size: 1.05rem;
    margin-bottom: 4px;
}

.date-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
