:root {
    font-family: system-ui, -apple-system, sans-serif;
    color: #17324b;
    background: #f4f7fa;
    --surface: #fff;
    --navy: #123b5d;
    --blue: #155d93;
    --border: #ccdbe7;
    --muted: #496479;
    --green-text: #205739;
    --green-bg: #e6f3ea;
}

* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.65rem, 4vw, 2.35rem); }
h2 { font-size: 1.25rem; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    max-width: 100%;
    padding: .5rem .85rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--navy);
    background: var(--surface);
    cursor: pointer;
    font-weight: 600;
    overflow-wrap: anywhere;
}

button:hover, .button:hover { background: #edf4fa; }
button.primary { background: var(--blue); border-color: var(--blue); color: white; }
button.primary:hover { background: var(--navy); }
button.danger { color: #962135; border-color: #e5bac3; }
button:disabled { opacity: .6; cursor: wait; }
:focus-visible { outline: 3px solid #08649e; outline-offset: 3px; }
[hidden] { display: none !important; }

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    padding: .7rem max(16px, calc((100% - 1120px) / 2));
    background: var(--navy);
    color: white;
}

.site-header nav, .controls, .actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.site-header nav a { color: white; padding: .45rem .3rem; }
.site-header :focus-visible { outline-color: white; }
button.logout-button { color: white; background: transparent; border-color: #96b3c9; }
button.logout-button:hover { background: #294f70; }
.skip-link { position: absolute; top: 0; left: 12px; transform: translateY(-150%); background: white; padding: 12px; z-index: 10; }
.skip-link:focus { transform: none; }

main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: clamp(1rem, 3vw, 1.75rem);
    max-width: 1152px;
    margin: auto;
    padding: clamp(12px, 3vw, 28px);
}

.page-heading, .section-heading, .period-bar, .toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .65rem 1rem;
}

.panel, .event-card {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 2px 8px #123b5d0a;
}

.panel { padding: clamp(12px, 3vw, 24px); }
.calendar-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(7rem, max-content); gap: .65rem; }
.calendar-filters label, .upload-form label { display: block; margin-bottom: .3rem; font-weight: 600; }
.period-bar { margin: 1rem 0 .45rem; }
#period::first-letter { text-transform: uppercase; }
#calendar { overflow-x: auto; padding: 4px; }
#status { color: var(--green-text); margin: .7rem 0 0; }
#status:empty { margin: 0; }

input, select, textarea {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: .55rem .65rem;
    color: inherit;
    background: #fff;
    border: 1px solid #a9bdce;
    border-radius: 9px;
}

.weekdays, .month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
    min-width: 338px;
}

