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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #fbf9f5;
    color: #362f28;
}

.hidden {
    display: none !important;
}

.calendar-app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh; /* Kan växa nedåt när en vecka har många händelser */
}

/* Toppmeny - Varm havre med skogsgröna länkar */
.top-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 14px;
    padding: 9px 12px;
    background: #f2ede4;
    border-bottom: 1px solid #e2d9c8;
    font-size: 14px;
}

.top-nav a {
    color: #3b5241;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s;
}

.top-nav a:hover {
    color: #1f3325;
}

.top-nav a.active {
    color: #1f3325;
    font-weight: 700;
    border-bottom: 2px solid #486b52;
    padding-bottom: 2px;
}

.logout-link {
    margin-left: auto;
    color: #7a6f63 !important;
    font-size: 13px;
}

/* Månadsrubrik */
.cal-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 8px 16px;
    background: #fbf9f5;
}

.cal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #2d4233;
    min-width: 155px;
    text-align: center;
    text-transform: capitalize;
}

.nav-btn {
    background: #f2ede4;
    border: 1px solid #dfd6c7;
    border-radius: 6px;
    color: #3b5241;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 10px;
}

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

/* VIKTIGT: 7 lika breda kolumner för både veckodagsraden och varje veckorad */
.cal-weekdays,
.cal-week-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-weekdays {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #756a5e;
    padding: 6px 0;
    background: #f6f2eb;
    border-top: 1px solid #e4dccf;
    border-bottom: 1px solid #e4dccf;
}

.cal-weekdays .sun {
    color: #b0573b;
}

/* Själva rutnätet */
.cal-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.cal-week-row {
    flex: 1 0 auto; /* Växer fritt på höjden när det är många händelser */
    border-bottom: 1px solid #ebe5da;
    min-height: 110px;
}

/* Varje enskild dag-ruta */
.day-cell {
    border-right: 1px solid #ebe5da;
    padding: 3px 2px 6px 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    cursor: pointer;
    background: #fbf9f5;
}

.day-cell:last-child {
    border-right: none;
}

.day-cell.other-month {
    background: #f4f0e8;
}

.day-cell.other-month .day-num {
    color: #b5aba0;
}

/* Toppraden i varje dag: Datum till vänster, veckonummer till höger */
.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 3px;
    margin-bottom: 1px;
    min-height: 22px;
}

.day-num {
    font-size: 12px;
    font-weight: 600;
    color: #423930;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    border-radius: 50%;
}

/* Dagens datum */
.day-cell.today {
    background: #f5eedc;
}

.day-cell.today .day-num {
    background: #486b52;
    color: #ffffff;
}

/* Veckonummer uppe till höger i måndagsrutan */
.week-num {
    font-size: 10px;
    color: #9c9184;
    font-weight: 500;
}

/* Händelse-bubblor som aldrig trycks ihop på höjden */
.event-chip {
    flex-shrink: 0;
    font-size: 10.5px;
    line-height: 1.35;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    font-weight: 500;
}

.event-chip.standard {
    background: #e8dfd1;
    color: #382b1e;
}

.event-chip.recurrent {
    background: #dce8de;
    color: #1f3d27;
}

.event-chip.birthday {
    background: #f5dce0;
    color: #5e1926;
    border-left: 3px solid #c45166;
    font-weight: 600;
}

/* Röda dagar (t.ex. Alla helgons dag, Juldagen) */
.event-chip.holiday-red {
    background: #f5d8d4;
    color: #7a1c14;
    border-left: 3px solid #bf3b2e;
    font-weight: 600;
}

/* Aftnar & Högtider (t.ex. Allhelgonaafton, Halloween, Vintertid) */
.event-chip.holiday-eve {
    background: #f2e2e4;
    color: #6e353e;
    border-left: 3px solid #b86b77;
}

/* Gör även själva datumsiffran röd på röda helgdagar */
.day-num.red-day-num {
    color: #b0573b;
}

/* Matcha i detalj-modalen */
.modal-event-item.holiday-red {
    border-left-color: #bf3b2e;
    background: #fcf0ee;
    color: #7a1c14;
}

.modal-event-item.holiday-eve {
    border-left-color: #b86b77;
    background: #faf2f3;
    color: #6e353e;
}

/* Soluppgång och solnedgång */
.sun-info {
    flex-shrink: 0;
    font-size: 10px;
    color: #756a5e;
    padding: 0 3px;
    line-height: 1.3;
    white-space: nowrap;
}

@media (min-width: 769px) {
    .sun-info {
        font-size: 11px;
    }
}

