:root {
    --brand-primary: #9CC73D;
    --brand-primary-hover: #84AB30;
    --brand-primary-light: #ECF3D5;
    --brand-primary-pale: #F7FAEC;
    --brand-accent: #5A6F1D;
    --ink: #1F2622;
    --ink-soft: #3D4439;
    --muted: #6B7268;
    --muted-soft: #9AA095;
    --bg: #F7F8F4;
    --card-bg: #ffffff;
    --bubble-customer: #E8ECE0;
    --bubble-staff: var(--brand-primary-light);
    --border: #DCE3CB;
    --border-soft: #EAEDDF;
    --danger: #C0392B;
    --danger-bg: #FBEAE7;
    --shadow-sm: 0 1px 2px rgba(31, 38, 34, 0.04);
    --shadow-card: 0 4px 16px rgba(31, 38, 34, 0.05);
    --radius-bubble: 18px;
    --radius-card: 14px;
    --radius-input: 10px;
    --tap-min: 44px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
    font-size: 16px;
}
a { color: var(--brand-accent); text-decoration: none; transition: color 0.15s; }
a:hover { text-decoration: underline; }

/* === shell === */
.public-shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px 96px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.public-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 16px;
}
.brand-link { display: inline-flex; align-items: center; gap: 8px; }
.brand-logo { height: 32px; width: auto; }
.public-main { flex: 1; }
.public-footer {
    padding: 24px 0 8px;
    color: var(--muted);
    text-align: center;
    font-size: 0.825rem;
}
.public-footer a { color: var(--muted); }

/* === embed mode (?embed=1) — strip the GTM chrome for in-app WebViews === */
body.is-embed .public-header,
body.is-embed .public-footer { display: none; }
body.is-embed .public-shell { padding: 0; max-width: none; }

/* === generic card === */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-card);
    padding: 24px;
    box-shadow: var(--shadow-card);
}
@media (max-width: 540px) {
    .card { padding: 16px; border-radius: 12px; }
    .public-shell { padding: 12px 12px 96px; }
}

/* === form / new ticket === */
.form-title { margin: 0 0 4px; font-size: 1.5rem; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.form-lead  { margin: 0 0 24px; color: var(--muted); font-size: 0.95rem; }

.field { display: block; margin-bottom: 16px; }
.field > span,
.field-radio > legend {
    display: block;
    font-weight: 600; font-size: 0.875rem;
    margin-bottom: 6px; color: var(--ink-soft);
}
.field input[type=text],
.field input[type=email],
.field select,
.field textarea {
    width: 100%; padding: 11px 14px;
    font: inherit; color: var(--ink);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    background: #fff;
    min-height: var(--tap-min);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}
.field textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

.field-radio { border: 1px solid var(--border); border-radius: var(--radius-input); padding: 12px 14px; }
.field-radio ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 20px; }
.field-radio label { display: inline-flex; gap: 8px; align-items: center; min-height: var(--tap-min); cursor: pointer; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 540px) { .field-grid { grid-template-columns: 1fr; } }

.field-error { color: var(--danger); display: block; margin-top: 6px; font-size: 0.85rem; }

/* === buttons === */
.btn-primary, .btn-secondary {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 12px 20px; font: inherit; font-weight: 600;
    border-radius: var(--radius-input); cursor: pointer;
    border: 1px solid transparent; text-decoration: none;
    min-height: var(--tap-min);
    transition: background 0.15s, transform 0.05s;
}
.btn-primary { background: var(--brand-primary); color: var(--ink); }
.btn-primary:hover { background: var(--brand-primary-hover); text-decoration: none; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--brand-primary-pale); text-decoration: none; }

/* === flash messages === */
.flash-stack { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: var(--radius-input); border: 1px solid; font-size: 0.9rem; }
.flash-success { background: var(--brand-primary-light); border-color: var(--brand-primary); color: var(--brand-accent); }
.flash-error, .flash-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.flash-info { background: #EEF4F8; border-color: #CFE0EA; color: #294F66; }

/* === ticket detail (the "report" page) === */

/* header strip — app icon + name + status + ticket id */
.ticket-header {
    display: flex; gap: 14px; align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 20px;
}
.app-avatar {
    flex-shrink: 0;
    width: 52px; height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover));
    color: var(--ink);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.app-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ticket-header-text { flex: 1; min-width: 0; }