.weekdays { margin-bottom: .35rem; text-align: center; font-weight: 700; color: var(--muted); }
.day {
    min-width: 44px;
    min-height: 90px;
    padding: .4rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: .25rem;
    text-align: left;
    overflow: hidden;
}
.day.today { border: 2px solid var(--blue); background: #eff7ff; }
.day.other { color: var(--muted); background: #f5f7fa; }
.event-chip { display: block; padding: .2rem; border-radius: 5px; background: var(--green-bg); color: var(--green-text); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda-group + .agenda-group { margin-top: .85rem; }
.agenda-date { padding: .35rem 0; color: var(--muted); font-size: .95rem; }
.agenda-row {
    display: block;
    width: 100%;
    text-align: left;
    background: #f6f9fc;
    margin-top: .35rem;
}
.agenda-row span { display: block; }
.agenda-time, .event-date { color: var(--muted); font-size: .92rem; }
#count { color: var(--muted); }

.event-feed { display: grid; gap: .75rem; margin-top: .65rem; }
.event-card { display: grid; grid-template-columns: minmax(0, 1fr); overflow: hidden; }
.event-card.has-image { grid-template-columns: minmax(95px, 22%) minmax(0, 1fr); }
.event-card img { width: 100%; height: 100%; min-height: 110px; max-height: 220px; object-fit: cover; }
.event-body { min-width: 0; padding: .9rem; }
.event-body h3 { margin: .2rem 0; }
.event-body p { margin: .25rem 0 0; }
.tag { display: inline-block; background: var(--green-bg); color: var(--green-text); border-radius: 20px; padding: .15rem .5rem; font-size: .82rem; }
.empty { padding: .75rem; margin: 0; color: var(--muted); }
.upload-form { margin-top: .8rem; }
.upload-form input[type=file] { flex: 1 1 16rem; }
.media-library:not(:empty) { margin-top: .75rem; }
.media-thumbnail { object-fit: cover; border-radius: 8px; }
.media-item { margin: 0; display: inline-flex; flex-direction: column; gap: .35rem; align-items: center; }
.media-delete { font-size: .85rem; padding: .3rem .6rem; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(700px, 95vw); max-height: 92dvh; box-shadow: 0 20px 70px #1235; color: inherit; }
dialog::backdrop { background: #0d263b99; }
.modal-inner { padding: clamp(12px, 3vw, 24px); overflow: auto; max-height: 92dvh; }
.toolbar { margin-bottom: .85rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.form-grid label { display: flex; flex-direction: column; gap: .25rem; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.wide { grid-column: 1 / -1; }
.actions { margin-top: .65rem; }
.day-list { display: grid; gap: .5rem; margin: .7rem 0; }
.day-list button { justify-content: flex-start; text-align: left; }
.error { color: #962135; overflow-wrap: anywhere; }
.error:empty { display: none; }

.login-page { background: var(--navy); min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-box { display: block; background: white; border-radius: 14px; padding: clamp(20px, 6vw, 40px); width: min(100%, 420px); margin: auto; }
.login-box form { display: grid; gap: .65rem; }
.login-box h1 { font-size: 1.8rem; }

@media (max-width: 680px) {
    .day { min-height: 70px; padding: .25rem; }
    .weekdays { font-size: .8rem; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .event-card.has-image { grid-template-columns: minmax(0, 1fr); }
    .event-card img { max-height: 160px; }
}

@media (max-width: 400px) {
    .calendar-filters { grid-template-columns: minmax(0, 1fr); }
}

/* Calendar dashboard */
.site-header { background: #15405f; }
.calendar-filters { grid-template-columns: minmax(0, 1fr) minmax(7rem, .36fr) minmax(7rem, .45fr); }
#calendar { overflow-x: auto; padding: 6px; }
.weekdays, .month-grid { min-width: 0; }
.day {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    overflow: visible;
}
.day-number {
    align-self: flex-start;
    min-width: min(44px, 100%);
    padding: .15rem;
    border-color: transparent;
    background: transparent;
}
.day-number[aria-current] { background: var(--blue); color: white; }
.event-chip {
    min-width: 0;
    min-height: 30px;
    width: 100%;
    text-align: left;
    border-color: transparent;
}
.event-chip.more { background: #ecf3f9; color: var(--navy); }
.event-visual { display: flex; flex-direction: column; gap: .5rem; padding: .75rem .75rem 0; }
.has-image .event-visual { padding: .75rem; }
.event-visual img { aspect-ratio: 3 / 2; max-height: none; height: auto; border-radius: 8px; }
.event-tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag.category { background: #ebf2f8; color: var(--navy); }
.event-body h3 { font-size: clamp(1.15rem, 3vw, 1.45rem); }
.event-body h3 a { color: var(--navy); text-underline-offset: .16em; }
.image-options { margin-top: 1rem; border: 1px solid var(--border); border-radius: 9px; padding: .75rem; }
.image-options summary { cursor: pointer; min-height: 44px; align-content: center; font-weight: 700; }
.image-ai { margin: .75rem 0; display: grid; gap: .4rem; justify-items: start; }
#cropPreview { display: block; max-width: 100%; max-height: 280px; width: auto; height: auto; margin: .6rem auto; }
#imageStatus:empty { margin: 0; }
.event-detail { max-width: 960px; }
.detail-hero { overflow: hidden; padding: 0; }
.detail-hero img { display: block; width: 100%; max-height: 420px; object-fit: cover; }
.detail-title { padding: clamp(1rem, 4vw, 2rem); }
.detail-title h1 { margin: .5rem 0; }
.detail-description { white-space: pre-wrap; }
.event-map { width: 100%; height: clamp(220px, 40vw, 380px); margin-top: .75rem; border: 1px solid var(--border); border-radius: 9px; }
.event-detail .button { text-decoration: none; }

@media (max-width: 680px) {
    .calendar-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .calendar-filters > div:first-child { grid-column: 1 / -1; }
    .weekdays, .month-grid { gap: 3px; }
    .day { padding: 2px; min-height: 52px; }
    .calendar-filters label, .event-tags { overflow-wrap: anywhere; }
    .day-number { width: 100%; min-height: 44px; padding: 0; }
    .event-chip { min-height: 30px; padding: .1rem; }
    .event-visual img { max-height: 230px; }
}

@media (max-width: 360px) {
    .calendar-panel { padding-inline: 5px; }
    .weekdays { font-size: min(.8rem, 3.5vw); }
    .day-number { font-size: min(1rem, 5.5vw); }
}

.event-card { position: relative; }
.event-body h3 a::after { content: ''; position: absolute; inset: 0; }
.event-body .actions { position: relative; z-index: 1; width: fit-content; }
