:root {
    --bg: #0f1115;
    --bg-soft: #151924;
    --card: #1a1f2b;
    --card-hover: #212736;
    --border: #2a3040;
    --text: #e8ebf2;
    --text-dim: #8b93a7;
    --blue: #3aa3c9;
    --blue-soft: rgba(58, 163, 201, .16);
    --orange: #cf8f2e;
    --orange-soft: rgba(207, 143, 46, .16);
    --red: #d05656;
    --purple: #8b7dd8;
    --radius: 14px;
    font-size: 16px;
}

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

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    background: rgba(15, 17, 21, .88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: .06em;
}
.brand span { color: var(--blue); }

.tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    margin-left: auto;
}

.tab {
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 999px;
    cursor: pointer;
}
.tab.active { background: var(--card-hover); color: var(--text); }

.logout {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 1.1rem;
    padding: 4px 6px;
}
.logout:hover { color: var(--red); }

/* ---------- main ---------- */

main {
    max-width: 860px;
    margin: 0 auto;
    padding: 16px 14px 110px;
    /* always slightly scrollable so the mobile browser toolbar (and with it
       the FAB) behaves identically in list and calendar view */
    min-height: calc(100vh + 2px);
}
@supports (height: 100lvh) {
    main { min-height: calc(100lvh + 2px); }
}

.month-head {
    font-size: .82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--text-dim);
    margin: 26px 4px 10px;
}
.month-head:first-child { margin-top: 6px; }

/* ---------- cards (list view) ---------- */

.card {
    display: flex;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: background .12s ease;
}
.card:hover { background: var(--card-hover); }

.card-bar { width: 5px; flex: none; }
.card.status-confirmed .card-bar { background: var(--blue); }
.card.status-pending   .card-bar { background: var(--orange); }

.card-body { padding: 12px 14px; min-width: 0; flex: 1; }

.card-title { font-weight: 650; font-size: 1rem; line-height: 1.3; }

.card-meta {
    color: var(--text-dim);
    font-size: .85rem;
    margin-top: 3px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip {
    font-size: .72rem;
    font-weight: 650;
    padding: 3px 9px;
    border-radius: 999px;
    letter-spacing: .02em;
}
.chip-confirmed { background: var(--blue-soft);   color: var(--blue); }
.chip-pending   { background: var(--orange-soft); color: var(--orange); }
.chip-personal  { background: rgba(139, 125, 216, .16); color: var(--purple); }
.chip-clash     { background: rgba(208, 86, 86, .14);   color: var(--red); }
.chip-archived  { background: rgba(139, 147, 167, .16); color: var(--text-dim); }
.chip-today     { background: rgba(76, 175, 125, .18);  color: #4caf7d; }

.archive-section .card { opacity: .55; }
.archive-section .card-bar { background: var(--text-dim) !important; }

.past-toggle {
    display: block;
    margin: 24px auto 0;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font: inherit;
    font-size: .85rem;
    padding: 8px 18px;
    border-radius: 999px;
    cursor: pointer;
}
.past-toggle:hover { color: var(--text); }

.past-section { opacity: .55; }

.empty {
    text-align: center;
    color: var(--text-dim);
    padding: 60px 20px;
    font-size: .95rem;
}

/* ---------- calendar ---------- */

.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 2px 14px;
}

.cal-title { font-size: 1.15rem; font-weight: 700; text-transform: capitalize; }

.cal-btns { display: flex; gap: 6px; }

.icon-btn {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    color: var(--text);
    font: inherit;
    font-size: .9rem;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: var(--card-hover); }
.icon-btn.wide { width: auto; padding: 0 12px; font-size: .82rem; font-weight: 600; }

.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 6px;
}

.week {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: min-content;
    border-top: 1px solid var(--border);
    padding: 4px 0 10px;
    min-height: 74px;
    user-select: none;
    -webkit-user-select: none;
}

.today-col {
    grid-row: 1 / -1;
    background: var(--blue-soft);
    border-top: 2px solid var(--blue);
    border-radius: 0 0 8px 8px;
    pointer-events: none;
    z-index: 0;
}

.sel-col {
    grid-row: 1 / -1;
    background: rgba(58, 163, 201, .18);
    border: 1.5px dashed var(--blue);
    border-radius: 8px;
    pointer-events: none;
    z-index: 0;
}

.dayno.pastday { opacity: .35; }

.dayno {
    grid-row: 1;
    text-align: center;
    font-size: .78rem;
    color: var(--text-dim);
    padding: 4px 0 6px;
    cursor: pointer;
    position: relative;
}
.dayno.other { opacity: .28; }
.dayno.today .num {
    background: var(--blue);
    color: #fff;
    border-radius: 999px;
    padding: 2px 7px;
    font-weight: 700;
}
.dayno .dot {
    position: absolute;
    top: 1px;
    right: calc(50% - 14px);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
}

