/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --border-color: #cbd5e1;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);

    --today-color: #dc2626;

    --accent-soft: #dbeafe;
    --accent: #2563eb;
}

[data-theme="dark"] {
    --bg-primary: #1e293b;
    --bg-secondary: #334155;
    --bg-tertiary: #475569;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --border-color: #475569;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
}

[v-cloak] {
    display: none;
}

/* Accessibility Styles */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 0 0 4px 4px;
    z-index: 10000;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

/* Focus styles for better keyboard navigation */
.btn:focus,
.btn-icon:focus,
.theme-toggle:focus,
select:focus,
input:focus,
[contenteditable="true"]:focus,
.task-bar:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Better focus indicators for interactive elements */
.btn-icon:focus-visible,
.theme-toggle:focus-visible {
    background-color: var(--bg-tertiary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    }

    .task-bar {
        border: 1px solid #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .today-indicator {
        animation: none;
    }

    .task-bar {
        transition: none;
    }
}

/* Layout */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow);
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.header-info {
    text-align: center;
}

.current-date {
    font-size: 0.875rem;
    color: #1e293b;
}

.app-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    align-items: stretch;
}

.tasks-header,
.timeline-header {
    height: 3rem;
    flex-shrink: 0;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-row .form-group {
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 0;
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.form-group input[type="color"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input[type="color"]:not([value="#3b82f6"]) {
    border-color: currentColor;
}

[data-theme="dark"] .form-group input[type="color"]:not([value="#3b82f6"]) {
    border-color: color-mix(in srgb, currentColor 70%, white 30%);
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

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

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

.btn-icon {
    padding: 0.25rem 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 0.25rem;
    transition: all 0.2s;
}

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

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

.btn-icon:not(:disabled):hover {
    background: var(--bg-tertiary);
    color: var(--primary-color);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.theme-toggle:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Legend */
.legend-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-item input[type="color"] {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
}

.legend-item input[type="text"] {
    flex: 1;
}

.btn-remove {
    background: var(--danger-color);
    color: white;
    border: none;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.btn-add {
    background: none;
    border: 1px dashed var(--primary-color);
    color: var(--primary-color);
    padding: 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: all 0.2s;
}

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

/* Tasks Container */
.tasks-container {
    width: 300px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.tasks-container .tasks-list,
.gantt-container .gantt-body {
    height: calc(100% - 3rem);
}

.tasks-header {
    height: 3rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.tasks-list {
    flex: 1;
    overflow-y: auto;
}

.task-row {
    display: flex;
    align-items: center;
    min-height: 3rem;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    margin: 0;
    transition: all 0.2s ease;
    cursor: grab;
}

.task-row:active {
    cursor: grabbing;
}

.task-row.drag-over {
    background-color: var(--accent-soft);
    border: 2px dashed var(--primary-color);
    transform: scale(1.02);
}

.task-row.dragging {
    opacity: 0.5;
    background-color: var(--bg-tertiary);
}

.task-row::before {
    content: '⋮⋮';
    color: var(--text-muted);
    margin-right: 0.5rem;
    font-size: 0.8rem;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.2s;
}

.task-row:hover::before {
    opacity: 1;
}

.task-row:active::before {
    opacity: 1;
    color: var(--primary-color);
}

.task-row--highlight {
    background: rgba(255, 255, 0, 0.1);
}

.task-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 3rem;
    flex: 1;
}

.task-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.task-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.2;
}

.task-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.25rem;
    line-height: 1;
}

.task-tag {
    background: #1e40af;
    color: #ffffff;
    padding: 0.125rem 0.375rem;
    border-radius: 0.75rem;
    font-size: 0.7rem;
    line-height: 1;
    font-weight: 600;
}

.task-actions {
    padding: 0 1rem;
    display: flex;
    gap: 0.25rem;
}

/* Gantt Container */
.gantt-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    border-left: none;
}

.timeline-header {
    display: grid;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: 3rem;
    overflow-x: auto;
    overflow-y: hidden;
}

.timeline-header-inner {
    display: grid;
    height: 100%;
    min-width: min-content;
}

.timeline-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-right: 1px solid var(--border-color);
    min-width: 60px;
    height: 100%;
    position: relative;
    transition: all 0.2s ease;
}

.timeline-cell--today {
    background: #dc2626 !important;
    color: white !important;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
    z-index: 2;
    position: relative;
}

[data-theme="dark"] .timeline-cell--today {
    background: #dc2626 !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.5);
}

.timeline-cell:hover {
    background-color: var(--bg-tertiary);
}

.today-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6rem;
    animation: pulse 2s infinite;
    color: white;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.gantt-body {
    flex: 1;
    overflow: auto;
    position: relative;
}

.gantt-body-inner {
    position: relative;
    min-width: min-content;
    height: 100%;
}

.gantt-row {
    display: flex;
    align-items: center;
    min-height: 3rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    min-width: min-content;
    margin: 0;
}

.gantt-row:hover {
    background: var(--bg-tertiary);
}

.gantt-row--highlight {
    background: rgba(255, 255, 0, 0.1);
}

.task-timeline {
    flex: 1;
    position: relative;
    height: 100%;
    min-width: min-content;
}

.task-bar-container {
    position: relative;
    height: 100%;
    width: 100%;
    min-width: min-content;
}

.task-bar {
    position: absolute;
    height: 2rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.task-bar:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.task-progress {
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 0.25rem;
}

.task-bar-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.task-bar-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-bar-progress {
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Content Editable */
[contenteditable="true"] {
    outline: none;
    border-radius: 0.25rem;
    padding: 0.125rem 0.25rem;
    transition: background-color 0.2s;
    border: 1px dashed transparent;
}

[contenteditable="true"]:focus {
    background: rgba(37, 99, 235, 0.1);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
    border-color: var(--primary-color);
}

.date-editable {
    border: 1px dashed transparent;
    border-radius: 0.25rem;
    padding: 0.125rem 0.25rem;
    transition: all 0.2s;
    min-width: 70px;
    display: inline-block;
    text-align: center;
    position: relative;
}

.date-editable:focus {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
    outline: none;
}

.date-editable:hover {
    border-color: var(--border-color);
}

/* Scrollbars */
.timeline-header::-webkit-scrollbar,
.gantt-body::-webkit-scrollbar {
    height: 8px;
}

.timeline-header::-webkit-scrollbar-track,
.gantt-body::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.timeline-header::-webkit-scrollbar-thumb,
.gantt-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.timeline-header::-webkit-scrollbar-thumb:hover,
.gantt-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Print Controls */
.print-controls {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app-main {
        flex-direction: column;
    }

    .task-info {
        width: 200px;
    }

    .timeline-cell {
        min-width: 50px;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .gantt-container {
        margin: 0.5rem;
    }

    .header-main {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .header-controls {
        flex-wrap: wrap;
    }

    .tasks-container {
        width: 100%;
    }
}

@media print {
    .sidebar,
    .print-controls,
    .app-header {
        display: none !important;
    }

    .app-main {
        display: block;
    }

    .gantt-container {
        margin: 0;
        box-shadow: none;
        border-radius: 0;
    }

    .skip-link {
        display: none !important;
    }
}