:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #334155;
    
    /* Shift Colors */
    --color-m: #fbbf24; /* Morning - Yellow */
    --color-t: #f97316; /* Afternoon - Orange */
    --color-n: #818cf8; /* Night - Indigo */
    --color-d: #22c55e; /* Rest - Green */
    --color-l: #38bdf8; /* Free - Sky */
    --color-v: #ef4444; /* Vacation - Red */
    --color-none: transparent;
    
    --header-height: 120px;
    --nav-height: 70px;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden; /* Prevent body scroll, use container scroll */
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

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

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 10px;
}

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

.header-actions button {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#today-btn {
    padding: 0.5rem 1rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.weekday-header {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    padding: 0 1rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Calendar Grid */
#calendar-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-auto-rows: 1fr;
    gap: 1px;
    background-color: var(--border);
    overflow-y: auto;
    margin: 0 1rem;
    width: auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.day-cell {
    background-color: var(--bg-color);
    position: relative;
    aspect-ratio: 1 / 1.2;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    overflow: hidden;
}

.btn-icon-only {
    background: none;
    border: none;
    color: var(--text-main);
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-icon-only:hover {
    background: rgba(255,255,255,0.1);
}

.day-cell:active {
    background-color: #1e293b;
}

.day-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.875rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 0 3px rgba(0,0,0,0.8);
    z-index: 5;
    pointer-events: none;
    line-height: 1;
}

.day-cell.other-month {
    opacity: 0.3;
}

.day-cell.today .day-number {
    color: var(--accent);
    text-decoration: underline;
    font-weight: 800;
}

/* Shift Rendering */
.shift-indicator {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.125rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    transition: background-color 0.2s;
}

.shift-split {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.official-part, .modified-part {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.official-part {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0);
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 8px;
}

.modified-part {
    clip-path: polygon(0 0, 100% 100%, 0 100%);
    position: absolute;
    bottom: 0;
    left: 0;
    height: 100%;
    width: 100%;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 8px;
}

/* Bottom Nav */
.bottom-nav {
    height: var(--nav-height);
    background-color: var(--card-bg);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
}

.nav-item.active {
    color: var(--accent);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    z-index: 100;
    transition: opacity 0.3s;
    overflow-y: auto;
    padding: 1rem 0 0 0;
}

.modal {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    animation: slideUp 0.3s ease-out;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    /* Prevent cutting off the top on short screens */
    margin-top: auto; 
}

.modal-content {
    overflow-y: auto;
    flex: 1;
    margin-right: -0.75rem;
    padding-right: 0.75rem;
    padding-bottom: 1.5rem;
    /* Visual cue: fade only at the bottom to show more content */
    -webkit-mask-image: linear-gradient(to bottom, black 92%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 92%, transparent 100%);
    overscroll-behavior: contain;
}

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

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

h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

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

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

.shift-selector {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px;
}

.shift-option {
    aspect-ratio: 1;
    border-radius: 12px;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: pointer;
    color: white;
}

.shift-option.selected {
    border-color: white;
    transform: scale(0.95);
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.shift-option.none {
    border: 2px dashed var(--border);
    color: var(--text-muted);
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

input[type="text"], input[type="date"], input[type="number"], select {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background-color: rgba(15, 23, 42, 0.6); /* Slightly transparent */
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    background-color: rgba(15, 23, 42, 0.9);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2), inset 0 2px 4px rgba(0,0,0,0.1);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background-color: var(--card-bg);
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 0.75rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    font-family: inherit;
}

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

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

.btn-tertiary {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    font-family: inherit;
    flex: 1;
}

.btn-tertiary:active {
    background-color: var(--border);
}

.profile-manager {
    display: flex;
    gap: 10px;
    align-items: center;
}

.profile-manager select {
    flex: 1;
    /* Styles inherited from global select */
}

.profile-actions-inline {
    display: flex;
    gap: 5px;
}

.btn-icon-only {
    background: var(--bg-color);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-only:active {
    transform: scale(0.9);
    background: var(--border);
}

.btn-icon-only.btn-danger {
    color: #ef4444;
}

.backup-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.backup-actions .btn-tertiary {
    background-color: var(--border);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.backup-actions .btn-tertiary:active {
    background-color: var(--accent);
    transform: scale(0.98);
}

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

.shift-edit-row {
    display: grid;
    grid-template-columns: 46px 54px 74px 1fr 34px;
    gap: 8px;
    align-items: center;
    background: #0f172a; /* Solid background for editing */
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.shift-edit-row input.shift-time-input {
    font-weight: 500;
}

.shift-edit-row input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: none;
    cursor: pointer;
}

.shift-edit-row input[type="text"] {
    padding: 0.6rem 0.4rem;
    font-size: 0.9rem;
    text-align: center;
    border-radius: 10px;
    background-color: rgba(30, 41, 59, 0.5);
    min-width: 0; /* Allow shrinking in grid */
}

.btn-delete-shift {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-delete-shift:active {
    background: rgba(239, 68, 68, 0.2);
}

/* Statistics Modal Styles */
.stats-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.total-hours-card {
    background: linear-gradient(135deg, var(--accent) 0%, #1d4ed8 100%);
    padding: 1.5rem;
    border-radius: 16px;
    text-align: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.total-hours-card .label {
    display: block;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.total-hours-card .value {
    display: block;
    font-size: 2.5rem;
    font-weight: 800;
    color: white;
}

.shift-counts-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
}

.shift-count-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.shift-count-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.shift-count-badge .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.shift-count-badge .name {
    font-size: 0.875rem;
    font-weight: 500;
}
/* Sequence Builder */
.sequence-builder {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
}

.sequence-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 44px;
    margin-bottom: 12px;
    padding: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

.sequence-item {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: white;
    cursor: pointer;
    animation: fadeIn 0.1s ease-out;
}

.sequence-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.btn-clear-seq {
    width: 100%;
    background: #450a0a;
    color: #fca5a5;
    border: 1px solid #7f1d1d;
    padding: 8px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Notes */
#day-notes {
    background-color: rgba(15, 23, 42, 0.6);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    width: 100%;
    font-family: inherit;
    resize: none;
}

.note-indicator {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    background-color: #fbbf24;
    color: #0f172a;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

/* Profiles Overlay */
.overlay-profiles-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.overlay-profile-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.3);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
}

.overlay-profile-item.active {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid var(--accent);
}

.overlay-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.mini-indicator {
    height: 3px;
    width: 80%;
    margin: 1px auto;
    border-radius: 1px;
}

/* Print / PDF */
@media print {
    .bottom-nav, .header-actions, .modal-overlay, #pdf-export-btn {
        display: none !important;
    }
    
    /* Specific print modes */
    body.print-calendar #stats-modal, 
    body.print-calendar .bottom-nav,
    body.print-calendar .day-note-text,
    body.print-calendar .note-indicator {
        display: none !important;
    }

    body.print-stats {
        display: none !important;
    }

    body {
        background-color: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
    }
    
    #app {
        height: auto !important;
    }
    
    header {
        background: none !important;
        color: black !important;
        border-bottom: 2px solid #ddd !important;
    }
    
    #calendar-grid {
        background-color: #ddd !important;
        display: grid !important; /* Forces grid back if hidden by stats mode */
        overflow: visible !important;
        margin: 0 !important;
        width: 100% !important;
    }
    
    .day-cell {
        background-color: white !important;
        border: 1px solid #eee !important;
        aspect-ratio: 1 / 1.1 !important;
    }
    
    .day-number {
        color: black !important;
        text-shadow: none !important;
    }
    
    .shift-indicator, .official-part, .modified-part {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
.shift-count-item .count {
    font-weight: 700;
    color: var(--text-main);
}

.version-tag {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.5;
    margin-top: 2rem;
    letter-spacing: 0.1em;
}

/* Phases List */
.phases-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.phase-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.3);
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}

.phase-item.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.phase-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.phase-date {
    font-weight: 600;
    font-size: 0.9rem;
}

.phase-summary {
    font-size: 0.7rem;
    color: var(--text-muted);
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.btn-phase-del {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.active-phase-editor {
    border-top: 1px dashed var(--border);
    margin-top: 16px;
    padding-top: 16px;
    animation: fadeIn 0.3s ease-out;
}
