:root {
	--red: #d62828;
	--red-dark: #9d1c1c;
	--yellow: #fcbf49;
	--ink: #1d1d1f;
	--muted: #6b7280;
	--line: #e5e7eb;
	--bg: #f7f7f8;
	--green: #16a34a;
	--tap: 44px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var(--ink);
	background: var(--bg);
	line-height: 1.5;
	font-size: 16px;
}
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* Mobile-first container: full-width with comfortable gutters */
.wrap { width: 100%; max-width: 1000px; margin: 0 auto; padding: 0 14px; }

/* ---------- Top bar (mobile-first, collapsible nav) ---------- */
.topbar { background: var(--red); color: #fff; position: sticky; top: 0; z-index: 50; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.brand { display: flex; flex-direction: column; color: #fff; line-height: 1.1; }
.brand:hover { text-decoration: none; }
.brand-main { font-weight: 800; font-size: 18px; }
.brand-sub { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--yellow); }

.nav-toggle {
	display: inline-flex; align-items: center; justify-content: center;
	width: var(--tap); height: var(--tap); margin-right: -8px;
	background: transparent; border: 0; color: #fff; cursor: pointer; padding: 0;
}
.nav-toggle span, .nav-toggle span::before, .nav-toggle span::after {
	content: ""; display: block; width: 22px; height: 2px; background: #fff; position: relative; transition: transform .2s;
}
.nav-toggle span::before { position: absolute; top: -7px; }
.nav-toggle span::after { position: absolute; top: 7px; }

