:root {
    /* Color Palette */
    --bg-base: #0f1115;
    --bg-panel: #161921;
    --bg-surface: #1e222d;
    --bg-hover: #2a2e3b;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-faint: #475569;
    
    --border-subtle: #2d3242;
    --border-strong: #3b4255;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    
    /* Priorities */
    --p1-bg: rgba(239, 68, 68, 0.15);
    --p1-border: #ef4444;
    --p1-text: #fca5a5;
    
    --p2-bg: rgba(245, 158, 11, 0.15);
    --p2-border: #f59e0b;
    --p2-text: #fcd34d;
    
    --p3-bg: rgba(16, 185, 129, 0.15);
    --p3-border: #10b981;
    --p3-text: #6ee7b7;
    
    --p4-bg: rgba(99, 102, 241, 0.15);
    --p4-border: #6366f1;
    --p4-text: #a5b4fc;
    
    /* Layout Constants */
    --header-height: 120px;
    --sidebar-width: 320px;
    --time-col-width: 60px;
    --slot-height: 48px; /* 1 hour height */
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.5);
    --shadow-glass: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

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

/* Header */
.main-header {
    height: var(--header-height);
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    flex: 1;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.logo i {
    width: 24px;
    height: 24px;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.week-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding-bottom: 0.75rem;
}

.week-navigation h2 {
    font-size: 1.1rem;
    font-weight: 500;
    min-width: 200px;
    text-align: center;
}

/* Main Layout */
.calendar-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.task-inbox {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid var(--border-subtle);
}

.daily-summary {
    height: 250px;
    display: flex;
    flex-direction: column;
}

.section-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
}

.section-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.badge {
    background-color: var(--bg-base);
    color: var(--text-main);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-strong);
}

.task-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.summary-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.empty-state-text {
    color: var(--text-faint);
    text-align: center;
    font-style: italic;
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Weekly Grid */
.weekly-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-base);
}

.days-header {
    display: flex;
    padding-left: var(--time-col-width);
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-panel);
}

.day-header-col {
    flex: 1;
    text-align: center;
    padding: 0.75rem 0.5rem;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.day-header-col:hover {
    background-color: var(--bg-hover);
}

.day-header-col.is-today {
    background-color: rgba(59, 130, 246, 0.1);
}

.day-header-col.is-selected {
    border-bottom: 2px solid var(--primary);
}

.day-name {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
}

.day-date {
    font-size: 1.125rem;
    font-weight: 500;
}

.is-today .day-date {
    color: var(--primary);
    font-weight: 700;
}

.time-grid-container {
    flex: 1;
    display: flex;
    overflow-y: auto;
    position: relative;
}

.time-labels {
    width: var(--time-col-width);
    flex-shrink: 0;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
}

.time-label {
    height: var(--slot-height);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-bottom: 1px solid transparent;
}

.time-label span {
    transform: translateY(-50%);
    background-color: var(--bg-panel);
    padding: 0 4px;
}

.days-columns {
    display: flex;
    flex: 1;
    position: relative;
    background-size: 100% var(--slot-height);
    background-image: linear-gradient(to bottom, var(--border-subtle) 1px, transparent 1px);
}

.day-column {
    flex: 1;
    border-right: 1px solid var(--border-subtle);
    position: relative;
    min-height: 100%;
}

.day-column.drag-over, .task-list.drag-over {
    background-color: rgba(255,255,255,0.03);
}

/* Task Item */
.task {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    cursor: grab;
    user-select: none;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: var(--shadow-sm), var(--shadow-glass);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow: hidden;
}

.task:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.task.dragging {
    opacity: 0.5;
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

/* Grid Positional Tasks */
.day-column .task {
    position: absolute;
    left: 4px;
    right: 4px;
    /* Height and Top set via runtime JS */
    z-index: 5;
}

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.task-title {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-duration {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.task-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.task-category {
    background-color: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Priorities */
.task[data-priority="p1"] {
    background-color: var(--p1-bg);
    border-color: var(--p1-border);
}
.task[data-priority="p1"] .task-title { color: var(--p1-text); }

.task[data-priority="p2"] {
    background-color: var(--p2-bg);
    border-color: var(--p2-border);
}
.task[data-priority="p2"] .task-title { color: var(--p2-text); }

.task[data-priority="p3"] {
    background-color: var(--p3-bg);
    border-color: var(--p3-border);
}
.task[data-priority="p3"] .task-title { color: var(--p3-text); }

.task[data-priority="p4"] {
    background-color: var(--p4-bg);
    border-color: var(--p4-border);
}
.task[data-priority="p4"] .task-title { color: var(--p4-text); }


/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

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

.btn.secondary {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-strong);
}
.btn.secondary:hover {
    background-color: var(--bg-hover);
}

.btn.danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn.danger:hover {
    background-color: rgba(239, 68, 68, 0.2);
}

.btn.small {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s;
}
.icon-btn:hover {
    color: var(--text-main);
    background-color: var(--bg-hover);
}
.icon-btn i {
    width: 20px;
    height: 20px;
}

input, select, textarea {
    width: 100%;
    padding: 0.5rem;
    background-color: var(--bg-base);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg), var(--shadow-glass);
    display: flex;
    flex-direction: column;
    transform: scale(1);
    transition: transform 0.2s;
}

.modal-backdrop.hidden .modal {
    transform: scale(0.95);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

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

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

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    align-items: center;
}

.grow {
    flex: 1;
}

.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .calendar-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }
    
    .header-actions #btn-export-ics,
    .header-actions #btn-print {
        display: none;
    }
}

/* Print Styles */
@media print {
    .sidebar, .main-header, .btn, .icon-btn {
        display: none !important;
    }
    .calendar-layout {
        height: auto;
        overflow: visible;
    }
    body {
        background-color: white;
        color: black;
    }
    .time-labels {
        background-color: transparent;
        color: black;
    }
    .days-columns {
        background-image: linear-gradient(to bottom, #ddd 1px, transparent 1px);
    }
    .task {
        box-shadow: none;
        border: 1px solid #aaa;
    }
}
