:root {
    --bg: #0b1221;
    --surface: #121a2e;
    --surface-2: #1a2340;
    --border: #273152;
    --text: #e6ecff;
    --text-dim: #96a3c6;
    --accent: #ff9900;
    --accent-dim: #c87400;
    --ok: #22c55e;
    --warn: #f59e0b;
    --err: #ef4444;
    --info: #3b82f6;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
}
body.modal-open { overflow: hidden; }

/* ---- App bar (top bar + tabs stick together) ---- */
.appbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    padding-top: env(safe-area-inset-top);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-weight: 700;
    font-size: 16px;
}
.brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 28px; height: 28px;
    border-radius: 6px;
    background: var(--accent);
    color: #0b1221;
    font-weight: 800;
    font-size: 12px;
}

.edition-picker {
    display: flex;
    align-items: center;
    flex: none;
    gap: 8px;
    color: var(--text-dim);
}
.edition-picker label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.edition-picker select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-family: inherit;
    font-size: 14px;
}
.icon-btn {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.icon-btn:hover { background: var(--border); }

/* ---- Tabs ---- */
.tabs {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 16px;
    gap: 2px;
    padding: 10px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    background: transparent;
    color: var(--text-dim);
    border: none;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* ---- Main view ---- */
main {
    padding: 20px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    max-width: 1400px;
    margin: 0 auto;
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.view-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}
.view-header .sub {
    color: var(--text-dim);
    font-size: 13px;
}

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="url"],
input[type="search"], textarea, select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    min-width: 0;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
}
textarea { resize: vertical; min-height: 72px; }
label.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
label.field input, label.field select, label.field textarea {
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);
    font-size: 14px;
}
label.field.check {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    text-transform: none;
    letter-spacing: normal;
    font-size: 14px;
    color: var(--text);
}
label.field.check input[type="checkbox"] {
    width: 20px; height: 20px;
    margin: 0;
    flex: none;
    accent-color: var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--border); }
.btn.primary {
    background: var(--accent);
    color: #0b1221;
    border-color: var(--accent);
    font-weight: 600;
}
.btn.primary:hover { background: var(--accent-dim); color: #fff; }
.btn.ghost {
    background: transparent;
    color: var(--text-dim);
}
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 8px; font-size: 12px; }

/* ---- Cards grid (dashboard) ---- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.card .label {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 8px;
}
.card .value {
    font-size: 26px;
    font-weight: 700;
}
.card .hint {
    color: var(--text-dim);
    margin-top: 6px;
    font-size: 12px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.panel h3 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
}

/* ---- Table ---- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--surface-2);
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    white-space: nowrap;
}
tbody td {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    vertical-align: top;
}
th.num, td.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
.row-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    white-space: nowrap;
}
.empty {
    padding: 32px;
    text-align: center;
    color: var(--text-dim);
}

/* ---- Status chips ---- */
.chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid var(--border);
    color: var(--text-dim);
    background: var(--surface-2);
    white-space: nowrap;
}
.chip.ok     { background: rgba(34,197,94,0.15);  color: #86efac; border-color: rgba(34,197,94,0.3); }
.chip.warn   { background: rgba(245,158,11,0.15); color: #fde68a; border-color: rgba(245,158,11,0.3); }
.chip.err    { background: rgba(239,68,68,0.15);  color: #fca5a5; border-color: rgba(239,68,68,0.3); }
.chip.info   { background: rgba(59,130,246,0.15); color: #93c5fd; border-color: rgba(59,130,246,0.3); }
.chip.muted  { background: var(--surface-2); color: var(--text-dim); }

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    max-width: calc(100% - 32px);
    transform: translateX(-50%) translateY(80px);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 13px;
    box-shadow: var(--shadow);
    z-index: 100;
    opacity: 0;
    transition: all 0.2s ease-out;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.ok { border-color: rgba(34,197,94,0.5); }
.toast.err { border-color: rgba(239,68,68,0.5); }

/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.modal[aria-hidden="false"] { display: flex; }
.modal-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: min(560px, 100%);
    max-height: 90vh;
    max-height: 90dvh;
    box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 16px; flex: none; }
.modal-card form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}
.modal-card form .full { grid-column: 1 / -1; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    flex: none;
}

/* ---- Checklist ---- */
.checklist-group { margin-bottom: 20px; }
.checklist-group h3 {
    margin: 0 0 10px;
    font-size: 14px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.checklist-items {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}
.checklist-item:first-child { border-top: none; }
.checklist-item input[type="checkbox"] {
    width: 18px; height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}
.checklist-item .title { flex: 1; }
.checklist-item.done .title { color: var(--text-dim); text-decoration: line-through; }
.checklist-item .meta {
    color: var(--text-dim);
    font-size: 12px;
    display: flex; gap: 8px; align-items: center;
}
.checklist-item .meta-text { margin-right: auto; }

.checklist-item.overdue .meta { color: var(--err); }

/* ---- Session / team / portal ---- */
.user-box {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--text-dim);
    font-size: 13px;
}
.user-box .user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-box .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    text-decoration: none;
    font-size: 16px;
}
.blocker { max-width: 520px; margin: 40px auto; text-align: center; }
.blocker .btn { display: inline-block; text-decoration: none; }
.card .value.sm { font-size: 16px; font-weight: 600; }
.prewrap { white-space: pre-wrap; }
.hint { color: var(--text-dim); font-size: 12px; }
.role-help { margin: 0; padding-left: 18px; color: var(--text-dim); }
.role-help strong { color: var(--text); }
.portal-dialog { display: flex; flex-direction: column; gap: 12px; }
.portal-dialog p { margin: 0; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }

/* The portal has no tab strip, so its top bar sticks on its own. */
body.portal .topbar { position: sticky; top: 0; z-index: 10; }
body.portal main { max-width: 820px; }
body.portal .panel p { margin: 0 0 12px; }
.portal-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}
.portal-form .full { grid-column: 1 / -1; }
label.field .hint { text-transform: none; letter-spacing: normal; }
.talk-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.session-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 12px; }
.session-list .talk-title { margin-bottom: 2px; }
.search { min-width: 220px; }
.multiselect { display: flex; flex-direction: column; gap: 6px; }
.multiselect-list {
    max-height: 200px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 6px 10px;
}
.multiselect-item {
    display: flex; align-items: center; gap: 8px; padding: 3px 0;
    font-size: 14px; color: var(--text); text-transform: none; letter-spacing: normal;
}
.multiselect-item input { width: auto; }
tr.voided td { color: var(--text-dim); text-decoration: line-through; }
.import-details { max-height: 300px; overflow-y: auto; font-size: 13px; color: var(--text-dim); padding-left: 18px; }
.portal-actions { display: flex; justify-content: flex-end; margin-bottom: 40px; }

