:root {
    --blue: #BFDDF7;
    --green: #C6EBD3;
    --purple: #D9CCF5;
    --blue-deep: #7FB3E6;
    --green-deep: #8FD1AA;
    --purple-deep: #A992E3;
    --ink: #2E2A3B;
    --muted: #6E6982;
    --bg: #F7F6FB;
    --surface: #FFFFFF;
    --line: #E7E4F0;
    --danger: #C2415B;
    --gradient: linear-gradient(135deg, var(--blue-deep) 0%, var(--purple-deep) 50%, var(--green-deep) 100%);
    --shadow: 0 6px 24px rgba(46, 42, 59, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

h1, h2, h3, .logo { font-family: 'Fredoka', 'Inter', system-ui, sans-serif; font-weight: 600; }
h1 { margin: 0 0 24px; font-size: 1.9rem; }
h2 { margin: 0 0 8px; font-size: 1.2rem; }
a { color: inherit; }
.muted { color: var(--muted); }

/* ---- Loading bar (see layout.php) ------------------------------- */
html.is-loading body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
    height: 3px;
    width: 90%;
    background: var(--gradient);
    animation: loading 4s cubic-bezier(.1, .8, .2, 1);
}
@keyframes loading { from { width: 0; } }

/* ---- Logo ------------------------------------------------------- */
.logo { text-decoration: none; letter-spacing: -.01em; color: #fff; }
.logo span { opacity: .7; }
.logo--ink { color: var(--ink); font-size: 1.35rem; }

/* ---- Holding + login (gradient pages) --------------------------- */
.gradient-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--gradient);
}
.holding-logo {
    font-size: clamp(2.4rem, 9vw, 5.5rem);
    text-shadow: 0 2px 18px rgba(46, 42, 59, .18);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: 18px;
    padding: 32px 28px;
    box-shadow: 0 20px 50px rgba(46, 42, 59, .18);
}
.login-card .logo { display: block; text-align: center; margin-bottom: 24px; font-size: 1.6rem; }

/* ---- Forms ------------------------------------------------------ */
label { display: block; font-weight: 500; font-size: .92rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=time], textarea, select {
    width: 100%;
    padding: 11px 13px;
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}
input:focus-visible, .btn:focus-visible, a:focus-visible {
    outline: 3px solid var(--blue-deep);
    outline-offset: 2px;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 22px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--purple-deep); }

.btn {
    display: inline-block;
    width: 100%;
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--ink);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}
.btn:hover { background: #46405A; }
.btn--small { width: auto; padding: 8px 14px; font-size: .9rem; }

.alert {
    padding: 10px 12px;
    margin-bottom: 16px;
    border-radius: 10px;
    background: #FBE8EC;
    color: var(--danger);
    font-size: .92rem;
}

/* ---- App shell: top bar (desktop) / burger menu (phones) --------- */
.app { min-height: 100vh; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 10px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.topnav { display: flex; gap: 4px; }
.nav-link {
    display: block;
    padding: 8px 14px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 500;
}
.nav-link:hover { background: var(--bg); }
.nav-link.is-active { background: var(--purple); }

.profile { position: relative; margin-left: auto; }
.profile-btn { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--purple); color: var(--ink); cursor: pointer; }
.profile-btn:hover, .profile-btn[aria-expanded="true"], .profile-btn.is-active { background: var(--purple-deep); color: #fff; }
.profile-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 190px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.profile-menu .nav-link { padding: 8px 12px; }
.profile-name { display: block; padding: 6px 12px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .85rem; }

.menu { display: none; }
.burger { display: none; place-content: center; gap: 5px; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 10px; background: none; cursor: pointer; }
.burger span { display: block; width: 22px; height: 2px; border-radius: 2px; background: var(--ink); transition: transform .2s, opacity .2s; }

.content { flex: 1; min-width: 0; padding: 32px; }

/* ---- Cards ------------------------------------------------------ */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
    background: var(--surface);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow);
    text-decoration: none;
    display: block;
}
a.card:hover { transform: translateY(-1px); }
.card--blue { border-top: 5px solid var(--blue); }
.card--green { border-top: 5px solid var(--green); }
.card--purple { border-top: 5px solid var(--purple); }
.card p { margin: 0; }