/* Nav is a stacked drawer on mobile, hidden until toggled */
.nav {
	display: none;
	position: absolute; top: 56px; left: 0; right: 0;
	background: var(--red-dark);
	flex-direction: column; align-items: stretch;
	padding: 6px 14px 12px;
	box-shadow: 0 8px 16px rgba(0,0,0,.2);
}
.nav.open { display: flex; }
.nav a { color: #fff; font-size: 16px; padding: 12px 4px; border-bottom: 1px solid rgba(255,255,255,.12); min-height: var(--tap); display: flex; align-items: center; }
.nav a:last-child { border-bottom: 0; }
.nav .btn, .nav .btn-ghost { margin-top: 8px; justify-content: center; }
.nav .btn { background: var(--yellow); color: var(--ink); }

/* ---------- Buttons: full-width & thumb-friendly on mobile ---------- */
.btn, .btn-ghost {
	display: inline-flex; align-items: center; justify-content: center;
	min-height: var(--tap); padding: 11px 18px; border-radius: 10px;
	font-size: 16px; font-weight: 600; cursor: pointer; border: none;
	text-align: center;
}
.btn { background: var(--red); color: #fff; }
.btn:hover { background: var(--red-dark); text-decoration: none; }
.btn-ghost { background: transparent; border: 1px solid currentColor; color: inherit; }
.btn-lg { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-danger { background: #374151; }
form { margin: 0; }

/* ---------- Content ---------- */
main.wrap { padding-top: 18px; padding-bottom: 40px; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 15px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.card-narrow { max-width: 460px; margin-left: auto; margin-right: auto; }

.page-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }

/* Forms: full-width fields, big tap targets, 16px to avoid iOS zoom */
label { display: block; margin-bottom: 14px; font-size: 14px; font-weight: 600; }
input, select, textarea {
	width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
	font-size: 16px; font-weight: 400; margin-top: 5px; min-height: var(--tap);
	background: #fff; -webkit-appearance: none; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
textarea { min-height: 84px; resize: vertical; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: var(--tap); }
label.check input { width: auto; margin: 0; min-height: 0; width: 20px; height: 20px; }

/* Stack rows on mobile */
.row { display: flex; flex-direction: column; gap: 0; }
.row > label { flex: 1; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 32px 16px; background: linear-gradient(135deg, var(--red), var(--red-dark)); color: #fff; border-radius: 16px; margin-bottom: 22px; }
.hero-slim { padding: 20px 16px; }
.hero-slim h1 { margin-bottom: 12px; }
.hero h1 { font-size: 26px; color: #fff; }
.hero p { margin: 0 auto 18px; opacity: .95; font-size: 15px; }
.hero-cta { display: flex; flex-direction: column; gap: 10px; }
.hero .btn, .hero .btn-ghost { width: 100%; }
.hero .btn { background: var(--yellow); color: var(--ink); }
.hero .btn-ghost { color: #fff; }

/* ---------- Columns: stacked on mobile ---------- */
.cols { display: flex; flex-direction: column; gap: 16px; }
.col { width: 100%; }

/* ---------- Riders ---------- */
.rider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rider-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--ink); }
.rider-card:hover { text-decoration: none; border-color: var(--red); }
.rider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rider-bio { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.badge { display: inline-block; background: #eef2ff; color: #3730a3; font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.badge-ready { background: #dcfce7; color: var(--green); }
.stars { color: #b45309; font-size: 13px; font-weight: 600; }

/* ---------- Feed ---------- */
.feed { list-style: none; padding: 0; margin: 0; }
.feed-item { display: flex; gap: 8px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
.feed-merchant { font-weight: 600; }
.feed-brgy, .feed-rider { color: var(--muted); }

.status { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: capitalize; white-space: nowrap; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-claimed { background: #dbeafe; color: #1e40af; }
.status-purchased { background: #e0e7ff; color: #3730a3; }
.status-on_the_way { background: #cffafe; color: #0e7490; }
.status-delivered { background: #dcfce7; color: var(--green); }
.status-cancelled { background: #fee2e2; color: #991b1b; }

.live-dot { display: inline-block; width: 9px; height: 9px; background: var(--green); border-radius: 50%; animation: pulse 1.5s infinite; vertical-align: middle; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: .3; } 100% { opacity: 1; } }

/* ---------- Items ---------- */
.featured { margin-top: 22px; }
.item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.item-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.item-name { font-weight: 600; font-size: 14px; }
.item-price { color: var(--red); font-weight: 700; }
.item-count { font-size: 12px; color: var(--muted); }

/* ---------- Tables become cards on mobile ---------- */
.table { width: 100%; border-collapse: collapse; }
.table thead { display: none; }
.table tr { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: #fff; }
.table td { display: flex; justify-content: space-between; gap: 12px; text-align: right; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.table td:last-child { border-bottom: 0; }
.table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
.table tfoot tr { border-color: var(--red); }
.table tfoot td, .table tfoot th { display: flex; justify-content: space-between; padding: 8px 0; }

.link-danger { color: #991b1b; }
.muted { color: var(--muted); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs a { flex: 1; text-align: center; padding: 12px 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); min-height: var(--tap); display: flex; align-items: center; justify-content: center; }
.tabs a.active { background: var(--red); color: #fff; border-color: var(--red); }

.tracker { list-style: none; display: flex; flex-wrap: wrap; padding: 0; margin: 0; gap: 6px; }
.tracker li { flex: 1 1 30%; text-align: center; font-size: 12px; padding: 10px 4px; border-radius: 10px; background: #f3f4f6; color: var(--muted); }
.tracker li.done { background: var(--green); color: #fff; font-weight: 600; }

.job-card { border-left: 4px solid var(--red); }
.job-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.job-items { margin: 8px 0; padding-left: 18px; font-size: 14px; }

.summary { list-style: none; padding: 0; margin: 0 0 12px; }
.summary li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.total { font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px; text-align: center; color: var(--ink); }
.stat-card:hover { border-color: var(--red); text-decoration: none; }
.stat-num { display: block; font-size: 30px; font-weight: 800; color: var(--red); }
.stat-label { color: var(--muted); font-size: 14px; }

.chip { display: inline-block; background: #f3f4f6; border-radius: 999px; padding: 8px 12px; font-size: 14px; margin: 3px 3px 3px 0; min-height: 0; }
.bio { border-left: 3px solid var(--yellow); padding-left: 12px; color: #374151; font-style: italic; }
.review { padding: 12px 0; border-bottom: 1px solid var(--line); }
.review p { margin: 4px 0; }

.foot { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Cell actions (stacked buttons in table cards) ---------- */
.cell-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* ---------- Chat (mobile-first) ---------- */
.chat { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; margin-top: 12px; }
.chat-log {
	display: flex; flex-direction: column; gap: 8px;
	padding: 14px; overflow-y: auto;
	/* fill most of the viewport under the header on mobile */
	height: calc(100vh - 320px); min-height: 260px;
	background: #f9fafb;
	-webkit-overflow-scrolling: touch;
}
.chat-empty { text-align: center; margin: auto; }
.msg { max-width: 80%; padding: 9px 12px; border-radius: 16px; font-size: 15px; display: flex; flex-direction: column; gap: 3px; word-break: break-word; }
.msg-mine { align-self: flex-end; background: var(--red); color: #fff; border-bottom-right-radius: 4px; }
.msg-them { align-self: flex-start; background: #e5e7eb; color: var(--ink); border-bottom-left-radius: 4px; }
.msg-img { display: block; max-width: 220px; max-height: 260px; border-radius: 10px; margin-bottom: 2px; }
.msg-time { font-size: 11px; opacity: .75; align-self: flex-end; }
.chat-form { display: flex; align-items: center; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.chat-form input[type="text"] { flex: 1; margin: 0; }
.chat-attach {
	display: inline-flex; align-items: center; justify-content: center;
	width: var(--tap); height: var(--tap); min-height: var(--tap);
	border-radius: 10px; background: #f3f4f6; cursor: pointer; font-size: 20px; margin: 0; flex: 0 0 auto;
}
.chat-send { flex: 0 0 auto; }
.chat-preview { position: relative; display: inline-block; padding: 8px 10px 10px; }
.chat-preview img { max-width: 90px; max-height: 90px; border-radius: 8px; border: 1px solid var(--line); }
.chat-preview-x { position: absolute; top: 2px; left: 78px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }

@media (min-width: 640px) {
	.wrap { padding: 0 20px; }
	.nav-toggle { display: none; }
	.nav {
		display: flex; position: static; flex-direction: row; align-items: center;
		background: transparent; padding: 0; box-shadow: none; gap: 16px;
	}
	.nav a { border-bottom: 0; padding: 6px 0; font-size: 14px; min-height: 0; }
	.nav .btn, .nav .btn-ghost { margin-top: 0; }
	.brand-main { font-size: 20px; }

	.btn-lg { width: auto; }
	.hero-cta { flex-direction: row; justify-content: center; }
	.hero .btn, .hero .btn-ghost { width: auto; }
	.hero h1 { font-size: 32px; }

	.page-head { flex-direction: row; align-items: center; justify-content: space-between; }
	.row { flex-direction: row; gap: 12px; }

	.rider-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
	.item-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
	.stat-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

	/* Restore real tables on larger screens */
	.table thead { display: table-header-group; }
	.table tr { display: table-row; border: 0; padding: 0; margin: 0; background: transparent; }
	.table td, .table th { display: table-cell; text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
	.table td::before { display: none; }
	.table thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
	.table tfoot td, .table tfoot th { display: table-cell; }
	.table tfoot th { border-top: 2px solid var(--line); }

	.card { padding: 20px; }
	h1 { font-size: 26px; }
	.chat-log { height: 440px; }
}

/* ============================================================
   Desktop (>= 900px)
   ============================================================ */
@media (min-width: 900px) {
	.cols { flex-direction: row; }
	.col { flex: 1; min-width: 0; }
}
