/* ICS Calendar – Google-Calendar-like styling. All rules are scoped to .ics-calendar */
.ics-calendar {
    --ics-accent: #1a73e8;
    --ics-accent-soft: #e8f0fe;
    --ics-text: #3c4043;
    --ics-text-muted: #70757a;
    --ics-border: #dadce0;
    --ics-border-soft: #e8eaed;
    --ics-bg: #fff;
    --ics-bg-hover: #f1f3f4;
    --ics-now: #ea4335;
    --ics-radius: 8px;
    --ics-hour-height: 48px;
    --ics-gutter: 56px;
    --ics-month-head: 30px;
    --ics-month-lane: 24px;
    --ics-month-lanes: 3;
    --ics-list-width: 340px;
    --ics-font: inherit;
    font-family: var(--ics-font);
    color: var(--ics-text);
    background: var(--ics-bg);
    font-size: 14px;
    line-height: 1.35;
    position: relative;
    box-sizing: border-box;
}
.ics-calendar *,
.ics-calendar *::before,
.ics-calendar *::after { box-sizing: inherit; }
.ics-calendar :where(button) {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    margin: 0;
    padding: 0;
    cursor: pointer;
    text-align: left;
}
.ics-calendar :where(button):focus-visible,
.ics-calendar a:focus-visible { outline: 2px solid var(--ics-accent); outline-offset: 2px; }
.ics-calendar__error { color: var(--ics-now); margin: 0 0 12px; }
.ics-calendar__app[hidden] { display: none; }

/* ---------- Toolbar ---------- */
.ics-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 4px 0 14px;
}
.ics-toolbar__nav { display: flex; align-items: center; gap: 4px; }
.ics-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--ics-border);
    border-radius: 4px;
    background: var(--ics-bg);
    color: var(--ics-text);
    font-weight: 500;
    white-space: nowrap;
    transition: background-color .12s, box-shadow .12s;
}
.ics-btn:hover { background: var(--ics-bg-hover); }
.ics-btn:disabled { opacity: .4; cursor: default; background: var(--ics-bg); }
.ics-btn--icon {
    width: 36px;
    padding: 0;
    border-color: transparent;
    border-radius: 50%;
}
.ics-btn--icon svg { width: 20px; height: 20px; fill: currentColor; }
.ics-toolbar__title {
    font-size: 22px;
    font-weight: 400;
    margin: 0 4px;
    white-space: nowrap;
    color: var(--ics-text);
}
.ics-toolbar__spacer { flex: 1 1 auto; }
.ics-switch {
    display: inline-flex;
    border: 1px solid var(--ics-border);
    border-radius: 4px;
    overflow: hidden;
}
.ics-switch__btn {
    min-height: 34px;
    padding: 0 14px;
    font-weight: 500;
    color: var(--ics-text);
}
.ics-switch__btn + .ics-switch__btn { border-left: 1px solid var(--ics-border); }
.ics-switch__btn:hover { background: var(--ics-bg-hover); }
.ics-switch__btn[aria-pressed="true"] { background: var(--ics-accent-soft); color: var(--ics-accent); }
.ics-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ics-text-muted); }
.ics-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.ics-legend__dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Layout (week + list) ---------- */
.ics-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
.ics-layout--with-list { grid-template-columns: minmax(0, 1fr) var(--ics-list-width); }
.ics-view { min-width: 0; }

/* ---------- Chips (events) ---------- */
.ics-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    height: 22px;
    padding: 0 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    line-height: 22px;
    color: #fff;
    background: var(--ics-color, var(--ics-accent));
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: box-shadow .12s, filter .12s;
}
.ics-chip:hover { box-shadow: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15); filter: brightness(1.05); z-index: 2; }
.ics-chip__text { overflow: hidden; text-overflow: ellipsis; }
.ics-chip__time { font-weight: 400; opacity: .9; }
.ics-chip--timed {
    color: var(--ics-text);
    background: transparent;
}
.ics-chip--timed:hover { background: var(--ics-bg-hover); filter: none; box-shadow: none; }
.ics-chip--timed::before {
    content: "";
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ics-color, var(--ics-accent));
}
.ics-chip--continues-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.ics-chip--continues-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ics-chip--more {
    background: transparent;
    color: var(--ics-text);
    font-weight: 500;
}
.ics-chip--more:hover { background: var(--ics-bg-hover); filter: none; box-shadow: none; }