.pill { font-size: .8rem; padding: 2px 10px; border-radius: 99px; background: var(--bg); color: var(--muted); }

.empty { text-align: center; padding: 48px 20px; }

/* ---- Calendar --------------------------------------------------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.cal-head h2 { margin: 0; }
.cal-head .actions { display: flex; gap: 8px; }
.cal {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.cal-dow { padding: 10px 8px; font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--bg); text-align: center; }
.cal-day { min-height: 92px; padding: 8px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); font-size: .9rem; }
.cal-day:nth-child(7n + 1) { border-left: 0; }
.cal-day.is-other { color: #B9B5C6; background: #FCFBFE; }
.cal-day.is-today .num {
    display: inline-grid;
    place-items: center;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--purple-deep);
    color: #fff;
    font-weight: 600;
}

.cal-day .num { display: inline-block; margin-bottom: 2px; }
.cal-ev {
    display: block;
    margin-top: 3px;
    padding: 2px 6px;
    border-left: 3px solid var(--ev);
    border-radius: 6px;
    background: color-mix(in srgb, var(--ev) 18%, #fff);
    font-size: .78rem;
    line-height: 1.35;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-ev:hover { background: color-mix(in srgb, var(--ev) 30%, #fff); }
.cal-ev .t { font-weight: 600; margin-right: 2px; }
.cal-day.is-other .cal-ev { opacity: .6; }

.cal-agenda { display: none; }
.cal-agenda h3 { margin: 18px 0 4px; font-size: 1rem; }
.cal-agenda .cal-ev { font-size: .92rem; padding: 6px 10px; }

.connect { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.btn--google { display: inline-flex; align-items: center; gap: 10px; background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(46, 42, 59, .08); }
.btn--google:hover { background: var(--bg); }

/* ---- Lists ------------------------------------------------------ */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.list-new { display: flex; gap: 10px; margin-bottom: 20px; }
.list-new input { flex: 1; }
.lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.list { border-top: 5px solid var(--green); scroll-margin-top: 80px; }
.list-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.list-head h2 { margin: 0; overflow-wrap: anywhere; }
.list-head form { margin-left: auto; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.icon-btn:hover { background: var(--bg); color: var(--danger); }
.icon-btn--small { width: 28px; height: 28px; }
.items { list-style: none; margin: 0 0 12px; padding: 0; }
.item { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.item form { margin: 0; }
.item-toggle { flex: 1; min-width: 0; }
.item-toggle label { display: flex; align-items: center; gap: 10px; margin: 0; padding: 8px 0; font-weight: 400; cursor: pointer; }
.item-toggle input { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--green-deep); }
.item-toggle span { overflow-wrap: anywhere; }
.item.is-done span { color: var(--muted); text-decoration: line-through; }
.item-add { display: flex; gap: 8px; }
.item-add input { flex: 1; min-width: 0; padding: 8px 11px; }

/* ---- Dashboard: next 7 days ------------------------------------- */
.week-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.week-head h2 { margin: 0; }
.week-head a { margin-left: auto; font-size: .92rem; }
.week-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.week-day { min-width: 0; padding: 10px; border-radius: 10px; background: var(--bg); }
.week-day.is-today { background: var(--purple); }
.week-day h3 { margin: 0 0 6px; font-size: .95rem; }
.week-day h3 .muted { font-family: 'Inter', system-ui, sans-serif; font-weight: 400; font-size: .82rem; }
.week-day .cal-ev { white-space: normal; }
.week-empty { margin: 0; font-size: .85rem; }
/* Events with an icon (calendar, agenda, dashboard) start with a full-height tile
   in the darker calendar colour, icon in white. */
.cal-ev:has(.cal-icon) { display: flex; align-items: center; gap: 8px; padding: 0 6px 0 0; border-left: 0; overflow: hidden; }
.cal-ev .cal-icon { align-self: stretch; width: 28px; height: auto; min-height: 26px; margin: 0; top: 0; border-radius: 6px 0 0 6px; font-size: .8rem; }
.cal-ev .cal-icon svg { width: 15px; height: 15px; }
.cal-ev .cal-icon--plain { --icon-cut: color-mix(in srgb, var(--ev) 60%, #000); background: color-mix(in srgb, var(--ev) 60%, #000); color: #fff; }
.ev-text { min-width: 0; padding: 4px 0; }
/* Smaller tile in the month grid, where titles stay on one line. */
.cal-day .cal-ev:has(.cal-icon) { gap: 5px; }
.cal-day .cal-ev .cal-icon { width: 20px; min-height: 20px; font-size: .68rem; }
.cal-day .cal-ev .cal-icon svg { width: 12px; height: 12px; }
.cal-day .ev-text { padding: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1000px) {
    .week-days { grid-template-columns: 1fr; }
    .week-day h3 { display: flex; justify-content: space-between; }
}

.cal-panel { margin-bottom: 24px; }
.cal-panel-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 14px; }
.cal-panel-head h2 { margin: 0; }
.cal-panel.is-hidden .cal-panel-body { display: none; }
.cal-panel.is-hidden .cal-panel-head { margin-bottom: 0; }
.cal-sync { margin-left: auto; font-size: .92rem; color: var(--muted); text-decoration: none; }
.cal-sync-hover { display: none; color: var(--ink); text-decoration: underline; }
.cal-sync:hover .cal-sync-idle, .cal-sync:focus-visible .cal-sync-idle { display: none; }
.cal-sync:hover .cal-sync-hover, .cal-sync:focus-visible .cal-sync-hover { display: inline; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 6px 14px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: var(--bg);
    cursor: pointer;
}
.chip:has(input:not(:checked)) { opacity: .55; }
.chip .dot { background: var(--ev); }
.chip-name { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.chip-name:hover { text-decoration: underline; }

/* Calendar icon badge: darker shade of the calendar colour (set --ev on a parent). */
.cal-icon { display: inline-grid; place-items: center; flex-shrink: 0; width: 16px; height: 16px; margin-right: 4px; border-radius: 4px; background: color-mix(in srgb, var(--ev) 60%, #000); color: #fff; font: 700 .68rem/1 'Inter', system-ui, sans-serif; vertical-align: middle; position: relative; top: -1px; }
.cal-icon svg { width: 12px; height: 12px; }
.cal-icon--plain { background: none; color: color-mix(in srgb, var(--ev) 60%, #000); }
.cal-icon--plain svg { width: 16px; height: 16px; }
.chip-name .cal-icon, .icon-choice .cal-icon { margin-right: 0; top: 0; }

.label { display: block; font-weight: 500; font-size: .92rem; margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; margin: 0; padding: 0; border: 2px solid #fff; border-radius: 50%; background: var(--sw); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.is-selected { box-shadow: 0 0 0 2px var(--ink); }
.swatch:disabled { cursor: not-allowed; opacity: .5; }
.swatch--custom { position: relative; overflow: hidden; background: conic-gradient(#f83a22, #ffad46, #fbe983, #16a765, #4986e7, #a47ae2, #f83a22); }
.swatch--custom input { position: absolute; inset: -6px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }
.icon-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-choice { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; font-weight: 400; cursor: pointer; }
.icon-choice:has(input:checked) { border-color: var(--ink); background: var(--bg); }
.icon-choice .cal-icon { margin: 0; }
.chip input, .cal-group-head input { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
.chip .dot, .group-row .dot { border-radius: 4px; }

.cal-group { margin-bottom: 10px; }
.cal-group-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.cal-group-name { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 600; cursor: pointer; }
.cal-collapse { margin-left: auto; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--ink); font: inherit; font-size: 1.25rem; line-height: 1.4; cursor: pointer; }
.cal-collapse:hover { background: var(--line); }
.cal-group-body { padding: 10px 0 0 20px; }
.cal-group-body .cal-group-head { background: transparent; border-style: dashed; }
.cal-group.is-collapsed > .cal-group-body { display: none; }

/* ---- Popup (dialog) --------------------------------------------- */
.modal {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 24px;
    border: 0;
    border-radius: 14px;
    color: var(--ink);
    box-shadow: 0 20px 50px rgba(46, 42, 59, .25);
}
.modal::backdrop { background: rgba(46, 42, 59, .4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.modal-close { width: 36px; height: 36px; border: 0; border-radius: 10px; background: none; color: var(--ink); font-size: 1.6rem; line-height: 1; cursor: pointer; }
.modal-close:hover { background: var(--bg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---- Event popup ------------------------------------------------ */
.ev-cal { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; color: var(--muted); }
.ev-cal .dot { border-radius: 4px; background: var(--ev); }
.ev-details { display: grid; gap: 12px; margin: 0; }
.ev-details dt { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ev-details dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.ev-notes { white-space: pre-wrap; max-height: 40vh; overflow-y: auto; }
.ev-small { margin: 14px 0 0; font-size: .85rem; }
.ev-form .check { margin-bottom: 14px; }
.cal-day[data-date], .week-day[data-date] { cursor: pointer; }
.cal-day[data-date]:hover { background: #FBFAFE; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
textarea { resize: vertical; }
[hidden] { display: none !important; }
.group-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) minmax(0, 1.4fr); align-items: center; gap: 10px; margin-bottom: 8px; }
.group-row label { margin: 0; }
.group-row input { padding: 8px 11px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ev); flex-shrink: 0; }

/* ---- Alerts and pills ------------------------------------------- */
.alert--ok { background: var(--green); color: var(--ink); }
.pill--on { background: var(--green); color: var(--ink); }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn--ghost:hover { background: var(--bg); }

/* ---- Login (2FA step) ------------------------------------------- */
.login-card > .muted { margin: 0 0 16px; }
.login-alt { text-align: center; margin: 16px 0 0; font-size: .92rem; }

/* ---- Settings --------------------------------------------------- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tab {
    padding: 8px 16px;
    border-radius: 99px;
    background: var(--surface);
    border: 1px solid var(--line);
    font-weight: 500;
    font-size: .92rem;
    text-decoration: none;
}
.tab:hover { background: var(--bg); }
.tab.is-active { background: var(--purple); border-color: var(--purple); }

.settings-card { max-width: 560px; }
.settings-card > p { margin: 0 0 16px; }
.settings-card .btn { margin-top: 4px; }
.hint { display: block; font-size: .82rem; margin-top: 4px; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 10px; }
.qr { width: 180px; margin: 12px 0; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: block; margin-top: 4px; font-size: .95rem; letter-spacing: .05em; word-break: break-all; }

/* ---- Mobile ----------------------------------------------------- */
@media (max-width: 760px) {
    /* Burger with a full-screen menu instead of the top links and profile menu. */
    .topbar { justify-content: space-between; gap: 12px; padding: 8px 8px 8px 16px; }
    .topnav, .profile { display: none; }
    .topbar .logo, .burger { position: relative; z-index: 2; }
    .burger { display: inline-grid; }
    html.menu-open { overflow: hidden; }
    html.menu-open .menu {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1;
        padding: 84px 20px 32px;
        background: var(--surface);
        overflow-y: auto;
    }
    .menu nav { display: flex; flex-direction: column; gap: 8px; }
    .menu .nav-link { padding: 12px 16px; font-family: 'Fredoka', 'Inter', system-ui, sans-serif; font-size: 1.6rem; font-weight: 500; }
    html.menu-open .burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    html.menu-open .burger span:nth-child(2) { opacity: 0; }
    html.menu-open .burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    .content { padding: 20px 16px; }
    .cal-day { min-height: 56px; padding: 4px; font-size: .8rem; }
    .cal-dow { font-size: .7rem; padding: 8px 2px; }
    /* Grid shows coloured bars only; titles are in the agenda below. */
    .cal-day .cal-ev { height: 5px; padding: 0; border: 0; background: var(--ev); font-size: 0; }
    .cal-day .cal-ev .cal-icon { display: none; }
    .cal-agenda { display: block; }
    .cal-group-body { padding-left: 10px; }
    .group-row { grid-template-columns: 12px minmax(0, 1fr); }
    .group-row input { grid-column: 1 / -1; }
}
