* { box-sizing: border-box; }
body { margin: 0; font-family: var(--brand-font); background: var(--brand-bg); color: var(--brand-text); line-height: 1.45; }
a { color: var(--brand-accent); }
.muted { color: var(--brand-muted); }
.small { font-size: .85rem; }
.pad { padding: 1rem 1.25rem; }
.hidden { display: none !important; }

#top { background: var(--brand-primary); color: var(--brand-primary-text); display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; }
#top .brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; font-size: 1.05rem; text-decoration: none; color: inherit; }
#top .brand img { height: 28px; }
#top nav { display: flex; gap: .25rem; }
#top nav a { color: inherit; text-decoration: none; padding: .3rem .7rem; border-radius: 6px; opacity: .85; }
#top nav a.active, #top nav a:hover { background: rgba(255,255,255,.15); opacity: 1; }
#top .spacer { flex: 1; }
#top .who { font-size: .85rem; opacity: .9; }
#top button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.5); }

main { max-width: 1500px; margin: 0 auto; padding: 1.25rem; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.card { background: var(--brand-surface); border: 1px solid var(--brand-border); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.landing { max-width: 520px; margin: 4rem auto; text-align: center; }
.landing .card { text-align: left; }

button, .btn { font: inherit; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--brand-border); background: var(--brand-surface); color: var(--brand-text); cursor: pointer; }
button.primary { background: var(--brand-primary); color: var(--brand-primary-text); border-color: var(--brand-primary); }
button.danger { color: var(--brand-danger); border-color: var(--brand-danger); }
button.link { border: 0; background: none; color: var(--brand-accent); padding: 0; text-decoration: underline; text-align: left; }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: .4rem .55rem; border: 1px solid var(--brand-border); border-radius: 6px; background: #fff; max-width: 100%; }
textarea { width: 100%; }
label { display: block; font-size: .85rem; color: var(--brand-muted); margin-bottom: .2rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.row > div { min-width: 0; }
.row.spread { justify-content: space-between; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; align-items: center; }
.field { margin-bottom: .75rem; }
.field input:not([type=checkbox]):not([type=radio]), .field select { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--brand-surface); border: 1px solid var(--brand-border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--brand-border); vertical-align: top; font-size: .9rem; }
th { background: #eef0f4; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--brand-muted); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; border-radius: 8px; }
tr.group td { background: #f8f9fb; font-weight: 600; color: var(--brand-muted); }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--brand-border); margin: 1rem 0; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--brand-muted); border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--brand-text); border-bottom-color: var(--brand-primary); font-weight: 600; }

.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--brand-border); background: #eef0f4; white-space: nowrap; }
.pill.ok { background: #e3f4ea; color: var(--brand-ok); border-color: #b7e0c8; }
.pill.warn { background: #fdf3dc; color: #8a5a00; border-color: #ecd49a; }
.pill.bad { background: #fde8e6; color: var(--brand-danger); border-color: #f4b8b2; }
.pill.info { background: #e8eef8; color: var(--brand-primary); border-color: #c3d1e8; }

.error { color: var(--brand-danger); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--brand-muted); }

#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--brand-text); color: #fff; padding: .6rem .9rem; border-radius: 6px; max-width: 420px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.error { background: var(--brand-danger); }

/* Phase bar */
.phases { display: flex; gap: 2px; margin: .75rem 0 0; flex-wrap: wrap; }
.phases span { flex: 1; min-width: 6rem; text-align: center; padding: .35rem .25rem; font-size: .8rem; background: #e6e9ef; color: var(--brand-muted); }
.phases span:first-child { border-radius: 6px 0 0 6px; }
.phases span:last-child { border-radius: 0 6px 6px 0; }
.phases span.done { background: #c9d6e8; color: var(--brand-primary); }
.phases span.current { background: var(--brand-primary); color: var(--brand-primary-text); font-weight: 600; }
.progress { font-size: .8rem; color: var(--brand-muted); white-space: nowrap; }

/* Participant grid */
.grid th.m, .grid td.m { text-align: center; white-space: nowrap; font-size: .8rem; padding: .45rem .35rem; }
.grid th.m { text-transform: none; letter-spacing: 0; font-size: .74rem; min-width: 4.2rem; }
.grid th.m.gate { color: var(--brand-primary); }
.grid tr.funnel td { background: #f8f9fb; font-size: .78rem; color: var(--brand-muted); font-weight: 600; }
.grid td.m.has { color: var(--brand-ok); font-weight: 600; }
.grid tr.out td { color: var(--brand-muted); }
.grid tr.out td.firm button { color: var(--brand-muted); }
.grid tr.selected td { background: #fbf6ea; }
.grid td.firm { white-space: nowrap; }
.grid .sticky { position: sticky; left: 0; background: inherit; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.toolbar .count { font-size: .85rem; color: var(--brand-muted); margin-right: .5rem; }
.toolbar input[type=search] { min-width: 14rem; }
.toolbar .spacer, .grow { flex: 1; }
.grow input { width: 100%; }

/* Modal */
/* The dialog scrolls inside itself, so its scroll bar is part of the dialog (clicking it never closes the dialog). */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; z-index: 40; overflow: hidden; }
.modal { background: var(--brand-surface); border-radius: 10px; width: 100%; max-width: 640px; max-height: calc(100vh - 4rem); overflow-y: auto; padding: 1.25rem 1.5rem; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal h2 { margin-top: 0; }
.modal .foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.note { background: #f8f9fb; border-left: 3px solid var(--brand-accent); padding: .5rem .75rem; font-size: .88rem; margin: .5rem 0; white-space: pre-wrap; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: .35rem 0; border-bottom: 1px solid var(--brand-border); }
.list-plain li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; font-size: .9rem; }
.kv dt { color: var(--brand-muted); }
.kv dd { margin: 0; }
.blocked { background: #fde8e6; border: 1px solid #f4b8b2; color: var(--brand-danger); border-radius: 6px; padding: .5rem .75rem; font-size: .88rem; margin: .5rem 0; }
