:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #64748b;
    --border: #dde2e8;
    --accent: #2563eb;
    --accent-ink: #ffffff;
    --ok: #15803d;
    --warn: #b45309;
    --alert: #b91c1c;
    --radius: 8px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.mono { word-break: break-all; }

/* Layout */
.wrap { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 3rem; }
.topbar {
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    padding: .5rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a, .topbar nav .link { padding: .35rem .6rem; border-radius: 6px; color: var(--text); text-decoration: none; }
.topbar nav a.active { background: #e8eefc; color: var(--accent); }
.topbar nav a:hover { background: #f0f2f5; }
.nav-sep { flex: 1; }
.nav-toggle { display: none; }
@media (max-width: 800px) {
    .nav-toggle { display: inline-block; margin-left: auto; }
    .topbar nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; }
    .nav-open .topbar nav { display: flex; }
    .nav-sep { display: none; }
}

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.month-nav { display: flex; gap: .4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.highlight { border-color: var(--warn); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 1rem; }
.stack { display: flex; flex-direction: column; gap: .7rem; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .7rem; }
.narrow { max-width: 560px; }
.steps { list-style: none; padding: 0; margin: 0; }
.inline { display: inline; }

/* Forms */
label { display: flex; flex-direction: column; gap: .2rem; font-weight: 500; }
label:has(> input[type=checkbox]) { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; }
input, select, textarea {
    font: inherit; color: inherit; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; max-width: 100%;
}
input[type=checkbox] { width: 1.05rem; height: 1.05rem; }
input[type=color] { padding: 0; width: 2.5rem; height: 2.2rem; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 500; margin-bottom: .2rem; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.field-error { color: var(--alert); font-size: .85rem; font-weight: 400; }
.multi { min-width: 14rem; }
.w-sm { width: 5rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.filters input[type=search] { flex: 1; min-width: 12rem; }
.slot-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.slot-row label { flex-direction: row; align-items: center; gap: .3rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
    font: inherit; font-weight: 500; padding: .45rem .9rem; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--alert); border-color: #f1c4c4; }
.btn.warn { color: var(--warn); border-color: #f3d9b1; }
.btn.small { padding: .25rem .6rem; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .4rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
button.link.danger { color: var(--alert); }

/* Messages and tags */
.flash { padding: .6rem .8rem; border-radius: 6px; margin-bottom: .75rem; border: 1px solid; }
.flash-success, .flash-info { background: #ecfdf3; border-color: #b7e4c7; color: #14532d; }
.flash-warning { background: #fffbeb; border-color: #f5d68a; color: #78350f; }
.flash-error { background: #fef2f2; border-color: #f5b5b5; color: #7f1d1d; }
.tag { display: inline-block; padding: .05rem .45rem; border-radius: 999px; background: #eef1f5; font-size: .8rem; font-weight: 500; }
.tag.red { background: #fde8e8; color: var(--alert); }
.tag.st-proposed { background: #fff4db; color: var(--warn); }
.tag.st-confirmed { background: #e3f6ea; color: var(--ok); }
.tag.st-cancelled { background: #fde8e8; color: var(--alert); }
.tag.st-no_show { background: #ffedd5; color: #c2410c; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.text-alert { color: var(--alert); }
.chip {
    display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; margin: .1rem .2rem .1rem 0;
    border-radius: 999px; font-size: .85rem; background: color-mix(in srgb, var(--loc, #94a3b8) 18%, white);
    border-left: 4px solid var(--loc, #94a3b8);
}

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; color: var(--text); text-decoration: none; font-size: .9rem; }
.tile .n { display: block; font-size: 1.6rem; font-weight: 700; }
.tile.warn .n { color: var(--warn); }
.tile.alert { border-color: #f5b5b5; }
.tile.alert .n { color: var(--alert); }

/* Tables and lists */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.list th, .list td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.list thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr.inactive, .slot-row.inactive { opacity: .55; }
tr.row-error td { background: #fef2f2; }
.grid-table th, .grid-table td { padding: .3rem; border: 1px solid var(--border); text-align: center; }
.grid-table input { width: 4.5rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .2rem 0; }
ul.cols { columns: 2 220px; }
li.st-proposed strong { color: var(--warn); }
li.st-cancelled { text-decoration: line-through; color: var(--alert); }
li.st-no_show { color: #c2410c; }
.done-check { display: inline-flex; align-items: center; justify-content: center; width: 1.1rem; height: 1.1rem; margin-right: .35rem; border-radius: 4px; background: #16a34a; color: #fff; font-size: .8rem; font-weight: 700; vertical-align: -.15rem; }
.codes { columns: 2; font-size: 1.1rem; }

/* Auth pages */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 420px; }
.brand-lg { font-size: 1.25rem; }
.qr { width: 220px; max-width: 100%; margin: .5rem auto; }
.qr svg { width: 100%; height: auto; display: block; }
.secret { font-size: 1.05rem; letter-spacing: .05em; }

/* Calendar */
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.legend-proposed { border-left: 4px dashed var(--warn); background: #fde68a; color: #78350f; }
.legend-cancelled { border-left: 4px solid #dc2626; background: #fecaca; color: #7f1d1d; text-decoration: line-through; }
.legend-no_show { border-left: 4px solid #ea580c; background: #fdba74; color: #7c2d12; }
.status-filter { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .8rem; }
.legend-standing { border-left: 4px solid #334155; background: #eef1f5; }
#calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; }
/* Awaiting confirmation: amber fill whatever the location; the location colour stays as a left stripe. */
.fc .fc-event.st-proposed {
    background: #fde68a !important; border: 2px dashed #b45309 !important; border-left: 5px solid var(--loc, #b45309) !important;
}
.fc .fc-event.st-proposed .fc-event-main { color: #78350f; }
.fc .fc-daygrid-event.st-proposed .fc-daygrid-event-dot { border-color: #d97706; }
.fc .fc-event.st-cancelled { background: #fecaca !important; border: 2px solid #dc2626 !important; border-left: 5px solid var(--loc, #dc2626) !important; text-decoration: line-through; }
.fc .fc-event.st-cancelled .fc-event-main { color: #7f1d1d; }
.fc .fc-event.st-no_show { background: #fdba74 !important; border: 2px solid #ea580c !important; border-left: 5px solid var(--loc, #ea580c) !important; }
.fc .fc-event.st-no_show .fc-event-main { color: #7c2d12; }
.fc .fc-daygrid-event.st-cancelled .fc-daygrid-event-dot { border-color: #dc2626; }
.fc .fc-daygrid-event.st-no_show .fc-daygrid-event-dot { border-color: #ea580c; }
.fc .fc-event.st-completed { opacity: .7; }
.fc .fc-event.standing .fc-event-title::before { content: "↻ "; }
.fc .open-hours { opacity: .5; }
.fc .time-off { background: repeating-linear-gradient(45deg, #fde8e8 0 8px, #fff 8px 16px) !important; opacity: .8; }
.fc .fc-toolbar-title { font-size: 1.15rem; }
@media (max-width: 700px) { .fc .fc-toolbar { flex-direction: column; gap: .4rem; } }

dialog.panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog.small-panel { width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 42, .4); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.panel-head h2 { margin: 0; }
.panel-head .link { font-size: 1.5rem; line-height: 1; color: var(--muted); }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: .7rem 1rem; border-radius: 8px; background: #1f2933; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 1000; }
.toast-error { background: var(--alert); }
.toast-warn { background: var(--warn); }

/* Day sheet */
.sheet th, .sheet td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.sheet tr.cancelled { text-decoration: line-through; color: var(--muted); }

@media (max-width: 520px) {
    .row2 { grid-template-columns: 1fr; }
}