/* ---------- Week view ---------- */
.ics-week { border: 1px solid var(--ics-border); border-radius: var(--ics-radius); overflow: hidden; background: var(--ics-bg); }
.ics-week__scroll { overflow-x: auto; }
.ics-week__inner { min-width: 100%; }
.ics-week__head,
.ics-week__allday,
.ics-week__body {
    display: grid;
    grid-template-columns: var(--ics-gutter) repeat(var(--ics-days, 7), minmax(0, 1fr));
}
.ics-week__head { border-bottom: 1px solid var(--ics-border); }
.ics-week__corner { border-right: 1px solid var(--ics-border); }
.ics-week__dayhead {
    padding: 8px 4px 6px;
    text-align: center;
    border-right: 1px solid var(--ics-border-soft);
    cursor: default;
}
.ics-week__dayhead:last-child { border-right: 0; }
.ics-week__dow {
    display: block;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--ics-text-muted);
}
.ics-week__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-top: 2px;
    border-radius: 50%;
    font-size: 24px;
    font-weight: 400;
    color: var(--ics-text);
}
.ics-week__dayhead.is-today .ics-week__dow { color: var(--ics-accent); }
.ics-week__dayhead.is-today .ics-week__num { background: var(--ics-accent); color: #fff; }
.ics-week__dayhead.is-weekend .ics-week__num { color: var(--ics-text-muted); }

.ics-week__allday { border-bottom: 1px solid var(--ics-border); min-height: 30px; }
.ics-week__allday-label {
    padding: 4px 4px 4px 0;
    font-size: 10px;
    color: var(--ics-text-muted);
    text-align: right;
    border-right: 1px solid var(--ics-border);
    align-self: start;
}
.ics-week__allday-grid {
    grid-column: 2 / -1;
    display: grid;
    grid-template-columns: repeat(var(--ics-days, 7), minmax(0, 1fr));
    grid-auto-rows: 24px;
    gap: 2px 0;
    padding: 3px 0;
    position: relative;
}
.ics-week__allday-grid .ics-chip { margin: 0 4px; width: calc(100% - 8px); }
.ics-week__allday-grid .ics-chip--continues-left { margin-left: 0; width: calc(100% - 4px); }
.ics-week__allday-grid .ics-chip--continues-right { margin-right: 0; width: calc(100% - 4px); }
.ics-week__allday-grid .ics-chip--continues-left.ics-chip--continues-right { margin: 0; width: 100%; }
.ics-week__allday-bg {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: repeat(var(--ics-days, 7), minmax(0, 1fr));
    pointer-events: none;
}
.ics-week__allday-bg > div { border-right: 1px solid var(--ics-border-soft); }
.ics-week__allday-bg > div:last-child { border-right: 0; }

.ics-week__body { position: relative; }
.ics-week__gutter { position: relative; border-right: 1px solid var(--ics-border); }
.ics-week__hour {
    height: var(--ics-hour-height);
    position: relative;
}
.ics-week__hour-label {
    position: absolute;
    top: -7px;
    right: 8px;
    font-size: 10px;
    color: var(--ics-text-muted);
    white-space: nowrap;
}
.ics-week__hour:first-child .ics-week__hour-label { display: none; }
.ics-week__col {
    position: relative;
    border-right: 1px solid var(--ics-border-soft);
    background-image: linear-gradient(to bottom, var(--ics-border-soft) 1px, transparent 1px);
    background-size: 100% var(--ics-hour-height);
    min-height: 40px;
}
.ics-week__col:last-child { border-right: 0; }
.ics-week__col.is-today { background-color: rgba(26, 115, 232, .03); }
.ics-week__event {
    position: absolute;
    display: block;
    padding: 3px 6px;
    border-radius: 4px;
    background: var(--ics-color, var(--ics-accent));
    color: #fff;
    font-size: 12px;
    line-height: 1.3;
    overflow: hidden;
    border: 1px solid var(--ics-bg);
    transition: box-shadow .12s, filter .12s;
    width: calc(var(--ics-w) - 4px);
    left: calc(var(--ics-l) + 1px);
}
.ics-week__event:hover { box-shadow: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15); filter: brightness(1.05); z-index: 3; }
.ics-week__event-title { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ics-week__event-time { display: block; opacity: .92; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ics-week__event.is-short { padding-top: 1px; padding-bottom: 1px; line-height: 1.2; }
.ics-week__event.is-short .ics-week__event-title { display: inline; }
.ics-week__event.is-short .ics-week__event-time { display: inline; }
.ics-week__event.is-short .ics-week__event-time::before { content: ", "; }
.ics-week__now {
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background: var(--ics-now);
    z-index: 4;
    pointer-events: none;
}
.ics-week__now::before {
    content: "";
    position: absolute;
    left: -6px; top: -5px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--ics-now);
}

/* ---------- Month view ---------- */
.ics-month { border: 1px solid var(--ics-border); border-radius: var(--ics-radius); overflow: hidden; background: var(--ics-bg); }
.ics-month__head {
    display: grid;
    grid-template-columns: repeat(var(--ics-days, 7), minmax(0, 1fr));
    border-bottom: 1px solid var(--ics-border);
}
.ics-month__dow {
    padding: 8px 4px 6px;
    text-align: center;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--ics-text-muted);
}
.ics-month__row {
    position: relative;
    min-height: calc(var(--ics-month-head) + var(--ics-month-lanes) * var(--ics-month-lane) + 6px);
    border-bottom: 1px solid var(--ics-border-soft);
}
.ics-month__row:last-child { border-bottom: 0; }
.ics-month__cells {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: repeat(var(--ics-days, 7), minmax(0, 1fr));
}
.ics-month__cell {
    border-right: 1px solid var(--ics-border-soft);
    text-align: center;
    padding-top: 4px;
    cursor: default;
}
.ics-month__cell:last-child { border-right: 0; }
.ics-month__cell.is-other { background: #fafafa; }
.ics-month__cell.is-other .ics-month__daynum { color: var(--ics-text-muted); }
.ics-month__daynum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 4px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ics-text);
    background: transparent;
}
.ics-month__cell.is-today .ics-month__daynum { background: var(--ics-accent); color: #fff; }
.ics-month__cell.is-clickable { cursor: pointer; }
.ics-month__cell.is-clickable:hover .ics-month__daynum:not(.is-today) { background: var(--ics-bg-hover); }
.ics-month__events {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--ics-days, 7), minmax(0, 1fr));
    grid-auto-rows: var(--ics-month-lane);
    padding: var(--ics-month-head) 0 4px;
    pointer-events: none;
}
.ics-month__events .ics-chip { pointer-events: auto; margin: 0 4px; width: calc(100% - 8px); }
.ics-month__events .ics-chip--continues-left { margin-left: 0; width: calc(100% - 4px); }
.ics-month__events .ics-chip--continues-right { margin-right: 0; width: calc(100% - 4px); }
.ics-month__events .ics-chip--continues-left.ics-chip--continues-right { margin: 0; width: 100%; }

