/* CSS custom properties for responsive sizing */
:root {
    --ruler-width: clamp(3rem, 12vw, 7.5rem);          /* Timeline ruler width */
    --tile-padding: clamp(0.5rem, 2vw, 1rem);          /* Habit tile padding */
    --tile-gap: clamp(0.75rem, 3vw, 1.25rem);          /* Gap between tiles */
    --tile-height: clamp(3.5rem, 10vw, 4.375rem);      /* Default tile height */
    --header-height: 5rem;                              /* App header height */
    --fab-size: clamp(3rem, 10vw, 4rem);               /* Floating action button size */
    --touch-target: max(2.75rem, 44px);                 /* Minimum touch target size */
    --timeline-padding: clamp(1rem, 4vw, 2.5rem);      /* Timeline edge padding */
}

/* Remove tap highlight on mobile */
* {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Prevent bounce scrolling on mobile */
body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.overscroll-none {
    overscroll-behavior: none;
}

/* Timeline container setup */
.timeline-container {
    position: relative;
    width: 100%;
}

.timeline-content {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Right-side timeline ruler */
.timeline-ruler {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: var(--ruler-width);
    background: linear-gradient(to right, #f0f0f0 0%, #fafafa 100%);
    border-left: 3px solid #1e293b;
    z-index: 15;
    overflow: visible;
}

/* Ruler tick marks */
.ruler-tick {
    position: absolute;
    left: 0;
    background: #1e293b;
    transform: translateY(-50%);
}

/* Major tick (hours) */
.ruler-tick.major {
    width: min(40%, 1.5rem);
    height: 2px;
}

/* Medium tick (30 minutes) */
.ruler-tick.medium {
    width: min(30%, 1.125rem);
    height: 1.5px;
    background: #475569;
}

/* Minor tick (15 minutes) */
.ruler-tick.minor {
    width: min(20%, 0.75rem);
    height: 1px;
    background: #64748b;
}

/* Micro tick (5 minutes or less) */
.ruler-tick.micro {
    width: min(10%, 0.375rem);
    height: 1px;
    background: #cbd5e1;
}

/* Habit position tick */
.ruler-tick.habit {
    width: min(50%, 1.875rem);
    height: 2px;
    background: #ef4444;
    z-index: 15;
}

/* Time labels on ruler */
.ruler-label {
    position: absolute;
    right: 0;
    font-size: clamp(0.5rem, 1.5vw, 0.75rem);
    font-family: 'Inter', monospace;
    font-weight: 600;
    color: #1e293b;
    transform: translateY(-50%);
    white-space: nowrap;
    padding-right: clamp(0.125rem, 0.5vw, 0.25rem);
    padding-left: clamp(0.25rem, 1vw, 0.5rem);
    text-align: right;
    width: 100%;
    overflow: visible;
}

/* Wake time label styling */
.ruler-label.wake {
    background: #f59e0b;
    color: white;
    font-weight: 700;
    font-size: clamp(0.625rem, 2vw, 0.875rem);
    padding: clamp(0.0625rem, 0.5vw, 0.125rem) clamp(0.1875rem, 1vw, 0.375rem);
    border-radius: 0.25rem;
    z-index: 20;
    right: clamp(0.0625rem, 0.5vw, 0.125rem);
    width: auto;
    max-width: calc(100% - clamp(0.125rem, 1vw, 0.25rem));
	overflow: visible;
}

/* Drag position indicator line */
.drag-position-indicator {
    position: absolute;
    left: 0;
    right: var(--ruler-width);
    height: 2px;
    background: #3b82f6;
    z-index: 25;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}

/* Drag position indicator glow */
.drag-position-indicator::before {
    content: '';
    position: absolute;
    left: 0;
    top: -2px;
    width: 100%;
    height: 6px;
    background: rgba(59, 130, 246, 0.2);
}

/* Drag marker on ruler */
.drag-ruler-marker {
    position: absolute;
    left: -5%;
    width: min(60%, 2.25rem);
    height: 3px;
    background: #3b82f6;
    transform: translateY(-50%);
    z-index: 30;
    pointer-events: none;
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.8);
}

/* Drag marker arrow */
.drag-ruler-marker::after {
    content: '';
    position: absolute;
    right: -8px;
    top: -4px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid #3b82f6;
}

/* Container for habit tiles */
.habits-container {
    position: relative;
    width: 100%;
    padding-bottom: calc(var(--timeline-padding) * 2);
}

/* Individual habit tile */
.event-tile {
    position: absolute;
    left: var(--timeline-padding);
    right: calc(var(--ruler-width) + var(--timeline-padding));
    min-height: var(--tile-height);
    transition: all 0.3s ease;
    z-index: 10;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: var(--tile-padding);
    background: white;
    border-left: 4px solid #3b82f6;
    transform: translateY(calc(var(--tile-height) / -2));
    transform-origin: center top;
}

/* Expanded habit tile */
.event-tile.expanded {
    height: auto;
    z-index: 25;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    transform: translateY(calc(var(--tile-height) / -2));
}

/* Habit tile header section */
.tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: calc(var(--tile-height) - var(--tile-padding) * 2);
}

/* Main content area of tile */
.tile-main {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 2vw, 0.75rem);
    flex: 1;
    min-width: 0;
}

