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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
}

/* Login Screen */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    margin-bottom: 30px;
    color: #333;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn:hover {
    background: #5568d3;
}

.btn-secondary {
    background: #6c757d;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* Main App */
.app-container {
    display: none;
    height: 100vh;
    flex-direction: column;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header h1 {
    font-size: 24px;
    color: #333;
}

.calendar-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calendar-selector select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-small {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-small:hover {
    background: #5568d3;
}

.btn-danger {
    background: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
}

.user-info {
    color: #666;
    font-size: 14px;
}

/* Controls */
.controls {
    background: white;
    padding: 20px 30px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-btn {
    padding: 8px 16px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.nav-btn:hover {
    background: #e0e0e0;
}

.month-display {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.toggle-deleted {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-deleted input[type="checkbox"] {
    width: 40px;
    height: 20px;
    cursor: pointer;
}

/* Calendar */
.calendar-container {
    flex: 1;
    overflow: auto;
    padding: 30px;
    width: 100%;
}

.calendar {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    width: 100%;
    table-layout: fixed;
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    width: 100%;
}

.calendar-header div {
    padding: 15px;
    text-align: center;
    font-weight: 600;
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(120px, auto);
    width: 100%;
}

.calendar-day {
    border: 1px solid #e0e0e0;
    padding: 8px;
    min-height: 120px;
    cursor: pointer;
    transition: background 0.2s;
    overflow: hidden;
    min-width: 0;
}

.calendar-day:hover {
    background: #f8f9fa;
}

.calendar-day.other-month {
    background: #fafafa;
    color: #999;
}

.day-number {
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
}

.calendar-day.other-month .day-number {
    color: #999;
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .header {
        flex-direction: column;
        padding: 10px 15px;
        gap: 10px;
    }

    .header-left {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    .header h1 {
        font-size: 20px;
    }

    .calendar-selector {
        flex-direction: column;
        width: 100%;
    }

    .calendar-selector select {
        width: 100%;
    }

    .header-right {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    .user-info {
        font-size: 12px;
    }

    .controls {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }

    .nav-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .month-display {
        width: 100%;
        text-align: center;
        font-size: 16px;
    }

    .calendar-container {
        padding: 10px;
        overflow-x: hidden;
    }

    .calendar {
        border-radius: 8px;
    }

    .calendar-header div {
        padding: 8px 2px;
        font-size: 12px;
    }

    .calendar-grid {
        grid-auto-rows: minmax(80px, auto);
    }

    .calendar-day {
        padding: 4px;
        min-height: 80px;
    }

    .day-number {
        font-size: 14px;
        margin-bottom: 3px;
    }

    .event-item {
        font-size: 10px;
        padding: 2px 4px;
        margin: 1px 0;
    }

    .more-events {
        font-size: 10px;
        padding: 2px 4px;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
        padding: 20px;
    }

    .modal-header h3 {
        font-size: 18px;
    }

    .btn-small {
        width: 100%;
        margin-bottom: 5px;
        height: 36px;
        line-height: 20px;
    }

    .modal-actions {
        flex-direction: column;
    }
    
    .modal-actions .btn-small {
        width: 100%;
    }

    .form-group input,
    .form-group select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

@media screen and (max-width: 480px) {
    .calendar-header div {
        padding: 5px 1px;
        font-size: 10px;
    }

    .calendar-header div::first-letter {
        font-size: 11px;
    }

    .calendar-grid {
        grid-auto-rows: minmax(70px, auto);
    }

    .calendar-day {
        padding: 2px;
        min-height: 70px;
    }

    .day-number {
        font-size: 12px;
    }

    .event-item {
        font-size: 9px;
        padding: 1px 2px;
    }
}

.event-item {
    background: #667eea;
    color: white;
    padding: 4px 6px;
    margin: 2px 0;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: break-all;
    min-width: 0;
}

.event-item.deleted {
    background: #999;
    text-decoration: line-through;
}

.event-item:hover {
    opacity: 0.9;
}

.more-events {
    color: #667eea;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    text-align: center;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.more-events:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 20px;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    margin-bottom: 20px;
}

.event-details {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.event-details p {
    margin: 8px 0;
    color: #555;
}

.event-details strong {
    color: #333;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
}

.btn-edit {
    background: #28a745;
}

.btn-edit:hover {
    background: #218838;
}

.hidden {
    display: none;
}

.error-message {
    color: #dc3545;
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
}

.source-row {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    align-items: flex-start;
}

.source-row input[type="text"] {
    flex: 1;
}

.source-row input[type="checkbox"] {
    margin-top: 10px;
}

.source-actions {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.btn-remove {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.btn-remove:hover {
    background: #c82333;
}

.color-picker-wrapper {
    position: relative;
    display: inline-block;
}

.color-picker-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-preview-box {
    width: 50px;
    height: 36px;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.color-preview-box:hover {
    border-color: #667eea;
}

.btn-custom-color {
    padding: 6px 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn-custom-color:hover {
    background: #e0e0e0;
}

.color-palette {
    position: absolute;
    top: 42px;
    left: 0;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.color-palette.hidden {
    display: none;
}

.color-option {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.color-option:hover {
    transform: scale(1.15);
    border-color: #333;
}

.color-option.selected {
    border-color: #333;
    border-width: 3px;
}

.advanced-color-picker {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    cursor: move;
}

.advanced-color-picker.hidden {
    display: none;
}

.advanced-color-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    cursor: move;
    user-select: none;
}

.advanced-color-picker-header h4 {
    margin: 0;
    font-size: 16px;
}

.advanced-color-picker input[type="color"] {
    width: 100%;
    height: 150px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.advanced-color-picker-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}