/* ---------- List (schedule) panel ---------- */
.ics-list { min-width: 0; }
.ics-list__month {
    margin: 0 0 8px;
    padding: 8px 0 6px;
    font-size: 15px;
    font-weight: 500;
    color: var(--ics-text);
    border-bottom: 1px solid var(--ics-border);
}
.ics-list__month + .ics-list__month { margin-top: 20px; }
.ics-list__day {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--ics-border-soft);
}
.ics-list__date { text-align: center; line-height: 1.1; padding-top: 4px; }
.ics-list__date-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 400;
}
.ics-list__date-dow { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--ics-text-muted); margin-top: 2px; }
.ics-list__day.is-today .ics-list__date-num { background: var(--ics-accent); color: #fff; }
.ics-list__day.is-today .ics-list__date-dow { color: var(--ics-accent); }
.ics-list__items { display: flex; flex-direction: column; gap: 2px; }
.ics-list__item {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    width: 100%;
    padding: 5px 8px;
    border-radius: 6px;
}
.ics-list__item:hover { background: var(--ics-bg-hover); }
.ics-list__dot { width: 10px; height: 10px; margin-top: 4px; border-radius: 3px; background: var(--ics-color, var(--ics-accent)); }
.ics-list__title { font-weight: 500; }
.ics-list__meta { font-size: 12px; color: var(--ics-text-muted); }
.ics-list__empty { color: var(--ics-text-muted); padding: 12px 0; }
.ics-list__heading { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .8px; color: var(--ics-text-muted); margin: 0 0 4px; }

/* ---------- Popover ---------- */
.ics-popover {
    position: absolute;
    z-index: 50;
    width: 360px;
    max-width: calc(100vw - 24px);
    padding: 18px 20px 20px;
    border-radius: var(--ics-radius);
    background: var(--ics-bg);
    color: var(--ics-text);
    box-shadow: 0 1px 3px rgba(60,64,67,.3), 0 8px 24px 6px rgba(60,64,67,.2);
    animation: ics-pop .12s ease-out;
}
@keyframes ics-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ics-popover__close {
    position: absolute;
    top: 8px; right: 8px;
    width: 36px; height: 36px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ics-text-muted);
}
.ics-popover__close:hover { background: var(--ics-bg-hover); }
.ics-popover__close svg { width: 20px; height: 20px; fill: currentColor; }
.ics-popover__head { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 12px; align-items: start; padding-right: 32px; }
.ics-popover__color { width: 14px; height: 14px; margin-top: 4px; border-radius: 4px; background: var(--ics-color, var(--ics-accent)); }
.ics-popover__title { margin: 0; font-size: 20px; font-weight: 400; line-height: 1.25; overflow-wrap: anywhere; }
.ics-popover__date { margin: 4px 0 0; font-size: 14px; color: var(--ics-text); }
.ics-popover__rows { margin: 14px 0 0; display: flex; flex-direction: column; gap: 10px; }
.ics-popover__row { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 12px; align-items: start; font-size: 14px; }
.ics-popover__row svg { width: 20px; height: 20px; fill: var(--ics-text-muted); }
.ics-popover__desc { white-space: pre-line; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }
.ics-popover__calendar { color: var(--ics-text-muted); font-size: 13px; }
.ics-popover a { color: var(--ics-accent); text-decoration: none; overflow-wrap: anywhere; }
.ics-popover a:hover { text-decoration: underline; }
.ics-popover__daylist { margin: 6px 0 0; display: flex; flex-direction: column; gap: 2px; }
.ics-popover__daylist .ics-chip { height: 26px; line-height: 26px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .ics-calendar { --ics-list-width: 300px; }
}
@media (max-width: 900px) {
    .ics-layout--with-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
    .ics-calendar { --ics-gutter: 44px; --ics-month-lane: 8px; --ics-month-lanes: 4; --ics-month-head: 30px; }
    .ics-toolbar__title { font-size: 18px; }
    .ics-week__inner { min-width: 640px; }
    .ics-week__num { width: 32px; height: 32px; font-size: 18px; }
    .ics-month__events .ics-chip { height: 6px; line-height: 6px; padding: 0; border-radius: 3px; font-size: 0; }
    .ics-month__events .ics-chip--timed { background: var(--ics-color, var(--ics-accent)); }
    .ics-month__events .ics-chip--timed::before { display: none; }
    .ics-month__events .ics-chip--more { display: none; }
    .ics-month__row { min-height: calc(var(--ics-month-head) + var(--ics-month-lanes) * var(--ics-month-lane) + 12px); }
    .ics-popover {
        position: fixed;
        left: 12px !important; right: 12px !important; top: auto !important; bottom: 12px !important;
        width: auto; max-width: none;
        max-height: 80vh; overflow: auto;
    }
}
@media print {
    .ics-toolbar .ics-btn, .ics-switch { display: none; }
    .ics-popover { display: none; }
}

/* ---------- Lazy loading state ---------- */
.ics-toolbar__status { font-size: 12px; color: var(--ics-text-muted); min-height: 1em; }
.ics-toolbar__status.is-error { color: var(--ics-now); }
.ics-calendar__app.is-loading .ics-view,
.ics-calendar__app.is-loading .ics-list { opacity: .6; transition: opacity .15s; }
