:root {
    --rk-bg: #f5f6f8;
    --rk-surface: #ffffff;
    --rk-border: #d9dde3;
    --rk-brand: #1f3a5f;
    --rk-accent: #2f6feb;
    --rk-text: #1b1f24;
    --rk-muted: #5c6470;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--rk-text);
    background: var(--rk-bg);
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--rk-brand);
    color: #fff;
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
}

.brand-sub {
    font-weight: 400;
    opacity: 0.75;
    margin-left: 0.35rem;
}

.content {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 {
    font-size: 1.5rem;
    margin: 0.5rem 0 0.25rem;
}

.lede {
    color: var(--rk-muted);
    margin-top: 0;
}

.chat {
    background: var(--rk-surface);
    border: 1px solid var(--rk-border);
    border-radius: 10px;
    padding: 1rem;
    margin-top: 1rem;
    /* Bound the panel to the viewport and lay it out as a column so the message
       log scrolls internally instead of growing the page and pushing the input
       off-screen as the conversation gets long. */
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 12rem);
}

.chat-log {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 8rem;
    /* Take the remaining height in the panel and scroll when the conversation
       overflows, keeping the status, confirm bar, and input always visible. */
    flex: 1 1 auto;
    overflow-y: auto;
}

.chat-line {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    max-width: 85%;
    line-height: 1.35;
    /* The read-back preview is multi-line; preserve its formatting. */
    white-space: pre-wrap;
}

.chat-line.typing {
    opacity: 0.85;
}

/* Animated "agent is typing" dots. */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.1rem 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
    animation: rk-typing 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes rk-typing {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 0.9; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .typing-dots span { animation: none; opacity: 0.5; }
}

.chat-status {
    margin-bottom: 0.75rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.eliciting {
    background: #eef2f8;
    color: var(--rk-brand);
}

.badge.awaiting {
    background: #fff4d6;
    color: #8a6100;
}

.badge.confirmed {
    background: #def7e6;
    color: #1c7c43;
}

.chat-line.agent {
    background: #eef2f8;
    align-self: flex-start;
}

.chat-line.user {
    background: var(--rk-accent);
    color: #fff;
    align-self: flex-end;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
}

.text-input {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--rk-border);
    border-radius: 8px;
    font-size: 1rem;
}

/* The message box is a textarea that grows with its content (JS sets the height up to the cap). */
textarea.text-input {
    resize: none;
    overflow-y: hidden;
    min-height: 2.5rem;
    max-height: 160px;
    line-height: 1.35;
    font-family: inherit;
}

.primary {
    padding: 0.55rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--rk-accent);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Event builder (two-pane: conversation + live preview) --- */
.builder {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.builder-chat {
    flex: 1 1 22rem;
    min-width: 18rem;
}

.builder-preview {
    flex: 1 1 18rem;
    min-width: 16rem;
    position: sticky;
    top: 1rem;
}

.confirm-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.event-preview {
    background: var(--rk-surface);
    border: 1px solid var(--rk-border);
    border-radius: 10px;
    padding: 1rem 1.1rem;
}

.event-preview h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
}

.event-preview h3 {
    font-size: 0.95rem;
    margin: 0.9rem 0 0.4rem;
    color: var(--rk-muted);
}

.event-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.2rem 0.75rem;
    margin: 0;
}

.event-meta dt {
    color: var(--rk-muted);
    font-size: 0.85rem;
}

.event-meta dd {
    margin: 0;
    font-weight: 500;
}