.bar {
    position: relative;
    z-index: 1;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1;
    padding: 5px 7px;
    margin: 2px 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    color: #fff;
}
.bar.status-confirmed { background: var(--blue); }
.bar.status-pending   { background: var(--orange); }
.bar.cat-personal     { background: var(--purple); }
.bar.cat-personal.status-pending { background: var(--purple); opacity: .65; }
.bar.rs { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.bar.re { border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.bar:not(.rs) { margin-left: 0; padding-left: 4px; }
.bar:not(.re) { margin-right: 0; }

.bar.pastg { opacity: .4; }
.bar.dragging { opacity: .85; outline: 1.5px dashed rgba(255, 255, 255, .8); }

.bar-loc { font-weight: 400; opacity: .8; margin-left: 5px; display: none; }
.bar-time { font-weight: 400; opacity: .85; margin-right: 4px; }

.rz {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 11px;
    cursor: ew-resize;
    opacity: 0;
}
.rz-l { left: 0; border-radius: 6px 0 0 6px; }
.rz-r { right: 0; border-radius: 0 6px 6px 0; }

@media (hover: hover) {
    .bar { cursor: grab; }
    .bar:active { cursor: grabbing; }
    .bar:hover .rz { opacity: 1; background: rgba(255, 255, 255, .3); }
    .dayno { cursor: cell; }
}

/* ---------- desktop: larger, more detailed calendar ---------- */

@media (min-width: 900px) {
    body.view-cal main { max-width: 1280px; }
    body.view-cal .week { min-height: 132px; padding-bottom: 14px; }
    body.view-cal .dayno { font-size: .88rem; padding: 6px 0 8px; }
    body.view-cal .bar { font-size: .82rem; padding: 7px 9px; margin-top: 3px; }
    body.view-cal .bar-loc { display: inline; }
    body.view-cal .cal-title { font-size: 1.4rem; }
    body.view-cal .cal-weekdays { font-size: .75rem; }
}

/* ---------- pull to refresh ---------- */

#ptr {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 62px);
    left: 50%;
    transform: translate(-50%, -20px);
    background: var(--card-hover);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: .82rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 999px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
    z-index: 25;
}
#ptr.show  { opacity: 1; transform: translate(-50%, 0); }
#ptr.ready { color: var(--blue); border-color: var(--blue); }

.spin {
    display: inline-block;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- FAB ---------- */

#fab {
    position: fixed;
    right: 20px;
    bottom: calc(24px + env(safe-area-inset-bottom) + var(--vvoff, 0px));
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 0;
    background: var(--blue);
    color: #fff;
    font-size: 1.9rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(58, 163, 201, .45);
    z-index: 30;
}
#fab:active { transform: scale(.94); }

/* ---------- sheet / modal ---------- */

.overlay[hidden] { display: none; }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    /* keep the sheet's top edge clear of the notch/status bar */
    padding-top: calc(env(safe-area-inset-top) + 16px);
}

.sheet {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 560px;
    max-height: 100%;
    overflow-y: auto;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
    animation: slideup .18s ease;
}

@keyframes slideup {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
    .overlay { align-items: center; }
    .sheet { border-radius: 20px; }
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.sheet-title { font-size: 1.1rem; font-weight: 700; }

.lbl {
    display: block;
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-dim);
    margin: 11px 2px 5px;
}

.seg-row { margin-top: 14px; }

.field {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    /* 16px minimum — anything smaller makes iOS auto-zoom on focus and stay zoomed */
    font-size: 1rem;
    padding: 11px 12px;
    outline: none;
}
.field:focus { border-color: var(--blue); }
textarea.field { resize: vertical; }

input[type="date"].field,
input[type="time"].field {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    min-width: 0;      /* iOS date/time inputs have an intrinsic width that overflows grids */
    max-width: 100%;
}
input[type="date"].field::-webkit-calendar-picker-indicator,
input[type="time"].field::-webkit-calendar-picker-indicator { filter: invert(.7); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > div, .row2 > .seg { min-width: 0; }

.seg {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.seg-btn {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
    padding: 10px;
    cursor: pointer;
}
.seg-btn.active { color: var(--text); border-color: var(--text-dim); background: var(--card-hover); }
.seg-btn.seg-confirmed.active { border-color: var(--blue);   color: var(--blue);   background: var(--blue-soft); }
.seg-btn.seg-pending.active   { border-color: var(--orange); color: var(--orange); background: var(--orange-soft); }

.tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-chip {
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--text-dim);
    font: inherit;
    font-size: .82rem;
    font-weight: 650;
    padding: 6px 13px;
    border-radius: 999px;
    cursor: pointer;
}
.tag-chip .x { margin-left: 6px; opacity: .7; }

.tag-chip.new-tag { border-style: dashed; }

.tag-create {
    margin-top: 10px;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}
.swatch.active { border-color: #fff; transform: scale(1.12); }

.tag-create-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.tag-create-actions .btn { padding: 9px 14px; font-size: .85rem; flex: 1; }

.tagdot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
    box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .35);
}

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 16px;
    cursor: pointer;
}
.check-row input {
    width: 20px;
    height: 20px;
    margin-top: 1px;
    accent-color: var(--blue);
    flex: none;
    cursor: pointer;
}
.check-text { font-size: .92rem; font-weight: 600; }
.check-text small {
    display: block;
    font-size: .78rem;
    font-weight: 400;
    color: var(--text-dim);
    margin-top: 2px;
}

.sheet-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn {
    border: 0;
    border-radius: 12px;
    font: inherit;
    font-size: .95rem;
    font-weight: 700;
    padding: 13px 18px;
    cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; flex: 1; }
.btn-primary:active { transform: scale(.98); }
.btn-danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn-neutral { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-neutral:hover { color: var(--text); }
.btn-block { width: 100%; margin-top: 18px; }

/* ---------- login ---------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 34px 28px;
}

.login-logo {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-align: center;
}
.login-logo span { color: var(--blue); }

.login-sub {
    text-align: center;
    color: var(--text-dim);
    font-size: .9rem;
    margin: 4px 0 22px;
}

.login-card .field { margin-bottom: 12px; }

.login-error {
    background: rgba(208, 86, 86, .14);
    color: var(--red);
    font-size: .85rem;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 14px;
    text-align: center;
}