/* Completion checkbox button */
.checkbox-button {
    width: clamp(1.25rem, 4vw, 1.5rem);
    height: clamp(1.25rem, 4vw, 1.5rem);
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
}

/* Checked state for checkbox */
.checkbox-button.checked {
    background: #10b981;
    border-color: #10b981;
    color: white;
    transform: scale(1.1);
}

/* Tile content area */
.tile-content {
    flex: 1;
    min-width: 0;
}

/* Habit title text */
.tile-title {
    font-size: clamp(0.875rem, 3vw, 1rem);
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s ease;
}

/* Completed habit title style */
.tile-title.completed {
    text-decoration: line-through;
    color: #6b7280;
}

/* Metadata row under title */
.tile-meta {
    display: flex;
    align-items: center;
    gap: clamp(0.375rem, 1.5vw, 0.5rem);
    margin-top: 0.125rem;
}

/* Time display text */
.time-display {
    font-family: 'Inter', monospace;
    font-size: clamp(0.688rem, 2.25vw, 0.875rem);
    font-weight: 500;
    color: #4b5563;
}

/* Duration and dynamic badges */
.duration-badge,
.dynamic-badge {
    font-size: clamp(0.563rem, 1.75vw, 0.75rem);
    padding: clamp(0.0625rem, 0.5vw, 0.125rem) clamp(0.25rem, 1vw, 0.375rem);
    border-radius: 0.25rem;
}

/* Duration badge styling */
.duration-badge {
    background: #dbeafe;
    color: #1e40af;
}

/* Dynamic time badge styling */
.dynamic-badge {
    background: #fed7aa;
    color: #c2410c;
}

/* Action buttons container */
.tile-actions {
    display: flex;
    align-items: center;
    gap: clamp(0.25rem, 1vw, 0.5rem);
    flex-shrink: 0;
}

/* Individual action button */
.action-button {
    width: clamp(2.25rem, 8vw, var(--touch-target));
    height: clamp(2.25rem, 8vw, var(--touch-target));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: color 0.2s ease;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-size: clamp(0.875rem, 2.5vw, 1.125rem);
}

/* Action button hover state */
.action-button:hover {
    color: #3b82f6;
}

/* Drag handle cursor */
.drag-handle {
    cursor: grab;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: transform 0.1s ease, opacity 0.1s ease;
}

/* Active drag handle cursor */
.drag-handle:active,
.drag-handle.pressed {
    cursor: grabbing;
    transform: scale(0.95);
    opacity: 0.8;
}

/* Expanded tile content area */
.tile-expanded {
    margin-top: clamp(0.75rem, 2vw, 1rem);
    padding-top: clamp(0.75rem, 2vw, 1rem);
    border-top: 1px solid #e5e7eb;
}

/* Habit description text */
.tile-description {
    color: #4b5563;
    font-size: clamp(0.813rem, 2.25vw, 0.938rem);
    line-height: 1.5;
}

/* Sub-habits container */
.sub-habits {
    margin-top: clamp(0.75rem, 2vw, 1rem);
}

