:root {
    /* Light Theme (Paper aesthetic) */
    --bg-color: #FEFCE8;
    --surface-color: #FFFFFF;
    --text-main: #1F2937;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --border-faint: #F3F4F6;
    --primary-color: #F59E0B;
    --primary-hover: #D97706;
    --danger-color: #EF4444;
    
    /* Block Colors */
    --color-blue: #DBEAFE;
    --color-blue-border: #93C5FD;
    --color-blue-text: #1E3A8A;
    
    --color-green: #D1FAE5;
    --color-green-border: #6EE7B7;
    --color-green-text: #065F46;
    
    --color-yellow: #FEF3C7;
    --color-yellow-border: #FCD34D;
    --color-yellow-text: #92400E;
    
    --color-red: #FEE2E2;
    --color-red-border: #FCA5A5;
    --color-red-text: #991B1B;
    
    --color-purple: #EDE9FE;
    --color-purple-border: #C4B5FD;
    --color-purple-text: #5B21B6;

    /* Shadows & Radii */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius-sm: 4px;
    --radius-md: 8px;
    
    /* Dimensions */
    --header-height: 60px;
    --time-column-width: 50px;
    --hour-height: 48px;
}

[data-theme="dark"] {
    --bg-color: #111827;
    --surface-color: #1F2937;
    --text-main: #F9FAFB;
    --text-muted: #9CA3AF;
    --border-color: #374151;
    --border-faint: #1F2937;
    --primary-color: #F59E0B;
    
    /* Dark Theme Block Colors */
    --color-blue: #1E3A8A;
    --color-blue-border: #3B82F6;
    --color-blue-text: #DBEAFE;
    
    --color-green: #064E3B;
    --color-green-border: #10B981;
    --color-green-text: #D1FAE5;
    
    --color-yellow: #78350F;
    --color-yellow-border: #F59E0B;
    --color-yellow-text: #FEF3C7;
    
    --color-red: #7F1D1D;
    --color-red-border: #EF4444;
    --color-red-text: #FEE2E2;
    
    --color-purple: #4C1D95;
    --color-purple-border: #8B5CF6;
    --color-purple-text: #EDE9FE;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    /* Paper texture overlay could go here, for now solid color */
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Crimson Pro', serif;
    font-weight: 600;
}

/* Base Form Elements */
input[type="text"], textarea {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px dashed var(--border-color);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    padding: 4px 0;
    outline: none;
    resize: none;
}
input[type="text"]:focus, textarea:focus {
    border-bottom-color: var(--primary-color);
}
textarea {
    min-height: 60px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: rgba(255, 255, 255, 0.5);
}
[data-theme="dark"] textarea {
    background: rgba(0, 0, 0, 0.2);
}

/* Buttons */
button {
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}
.icon-btn:hover {
    background: var(--border-color);
}
.text-btn {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.text-btn:hover {
    background: var(--border-color);
}
.action-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    font-weight: 500;
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
}
.action-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.primary-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: var(--primary-color);
    color: white;
    font-weight: 500;
}
.primary-btn:hover {
    background: var(--primary-hover);
}
.secondary-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.secondary-btn:hover {
    background: var(--border-faint);
}
.danger-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--danger-color);
}
.danger-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* App Container and Header */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.header-left h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin: 0;
}

.week-navigation {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.week-navigation h2 {
    font-size: 1.25rem;
    min-width: 200px;
    text-align: center;
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
}

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

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

/* Sidebar Widgets */
.sidebar {
    width: 320px;
    min-width: 320px;
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.widget {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.widget h3 {
    font-size: 1.125rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.875rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.25rem;
}

/* Top Priorities */
.checklist {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.checklist li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.priority-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Priority Matrix */
.matrix-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 0.5rem;
}
.quadrant {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.quadrant h4 {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    text-align: center;
}
.quadrant textarea {
    flex: 1;
    min-height: 80px;
    font-size: 0.75rem;
    padding: 4px;
    border: none;
    background: transparent;
}
.q-urgent-important h4 { color: var(--danger-color); }
.q-not-urgent-important h4 { color: var(--primary-color); }
.q-urgent-not-important h4 { color: #3B82F6; }

/* Habit Tracker */
.habits-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    padding-right: 0.5rem;
}
.habit-name-spacer {
    flex: 1;
}
.days-header {
    display: flex;
    gap: 0.25rem;
}
.days-header span {
    width: 20px;
    text-align: center;
}
.habits-checklist {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.habit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.habit-row input[type="text"] {
    flex: 1;
    margin-right: 0.5rem;
    min-width: 0;
}
.habit-days {
    display: flex;
    gap: 0.25rem;
}
.habit-days input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-color);
}
.add-habit-btn {
    font-size: 0.75rem;
    color: var(--primary-color);
    justify-content: flex-start;
    padding: 0.25rem 0;
}
.add-habit-btn:hover {
    text-decoration: underline;
}

/* Brain Dump & Review */
.brain-dump textarea {
    min-height: 120px;
}
.review-prompt {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.review-prompt label {
    font-size: 0.8rem;
    font-weight: 500;
}
.review-prompt textarea {
    min-height: 60px;
}

/* Time Grid Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}

.time-grid-container {
    display: flex;
    min-height: 100%;
}

.time-labels {
    width: var(--time-column-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--surface-color);
    position: sticky;
    left: 0;
    z-index: 10;
}
.time-label {
    height: var(--hour-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; /* matches the grid lines */
    transform: translateY(-50%); /* aligns text with line */
}
/* We add a dummy label at the top to push everything down by half an hour, 
   but it's better to just offset the days columns or handle it in JS */

.days-columns {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.day-column {
    border-right: 1px solid var(--border-color);
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
}
.day-header {
    height: var(--header-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--surface-color);
    z-index: 5;
}
.day-name {
    font-weight: 600;
    font-size: 0.875rem;
}
.day-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.day-column.is-today .day-header {
    color: var(--primary-color);
}

.grid-slots {
    position: relative;
    flex: 1;
    background-image: linear-gradient(var(--border-faint) 1px, transparent 1px);
    background-size: 100% var(--hour-height);
}

/* Scheduled Blocks */
.time-block {
    position: absolute;
    left: 4px;
    right: 4px;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.2;
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border-left-width: 3px;
    border-left-style: solid;
    transition: transform 0.1s, box-shadow 0.1s;
    user-select: none;
}
.time-block:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    z-index: 2;
}
.time-block .block-title {
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.2s;
}
.modal.hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-content {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.modal-content h3 {
    margin: 0;
    font-size: 1.25rem;
    font-family: 'Inter', sans-serif;
}
.modal-content input[type="text"] {
    font-size: 1rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.modal-color-picker {
    display: flex;
    gap: 0.5rem;
}
.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
}
.color-btn.selected {
    border-color: var(--text-main);
    transform: scale(1.1);
}
.modal-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
}
.right-actions {
    display: flex;
    gap: 0.5rem;
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }
    .app-container {
        height: auto;
    }
    .planner-layout {
        flex-direction: column;
        overflow: visible;
    }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        padding: 0 0 1.5rem 0;
        margin-bottom: 1.5rem;
    }
    .main-content {
        overflow: visible;
    }
    .time-grid-container {
        page-break-inside: avoid;
    }
    body {
        --bg-color: #FFFFFF;
        background: white;
    }
    /* Ensure colors print correctly */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