.update-button {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
    background: var(--accent);
    color: #0b1221;
    border: none;
    border-radius: var(--radius);
    padding: 10px 16px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 100;
}

/* ---- Responsive ---- */

/* Tables are too wide to scroll sideways on a phone, so each row becomes a card. */
@media (max-width: 720px) {
    .table-wrap {
        background: none;
        border: none;
        border-radius: 0;
        overflow: visible;
    }
    table, tbody, tbody tr, tbody td { display: block; }
    thead { display: none; }

    tbody tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px 14px;
        margin-bottom: 10px;
    }
    tbody tr:hover { background: var(--surface); }
    tbody tr:last-child { margin-bottom: 0; }

    tbody td {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 12px;
        padding: 3px 0;
        border: none;
        text-align: left;
        font-size: 14px;
        /* Emails and URLs are long enough to push a card off-screen. */
        overflow-wrap: anywhere;
    }
    tbody td::before {
        content: attr(data-label);
        flex: 0 0 33%;
        min-width: 0;
        color: var(--text-dim);
        font-size: 11px;
        font-weight: 600;
        text-align: left;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }
    /* First column reads as the card title. */
    tbody td.cell-primary {
        display: block;
        font-size: 16px;
        font-weight: 600;
        padding: 0 0 8px;
    }
    tbody td.cell-primary::before { content: none; }

    tbody td.cell-actions {
        display: flex;
        padding: 12px 0 0;
        margin-top: 8px;
        border-top: 1px solid var(--border);
    }
    tbody td.cell-actions::before { content: none; }
    .row-actions { flex: 1; gap: 8px; }
    .row-actions .btn { flex: 1; max-width: 220px; }

    /* Blank fields add nothing but noise once rows are stacked. */
    tbody td.is-empty { display: none; }

    .empty {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
}

@media (max-width: 640px) {
    .topbar { padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); }
    .brand { font-size: 15px; }
    /* The edition picker and the signed-in account need the width more than the
       wordmark does. The portal has neither, and its wordmark is the event name. */
    body:not(.portal) .brand-text { display: none; }
    main { padding: 14px max(14px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }

    /* The edition select is self-explanatory next to its value; the label just eats width. */
    .edition-picker label {
        position: absolute;
        width: 1px; height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .icon-btn { width: 40px; height: 40px; }

    .tabs {
        padding: 6px max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
        scroll-padding-inline: 10px;
    }
    .tab { padding: 12px; min-height: 44px; }

    .view-header { align-items: flex-start; gap: 12px; }
    .view-header h2 { font-size: 18px; }
    .toolbar { width: 100%; }
    .toolbar > .btn { flex: 1 1 auto; }
    .toolbar > .search { flex: 1 1 100%; min-width: 0; }

    /* Keep stat cards two-up so the dashboard fits on a screen or two. */
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .card { padding: 12px; }
    .card .value { font-size: 22px; }
    .panel { padding: 12px; }

    .btn { min-height: 40px; }
    .btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }

    /* 16px keeps iOS Safari from zooming in when a field takes focus. */
    input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="url"],
    textarea, select, label.field input, label.field select, label.field textarea, .edition-picker select {
        font-size: 16px;
    }

    /* A full-width sheet is easier to reach than a centred dialog. */
    .modal { padding: 0; align-items: flex-end; }
    .modal-card {
        width: 100%;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        border-width: 1px 0 0;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    }
    .modal-card form { grid-template-columns: 1fr; }
    .modal-actions > .btn { flex: 1; }

    .checklist-item { flex-wrap: wrap; padding: 12px 14px; align-items: flex-start; }
    .checklist-item input[type="checkbox"] { width: 22px; height: 22px; margin-top: 1px; }
    .checklist-item .title { flex: 1 1 140px; }
    .checklist-item .meta { width: 100%; padding-left: 32px; justify-content: flex-end; }
    .checklist-item .meta .btn { min-width: 44px; }

    .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
    .update-button { left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); }
}

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