/* Sub-habits title */
.sub-habits-title {
    font-size: clamp(0.813rem, 2.25vw, 0.938rem);
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

/* Individual sub-habit item */
.sub-habit-item {
    background: #f9fafb;
    padding: clamp(0.5rem, 2vw, 0.75rem);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

/* Sub-habit header row */
.sub-habit-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Sub-habit checkbox */
.sub-checkbox {
    width: clamp(1rem, 3vw, 1.25rem);
    height: clamp(1rem, 3vw, 1.25rem);
    border-radius: 0.25rem;
    border: 1px solid #d1d5db;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* Checked sub-habit checkbox */
.sub-checkbox.checked {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

/* Sub-habit description text */
.sub-habit-description {
    font-size: clamp(0.688rem, 1.75vw, 0.813rem);
    color: #6b7280;
    margin-top: 0.375rem;
    padding-left: calc(clamp(1rem, 3vw, 1.25rem) + 0.5rem);
}

/* Current time indicator line */
.current-time-line {
    position: absolute;
    left: 0;
    right: var(--ruler-width);
    height: 3px;
    background: linear-gradient(90deg, #ef4444, #dc2626);
    z-index: 5;
    transition: top 0.1s linear;
    border-radius: 2px;
}

/* Current time indicator dot */
.current-time-line::after {
    content: '';
    position: absolute;
    right: -6px;
    top: -3px;
    width: 9px;
    height: 9px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
}

/* Hour marker lines */
.hour-line {
    position: absolute;
    left: 0;
    right: calc(var(--ruler-width) + 0.25rem);
    height: 1px;
    background: #e2e8f0;
    z-index: 1;
}

/* Major hour lines */
.hour-line.major {
    background: #cbd5e1;
    height: 2px;
}

/* Primary button styling */
.primary-button {
    background: #3b82f6;
    color: white;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1.5rem, 4vw, 2rem);
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: clamp(0.938rem, 3vw, 1.063rem);
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Primary button hover */
.primary-button:hover {
    background: #2563eb;
    transform: scale(1.05);
}

/* Floating action button */
.fab {
    position: fixed;
    bottom: clamp(1.5rem, 5vw, 2rem);
    right: clamp(1.5rem, 5vw, 2rem);
    width: var(--fab-size);
    height: var(--fab-size);
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 50;
    border: none;
    cursor: pointer;
}

/* FAB hover state */
.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

/* Touch target helper class */
.touch-target {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal backdrop overlay */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

/* Modal container */
.modal-container {
    background: white;
    border-radius: 1rem;
    width: 100%;
    max-width: 28rem;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    position: relative;
    z-index: 1001;
}

/* Modal header bar */
.modal-header {
    padding: clamp(1rem, 3vw, 1.5rem);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Modal title text */
.modal-title {
    font-size: clamp(1.125rem, 3vw, 1.25rem);
    font-weight: 600;
}

/* Modal body content */
.modal-body {
    padding: clamp(1rem, 3vw, 1.5rem);
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.25rem);
}

/* Markdown help section */
.markdown-help {
    padding: clamp(0.75rem, 2vw, 1rem);
    background: #eff6ff;
    border-bottom: 1px solid #dbeafe;
}

/* Form input and textarea base styles */
.form-input,
.form-textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: clamp(0.5rem, 2vw, 0.75rem) clamp(0.75rem, 2vw, 1rem);
    font-size: clamp(0.938rem, 2.5vw, 1rem);
    transition: all 0.2s ease;
}

/* Form element focus state */
.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Textarea specific styles */
.form-textarea {
    resize: vertical;
    min-height: 5rem;
}

/* Markdown format buttons */
.format-button {
    padding: 0.25rem;
    color: #6b7280;
    transition: color 0.2s ease;
    background: none;
    border: none;
    cursor: pointer;
    font-size: clamp(0.75rem, 2vw, 0.875rem);
}

/* Format button hover */
.format-button:hover {
    color: #1f2937;
}

/* Tag pill display */
.tag-pill {
    background: #dbeafe;
    color: #1e40af;
    font-size: clamp(0.75rem, 2vw, 0.813rem);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
}

/* Sub-task form container */
.sub-task-form {
    background: #f9fafb;
    padding: clamp(0.75rem, 2vw, 1rem);
    border-radius: 0.5rem;
}

/* Day summary modal */
.summary-modal {
    background: white;
    border-radius: 1rem;
    width: 100%;
    max-width: 28rem;
    padding: clamp(2rem, 5vw, 3rem);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

/* Progress bar animation */
.progress-bar {
    background: linear-gradient(90deg, #3b82f6, #1d4ed8, #3b82f6);
    background-size: 200% 100%;
    animation: gradient-flow 3s ease infinite;
}

/* Progress bar gradient animation */
@keyframes gradient-flow {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* Wake up screen animation */
.wake-up-animation {
    animation: gentle-bounce 2s ease-in-out infinite;
}

/* Gentle bounce animation */
@keyframes gentle-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Summary modal entrance animation */
.summary-enter {
    animation: summary-slide-in 0.5s ease-out;
}

/* Summary slide-in animation */
@keyframes summary-slide-in {
    0% { 
        opacity: 0; 
        transform: scale(0.9) translateY(20px); 
    }
    100% { 
        opacity: 1; 
        transform: scale(1) translateY(0); 
    }
}

/* Habit completion celebration */
.completion-celebration {
    animation: completion-bounce 0.6s ease-out;
}

/* Completion bounce animation */
@keyframes completion-bounce {
    0% { transform: translateY(calc(var(--tile-height) / -2)) scale(1); }
    50% { transform: translateY(calc(var(--tile-height) / -2)) scale(1.1); }
    100% { transform: translateY(calc(var(--tile-height) / -2)) scale(1); }
}

/* Current time pulse animation */
.current-time-indicator {
    animation: pulse-red 2s infinite;
}

/* Red pulse animation */
@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Tag filter button transitions */
.tag-filter {
    transition: all 0.2s ease;
}

/* Tag filter hover effect */
.tag-filter:hover {
    transform: scale(1.05);
}

/* Habit item transitions */
.habit-item {
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Alpine.js cloak helper */
[x-cloak] { 
    display: none !important; 
}

/* Markdown rendered content */
.markdown-content {
    line-height: 1.6;
    word-wrap: break-word;
}

/* Markdown headings */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
}

/* Markdown heading sizes */
.markdown-content h1 { font-size: 1.5em; }
.markdown-content h2 { font-size: 1.3em; }
.markdown-content h3 { font-size: 1.1em; }

/* Markdown paragraphs */
.markdown-content p {
    margin-bottom: 0.75em;
}

/* Markdown lists */
.markdown-content ul,
.markdown-content ol {
    margin-left: 1.5em;
    margin-bottom: 0.75em;
}

/* Markdown links */
.markdown-content a {
    color: #3b82f6;
    text-decoration: underline;
}

/* Markdown link hover */
.markdown-content a:hover {
    color: #2563eb;
}

/* Inline code styling */
.markdown-content code {
    background: #f3f4f6;
    padding: 0.125em 0.25em;
    border-radius: 0.25em;
    font-size: 0.875em;
    font-family: monospace;
}

/* Code block styling */
.markdown-content pre {
    background: #f3f4f6;
    padding: 1em;
    border-radius: 0.5em;
    overflow-x: auto;
    margin-bottom: 0.75em;
}

/* Blockquote styling */
.markdown-content blockquote {
    border-left: 4px solid #e5e7eb;
    padding-left: 1em;
    margin-left: 0;
    color: #6b7280;
    font-style: italic;
}

/* Video embed container */
.video-embed {
    position: relative;
    width: 100%;
    margin: 1em 0;
    border-radius: 0.5em;
    overflow: hidden;
    background: #000;
}

/* YouTube/Vimeo embed aspect ratio */
.youtube-embed,
.vimeo-embed {
    aspect-ratio: 16 / 9;
}

/* Video iframe positioning */
.video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* HTML5 video styling */
.video-embed video {
    width: 100%;
    height: auto;
    max-height: 400px;
}

/* Markdown image link wrapper */
.markdown-image-link {
    display: inline-block;
    margin: 0.5em 0;
}

/* Markdown image styling */
.markdown-image {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

/* Markdown image hover effect */
.markdown-image:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transform: scale(1.02);
}

/* Body cursor during drag */
body.dragging {
    cursor: grabbing !important;
}

/* Override all cursors during drag */
body.dragging * {
    cursor: grabbing !important;
}

/* Reduced motion accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .current-time-indicator {
        animation: none;
    }
}

/* Safe area insets for devices with notches */
@supports (padding: max(0px)) {
    .modal-container {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    .fab {
        bottom: max(clamp(1.5rem, 5vw, 2rem), env(safe-area-inset-bottom));
        right: max(clamp(1.5rem, 5vw, 2rem), env(safe-area-inset-right));
    }
}

/* Hover effects for devices with precise pointers */
@media (hover: hover) and (pointer: fine) {
    .event-tile:hover {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 11;
    }
}

/* Print styles */
@media print {
    /* Hide non-printable elements */
    .no-print,
    button,
    .fixed,
    .fab,
    .action-button {
        display: none !important;
    }
    
    /* Make timeline printable */
    .timeline-container {
        overflow: visible;
    }
    
    /* Adjust tile layout for print */
    .event-tile {
        position: relative;
        margin-bottom: 1rem;
        box-shadow: none;
        border: 1px solid #e5e7eb;
        page-break-inside: avoid;
    }
}