* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-elevated: #1a1a1a;
    --border: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #8a8a8a;
    --accent: #007AFF;
    --danger: #FF3B30;
    --success: #34C759;
    --warning: #FF9500;
    --purple: #B983FF;
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
}

/* Navigation Bar */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 0.5px solid var(--border);
    padding: calc(var(--safe-area-top) + 12px) 16px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: relative;
    z-index: 100;
}

.nav-date {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-arrow {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-arrow:active {
    transform: scale(0.95);
    background: var(--border);
}

.current-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

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

.date-full {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

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

.nav-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-icon:active {
    background: var(--bg-elevated);
    transform: scale(0.95);
}

/* Main Container */
.main-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg-primary);
}

/* Views */
.timeline-view, .list-view {
    display: none;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.timeline-view.active, .list-view.active {
    display: flex;
}

.timeline-view {
    flex-direction: row;
    overflow-x: hidden;
}

.time-column {
    width: 50px;
    border-right: 0.5px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    left: 0;
    background: var(--bg-primary);
    z-index: 10;
}

.time-markers {
    padding-top: 20px;
}

.time-marker {
    height: 60px;
    padding: 0 4px;
    display: flex;
    align-items: flex-start;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
    line-height: 1.2;
}

.tasks-column {
    flex: 1;
    position: relative;
    padding: 20px 8px;
    min-height: 1440px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.current-time-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--danger);
    z-index: 20;
    pointer-events: none;
    display: none;
}

.current-time-line::before {
    content: '';
    position: absolute;
    left: -8px;
    top: -4px;
    width: 10px;
    height: 10px;
    background: var(--danger);
    border-radius: 50%;
}

.tasks-grid {
    position: relative;
    height: 1440px;
    min-width: 100%;
}

.task-block {
    position: absolute;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--accent), rgba(0, 122, 255, 0.8));
    border-radius: 16px;
    padding: 16px;
    color: white;
    cursor: move;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: visible;
    touch-action: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.task-block:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.task-block.dragging {
    opacity: 0.8;
    z-index: 1000;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    transform: rotate(2deg) scale(1.02);
}

.task-block-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.task-block h3 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    flex: 1;
    margin-right: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.task-complete-btn {
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.task-complete-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.task-complete-btn.checked {
    background: white;
    border-color: white;
}

.task-complete-btn.checked::after {
    content: '✓';
    color: var(--accent);
    font-size: 12px;
    font-weight: bold;
}

.task-block-content {
    margin-bottom: 8px;
}

.task-block-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    opacity: 0.9;
}

.task-time-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.task-duration {
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.task-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.task-block:hover .task-actions {
    opacity: 1;
}

.task-action-btn {
    width: 26px;
    height: 26px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.task-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.task-comments-indicator {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 3px;
}

.task-comments-indicator::before {
    content: '💬';
    font-size: 10px;
}

.task-block.completed {
    opacity: 0.7;
    filter: grayscale(0.3);
}

.task-block.completed h3 {
    text-decoration: line-through;
}

.task-block.completed .task-block {
    background: linear-gradient(135deg, #666, #555);
}

/* Comments textarea styling */
.comments-textarea {
    min-height: 80px;
    border: 1px dashed var(--border);
    background: rgba(0, 122, 255, 0.05);
}

/* Bottom Bar */
.bottom-bar {
    background: var(--bg-secondary);
    border-top: 0.5px solid var(--border);
    padding: 8px 16px calc(var(--safe-area-bottom) + 8px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: relative;
}

.tab-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 11px;
}

.tab-button.active {
    color: var(--accent);
}

.tab-button:active {
    transform: scale(0.95);
}

.add-task-btn {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border: none;
    border-radius: 28px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

.add-task-btn:active {
    transform: scale(0.9);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.modal.active {
    display: flex;
    align-items: flex-end;
    animation: fadeIn 0.2s ease;
}

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

.modal-content {
    background: var(--bg-elevated);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 90vh;
    padding-bottom: var(--safe-area-bottom);
    animation: slideUp 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    text-align: center;
}

.modal-close, .modal-delete {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.modal-close:active, .modal-delete:active {
    background: var(--border);
}

.modal-delete {
    color: var(--danger);
}

/* Form */
.task-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-input, .form-textarea {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-input:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-primary);
}

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

.time-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.time-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.time-input-group label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.color-selector label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-options {
    display: flex;
    gap: 12px;
}

.color-dot {
    width: 32px;
    height: 32px;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-dot.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}

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

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.95);
}

/* AI Chat Modal */
.ai-modal {
    max-height: 80vh;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 60vh;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.message.user {
    background: var(--accent);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.ai {
    background: var(--bg-secondary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-input-wrapper {
    padding: 16px;
    border-top: 0.5px solid var(--border);
    display: flex;
    gap: 12px;
}

.chat-input {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-btn:active {
    transform: scale(0.9);
}

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    top: calc(var(--safe-area-top) + 70px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--warning);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: none;
    z-index: 2000;
}

.offline-indicator.show {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translate(-50%, -100%); }
    to { transform: translate(-50%, 0); }
}

/* AI Notification */
.ai-notification {
    position: fixed;
    top: calc(var(--safe-area-top) + 70px);
    right: 16px;
    background: var(--success);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 2001;
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.3);
    animation: slideInRight 0.3s ease;
}

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

/* Mobile timeline optimization */
@media (max-width: 768px) {
    .timeline-view {
        overflow-x: auto;
    }
    
    .tasks-grid {
        display: flex;
        flex-direction: column;
        gap: 2px;
        min-width: 300px;
        width: max-content;
    }
    
    .task-block {
        position: static !important;
        height: auto !important;
        min-height: 50px;
        max-height: 80px;
        margin: 0;
        width: 280px;
        order: var(--time-order);
    }
    
    .task-block h3 {
        font-size: 14px;
        -webkit-line-clamp: 1;
    }
    
    .task-block-meta {
        font-size: 11px;
    }
    
    .task-duration {
        font-size: 10px;
        padding: 1px 6px;
    }
    
    .tasks-column {
        padding: 20px 4px;
        overflow-x: auto;
        overflow-y: visible;
        min-height: auto;
    }
    
    .time-column {
        width: 45px;
    }
    
    .time-marker {
        font-size: 9px;
        height: 52px;
    }
}

@media (max-width: 480px) {
    .task-block {
        width: 260px;
        padding: 10px;
    }
    
    .task-block h3 {
        font-size: 13px;
    }
    
    .time-column {
        width: 40px;
    }
}

/* List View */
.list-view {
    flex-direction: column;
    padding: 16px;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-list-item {
    background: var(--bg-elevated);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 0.5px solid var(--border);
}

.task-list-item:active {
    transform: scale(0.98);
    background: var(--bg-secondary);
}

.task-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.task-checkbox.checked {
    background: var(--success);
    border-color: var(--success);
}

.task-checkbox.checked::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.task-list-content {
    flex: 1;
    min-width: 0;
}

.task-list-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-list-item.completed .task-list-title {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.task-list-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.task-color-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}