/* Trwi - hand-written, mobile-first CSS. No framework, no CDN, no build step. */
:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1b2430;
    --muted: #5b6675;
    --border: #d9dee5;
    --accent: #1f5fd1;
    --accent-dark: #174aa6;
    --ok: #17703a;
    --ok-bg: #e5f6ec;
    --warn: #8a5a00;
    --warn-bg: #fff4d6;
    --error: #a3231a;
    --error-bg: #fde8e6;
    --info: #1b4f8f;
    --info-bg: #e6f0fc;
    --radius: 10px;
    --tap: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
img, svg, video { max-width: 100%; height: auto; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow-wrap: anywhere; /* a very long email, name or URL wraps instead of making the page scroll sideways on a phone */
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1 { font-size: 1.5rem; margin: 1rem 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code { background: #eef1f5; padding: .1em .35em; border-radius: 4px; }
pre { background: #101826; color: #e6edf7; padding: .9rem; border-radius: var(--radius); overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: .5rem 0; }
pre code { background: none; padding: 0; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 1rem; }
main.container { padding-bottom: 2rem; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; min-height: 56px; }
.brand { font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.nav { display: flex; gap: .25rem; flex: 1 1 auto; overflow-x: auto; }
.nav a { padding: .6rem .75rem; text-decoration: none; color: var(--muted); border-radius: 8px; white-space: nowrap; min-height: var(--tap); display: inline-flex; align-items: center; }
.nav a.active, .nav a:hover { background: #eef2fa; color: var(--accent-dark); }
.logout { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-left: auto; min-width: 0; max-width: 100%; }
.logout .muted { min-width: 0; }
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; padding-top: 1rem; padding-bottom: 2rem; border-top: 1px solid var(--border); }

/* Cards, grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.kpi .label { color: var(--muted); font-size: .85rem; }

/* Forms */
.form-row { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
    width: 100%; min-height: var(--tap); padding: .55rem .7rem; font: inherit; color: inherit;
    background: #fff; border: 1px solid #b8c0cc; border-radius: 8px;
}
textarea { min-height: 8rem; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid #9bbcf5; outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 1.2rem; height: 1.2rem; vertical-align: middle; margin-right: .4rem; }
.inline-label { font-weight: 400; display: flex; align-items: center; min-height: var(--tap); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 1rem; padding: .75rem 1rem; min-width: 0; }
legend { font-weight: 600; padding: 0 .4rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: var(--tap); padding: .55rem 1.1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.btn:hover { background: #f1f3f6; color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { background: #7f1b14; color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 36px; padding: .3rem .7rem; font-size: .875rem; }
.btn[disabled], button[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline { display: inline; }

/* Alerts and badges (state is always conveyed with text, not color alone) */
.alert { border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; border: 1px solid transparent; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #b9e3c9; }
.alert-error { background: var(--error-bg); color: var(--error); border-color: #f3beb9; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #f1d98f; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bcd5f3; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: #e9edf2; color: var(--muted); letter-spacing: .02em; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-fail, .badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* Tables: scroll sideways on small screens */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }

/* Checklists and installer steps */
.checklist { list-style: none; padding: 0; margin: 1rem 0; }
.check { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.check .badge { min-width: 5.5rem; text-align: center; margin-top: .15rem; }
.steps { list-style: none; display: flex; gap: .5rem; padding: 0; margin: 1rem 0; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.steps li span { display: inline-flex; width: 1.7rem; height: 1.7rem; align-items: center; justify-content: center; border-radius: 50%; background: #e3e8ef; font-weight: 700; }
.steps li.current { color: var(--text); font-weight: 700; }
.steps li.current span { background: var(--accent); color: #fff; }
.steps li.done span { background: var(--ok); color: #fff; }

/* Sign-in page */
.hero { text-align: center; padding: 2.5rem 0 1rem; }
.hero p { max-width: 36rem; margin-left: auto; margin-right: auto; }

/* Copy box */
.copybox { position: relative; }
.copybox .btn { margin-top: .25rem; }

/* Event stream */
.stream-status { display: inline-flex; align-items: center; gap: .4rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; word-break: break-all; }

@media (max-width: 480px) {
    .logout { flex: 1 1 100%; margin-left: 0; justify-content: space-between; padding-bottom: .5rem; }
    h1 { font-size: 1.3rem; }
    .btn { width: 100%; }
    .actions .btn, .logout .btn { width: auto; }
    .check { flex-direction: column; gap: .25rem; }
}

/* CRM: lead cards, status chips, lead page (phone first) */
input[type=tel], input[type=date], input[type=time], input[type=datetime-local] {
    width: 100%; min-height: var(--tap); padding: .55rem .7rem; font: inherit; color: inherit;
    background: #fff; border: 1px solid #b8c0cc; border-radius: 8px;
}
.subnav { margin: .5rem 0 1rem; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding: .25rem 0 .75rem; -webkit-overflow-scrolling: touch; }
.chip { flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 40px; padding: .3rem .8rem; border: 1px solid var(--border); border-radius: 999px; background: #fff; color: var(--text); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.lead-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; margin: .6rem 0; overflow-wrap: anywhere; }
.lead-card-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .2rem; }
.lead-name { font-weight: 700; font-size: 1.05rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .6rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.card { overflow-wrap: anywhere; }

/* qualification checklist on the lead page: one big tap target per row */
.crit { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.crit input { flex: none; width: 1.25rem; height: 1.25rem; margin-top: .2rem; }

/* transactions on the lead page */
.tx { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.tx details { margin: .6rem 0; }
.tx summary { cursor: pointer; font-weight: 600; padding: .4rem 0; }

/* members page: a select and its button on one line, wrapping on a phone */
.inline-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0; }
.inline-form select { max-width: 100%; }

/* code samples in the webhook guide */
pre.code { overflow-x: auto; padding: .8rem; border: 1px solid var(--border); border-radius: 6px; font-size: .8rem; line-height: 1.45; }

/* import progress */
progress.import-progress { width: 100%; height: 1.1rem; margin: .6rem 0; }

/* lead list: tick box and bulk bar */
.bulk-pick { float: right; font-size: .85rem; }
.bulk-bar { margin-top: 1rem; }