/* Flytande + knapp */
.fab-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: #486b52;
    color: #ffffff;
    font-size: 28px;
    border: none;
    box-shadow: 0 4px 14px rgba(45, 66, 51, 0.25);
    cursor: pointer;
}

/* Detalj-popup när man klickar på en dag */
.day-modal {
    margin: auto;
    width: min(92vw, 420px);
    border: none;
    border-radius: 12px;
    padding: 0;
    background: #fbf9f5;
    box-shadow: 0 10px 30px rgba(45, 38, 30, 0.22);
}

.day-modal::backdrop {
    background: rgba(45, 38, 30, 0.35);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: #f2ede4;
    border-bottom: 1px solid #e2d9c8;
    color: #2d4233;
}

.close-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #756a5e;
}

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 65vh;
    overflow-y: auto;
}

.modal-event-item {
    padding: 9px 12px;
    border-left: 4px solid #9c8468;
    background: #f2ece1;
    color: #382b1e;
    border-radius: 4px;
}

.modal-event-item.recurrent {
    border-left-color: #648c6d;
    background: #ebf2ec;
    color: #1f3d27;
}

.modal-event-time {
    font-size: 12px;
    opacity: 0.8;
    font-weight: 600;
}

.modal-event-title {
    font-size: 14px;
    font-weight: 600;
    margin-top: 2px;
}

.modal-event-desc {
    font-size: 13px;
    opacity: 0.9;
    margin-top: 4px;
}

/* Inloggningsvy */
.login-overlay {
    position: fixed;
    inset: 0;
    background: #f2ede4;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
}

.login-card {
    background: #fbf9f5;
    width: 100%;
    max-width: 340px;
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #e4dccf;
    box-shadow: 0 4px 20px rgba(45, 38, 30, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-card h2 {
    color: #2d4233;
    text-align: center;
    margin-bottom: 6px;
}

.login-card label {
    font-size: 13px;
    font-weight: 600;
    color: #52473d;
}

.login-card input {
    padding: 10px 12px;
    border: 1px solid #d4c9b8;
    background: #ffffff;
    border-radius: 6px;
    font-size: 16px;
}

.login-btn {
    margin-top: 8px;
    padding: 12px;
    background: #486b52;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.login-error {
    background: #f9e6e2;
    color: #8f2d1e;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    text-align: center;
}

/* Mobil vs Desktop */
.d-long,
.event-time {
    display: none;
}

@media (min-width: 769px) {
    .d-short { display: none; }
    .d-long, .event-time { display: inline; }
    .day-cell { padding: 4px 6px; }
    .day-num { font-size: 13px; }
    .week-num { font-size: 11px; }
    .event-chip { font-size: 12px; padding: 2px 6px; }
}

/* Modal för Ny Händelse / Avancerat */
.entry-modal {
    margin: auto;
    width: min(94vw, 680px);
    border: 1px solid #d4c9b8;
    border-radius: 8px;
    padding: 20px 24px;
    background: #fbf9f5;
    box-shadow: 0 10px 30px rgba(45, 38, 30, 0.22);
}

.entry-modal::backdrop {
    background: rgba(45, 38, 30, 0.35);
}

.entry-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.entry-form h3 {
    color: #5c5349;
    font-size: 18px;
    margin-bottom: 6px;
}

.entry-form label {
    font-size: 14px;
    color: #362f28;
    margin-top: 4px;
}

.entry-form input[type="text"],
.entry-form input[type="date"],
.entry-form input[type="datetime-local"],
.entry-form select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #b5aba0;
    border-radius: 4px;
    background: #ffffff;
    font-size: 15px;
    color: #222;
}

#simple-fields,
#advanced-fields,
#recurrent-fields {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0 4px 0;
    cursor: pointer;
    font-size: 15px;
}

.weekdays-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin: 8px 0;
}

.weekdays-group .group-label {
    align-self: center;
    font-size: 14px;
    margin-bottom: 2px;
}

.weekdays-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    cursor: pointer;
}

.submit-entry-btn {
    width: 100%;
    margin-top: 12px;
    padding: 9px 16px;
    background: #e8dfd1;
    border: 1px solid #b5aba0;
    border-radius: 4px;
    color: #362f28;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

.submit-entry-btn:hover {
    background: #dfd3c0;
}

.entry-form-links {
    display: flex;
    gap: 28px;
    margin-top: 10px;
}

.entry-form-links a {
    color: #486b52;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
}

.entry-form-links a:hover {
    text-decoration: underline;
}

.entry-form-links a.delete-link {
    color: #b0573b;
}