.post-list {
    margin: 0;
    padding-left: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.post-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.post-role {
    font-weight: 600;
}

.post-count {
    color: var(--rk-muted);
}

.post-reqs {
    margin-top: 0.2rem;
}

.tag {
    display: inline-block;
    background: #eef2f8;
    color: var(--rk-brand);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    margin-right: 0.3rem;
}

.shift-list {
    margin: 0.3rem 0 0;
    padding-left: 1rem;
    color: var(--rk-muted);
    font-size: 0.9rem;
}

.muted {
    color: var(--rk-muted);
}

.muted.small {
    font-size: 0.8rem;
}

/* --- The human gate: approve & create --- */
.gate {
    margin-top: 1rem;
    background: var(--rk-surface);
    border: 1px solid var(--rk-border);
    border-left: 4px solid var(--rk-accent);
    border-radius: 10px;
    padding: 1rem 1.1rem;
}

.gate h2 {
    font-size: 1.1rem;
    margin: 0 0 0.4rem;
}

.gate-label {
    display: block;
    font-size: 0.85rem;
    color: var(--rk-muted);
    margin: 0.6rem 0 0.25rem;
}

.gate-button {
    margin-top: 0.6rem;
}

.gate-done {
    background: #def7e6;
    color: #1c7c43;
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}

/* --- Staging blocked: surfaced validation/grounding findings --- */
.blocked {
    margin-top: 1rem;
    background: #fdecec;
    border: 1px solid #f3c2c2;
    border-left: 4px solid #c0392b;
    border-radius: 10px;
    padding: 1rem 1.1rem;
}

.blocked h2 {
    font-size: 1.05rem;
    margin: 0 0 0.4rem;
    color: #a02a22;
}

.finding-list {
    margin: 0;
    padding-left: 1.1rem;
    color: #7a2018;
}

.badge.blocked {
    background: #fdecec;
    color: #a02a22;
}

/* --- Sign-out (topbar) --------------------------------------------------- */
.signout {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
}

.signout-user {
    font-size: 0.85rem;
    opacity: 0.8;
}

.signout-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    padding: 0.3rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
}

/* --- Events admin (read-only store view) -------------------------------- */
.events-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.events-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}

.back-link {
    color: var(--rk-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

.events-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.92rem;
}

.events-table th,
.events-table td {
    text-align: left;
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--rk-border);
    vertical-align: top;
}

.events-table th {
    color: var(--rk-muted);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.events-table tbody tr:hover {
    background: #f6f8fb;
}

.evt-name {
    font-weight: 600;
}

.signout-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* --- Sign-in page -------------------------------------------------------- */
.login {
    width: 100%;
    max-width: 420px;
    margin: 4rem auto;
    padding: 0 1.5rem;
}

.login-card {
    background: var(--rk-surface);
    border: 1px solid var(--rk-border);
    border-radius: 10px;
    padding: 2rem;
}

.login-card h1 {
    margin: 0 0 0.25rem;
}

.login-sub {
    color: var(--rk-muted);
    margin: 0 0 1.25rem;
}

.login-error {
    background: #fdecec;
    border: 1px solid #f3c2c2;
    color: #8a1f1f;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    margin: 0 0 1rem;
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--rk-muted);
}

.login-field input {
    border: 1px solid var(--rk-border);
    border-radius: 6px;
    padding: 0.55rem 0.65rem;
    font-size: 1rem;
    color: var(--rk-text);
}

.login-field input:focus {
    outline: none;
    border-color: var(--rk-accent);
    box-shadow: 0 0 0 2px rgba(47, 111, 235, 0.2);
}

.login-btn {
    background: var(--rk-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.25rem;
}

.login-btn:hover {
    background: #255fd0;
}

/* --- Menu page ----------------------------------------------------------- */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.menu-card {
    display: block;
    background: var(--rk-surface);
    border: 1px solid var(--rk-border);
    border-radius: 10px;
    padding: 1.25rem;
    text-decoration: none;
    color: var(--rk-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.menu-card:hover {
    border-color: var(--rk-accent);
    box-shadow: 0 2px 10px rgba(31, 58, 95, 0.08);
}

.menu-card h2 {
    margin: 0 0 0.4rem;
    font-size: 1.15rem;
    color: var(--rk-brand);
}

.menu-card p {
    margin: 0 0 0.75rem;
    color: var(--rk-muted);
    font-size: 0.9rem;
}

.menu-cta {
    color: var(--rk-accent);
    font-weight: 600;
    font-size: 0.9rem;
}