.ticket-app-name {
    margin: 0; font-size: 1.125rem; font-weight: 700;
    color: var(--ink); letter-spacing: -0.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ticket-meta-row {
    display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap;
}
.ticket-id { color: var(--muted); font-size: 0.85rem; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 12px; font-size: 0.78rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.status-pill::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
}
.status-pill-open { background: #FBEAE7; color: #C0392B; }
.status-pill-replied { background: var(--brand-primary-light); color: var(--brand-accent); }
.status-pill-closed { background: #EEEEEE; color: #555; }
.status-pill-canceled { background: #F2F2F2; color: #888; text-decoration: line-through; }

/* thread — chat-style asymmetric bubbles */
.thread {
    display: flex; flex-direction: column; gap: 14px;
    padding: 4px 0 16px;
}
.msg-row { display: flex; gap: 10px; align-items: flex-end; }
.msg-row-customer { flex-direction: row-reverse; }

.msg-avatar {
    flex-shrink: 0;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--brand-primary);
    color: var(--ink);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.78rem;
}
.msg-row-customer .msg-avatar { display: none; }   /* customer doesn't see their own avatar */

.msg-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: var(--radius-bubble);
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    position: relative;
}
.msg-row-customer .msg-bubble {
    background: var(--bubble-customer);
    color: var(--ink);
    border-bottom-right-radius: 6px;
}
.msg-row-staff .msg-bubble {
    background: var(--bubble-staff);
    color: var(--ink);
    border-bottom-left-radius: 6px;
}
.msg-author { font-weight: 600; font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 2px; }
.msg-row-customer .msg-author { display: none; }
.msg-body { white-space: pre-wrap; font-size: 0.95rem; line-height: 1.5; }
.msg-time {
    display: block; margin-top: 4px;
    font-size: 0.72rem; color: var(--muted-soft);
    text-align: right;
}
.msg-row-staff .msg-time { text-align: left; }
.msg-time[title] { cursor: help; }

/* system messages — meta-events, centered, no bubble */
.msg-system {
    align-self: center;
    padding: 6px 14px;
    background: transparent;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
    border: none;
    box-shadow: none;
}
.msg-system::before, .msg-system::after {
    content: '—'; opacity: 0.5; margin: 0 6px;
}

/* "what we know" disclosure */
.disclosure {
    margin: 12px 0 24px;
    padding: 12px 14px;
    background: var(--brand-primary-pale);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-input);
}
.disclosure summary {
    cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft);
    list-style: none; display: flex; align-items: center; gap: 6px;
    min-height: 24px;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::before {
    content: '›'; display: inline-block;
    transition: transform 0.15s;
    color: var(--muted);
    font-size: 1.05rem; line-height: 1;
}
.disclosure[open] summary::before { transform: rotate(90deg); }
.disclosure-content {
    margin-top: 10px;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.78rem; color: var(--muted);
    white-space: pre-wrap; word-break: break-word;
    padding: 8px 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
}

/* composer — sticky on mobile */
.composer {
    position: relative;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
}
.composer-inner {
    display: flex; gap: 8px; align-items: flex-end;
}
.composer-input {
    flex: 1;
    width: 100%;
    padding: 11px 14px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 22px;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-pale);
}
.composer-send {
    flex-shrink: 0;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--brand-primary);
    border: none; cursor: pointer; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s, transform 0.05s;
}
.composer-send:hover:not(:disabled) { background: var(--brand-primary-hover); }
.composer-send:active:not(:disabled) { transform: scale(0.94); }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer-send svg { width: 20px; height: 20px; fill: var(--ink); }

.composer-captcha { margin-top: 10px; }

@media (max-width: 640px) {
    .composer {
        position: sticky; bottom: 0;
        background: var(--card-bg);
        margin: 0 -16px;
        padding: 12px 16px;
        border-top: 1px solid var(--border-soft);
        z-index: 10;
    }
    body.is-embed .composer { margin: 0; padding: 12px; }
}

/* canceled state — explanatory note instead of composer */
.canceled-note {
    margin-top: 20px;
    padding: 14px 16px;
    background: #F4F4F2;
    color: var(--muted);
    border-radius: var(--radius-input);
    text-align: center; font-size: 0.9rem;
}

/* sent toast — fades out after 2s */
.sent-toast {
    position: fixed;
    bottom: 80px; left: 50%; transform: translateX(-50%);
    padding: 10px 18px;
    background: var(--brand-accent);
    color: #fff;
    border-radius: 20px;
    font-size: 0.85rem; font-weight: 500;
    box-shadow: 0 4px 16px rgba(31, 38, 34, 0.2);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 50;
}
.sent-toast.is-visible {
    opacity: 1; transform: translateX(-50%) translateY(-4px);
}

/* what-to-expect footer */
.expectations {
    margin-top: 32px;
    padding: 14px 16px;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    border-top: 1px dashed var(--border-soft);
}
.expectations a { color: var(--muted); text-decoration: underline; }

/* === thanks page === */
.thanks-icon {
    width: 64px; height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--brand-primary-light);
    color: var(--brand-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
}
.thanks-card { text-align: center; }
.ticket-link {
    display: block;
    padding: 12px 14px;
    background: var(--brand-primary-pale);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-input);
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.82rem;
    word-break: break-all;
    margin: 16px 0;
    color: var(--ink-soft);
}

/* === reduce-motion === */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* === captcha widget === */
.cf-turnstile { margin: 12px 0; }
