/*
 * Prime RoadRunners — driver app.
 * Builds on ../assets/css/rr.css (colours, buttons, fields, dialogs, toasts).
 *
 * Made for one hand, outdoors: large targets, high contrast, the main action of
 * every card at the bottom of it, within reach of the thumb.
 */

html {
    /* The page itself must not pull down to reload: lists refresh on their own */
    overscroll-behavior-y: contain;
}

body {
    min-height: 100dvh;
}

.app {
    --tabs-height: 64px;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 640px;
    margin: 0 auto;
    padding-bottom: calc(var(--tabs-height) + var(--safe-bottom) + 16px);
}

/* Toasts sit above the tab bar */
:root {
    --toasts-lift: 72px;
}

/* ------------------------------------------------------------------- top bar */

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 12px calc(16px + var(--safe-left));
    background: var(--brand);
    color: var(--on-brand);
}
:root[data-theme='dark'] .topbar {
    background: var(--surface);
    color: var(--ink);
    border-bottom: 1px solid var(--border);
}

.topbar__avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #FFFFFF;
    color: #3A4288;
    font-size: 16px;
    font-weight: 700;
}
:root[data-theme='dark'] .topbar__avatar {
    background: var(--brand);
    color: var(--on-brand);
}

.topbar__who {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
    min-width: 0;
}
.topbar__name {
    overflow: hidden;
    font-size: 17px;
    font-weight: 600;
    line-height: 22px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.topbar__state {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    color: var(--on-brand-2);
    font-size: 13px;
    line-height: 18px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
:root[data-theme='dark'] .topbar__state {
    color: var(--text-2);
}
.topbar__dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #7DDC9A;
}
.topbar__dot.is-off {
    background: #FFB4AB;
}

.topbar__btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    flex-shrink: 0;
    padding: 0;
    border: 0;
    border-radius: var(--r-md);
    background: #3A4288;
    color: #FFFFFF;
}
.topbar__btn .icon {
    width: 22px;
    height: 22px;
}
:root[data-theme='dark'] .topbar__btn {
    background: var(--surface-2);
    color: var(--ink);
}
/* Something about it needs the driver's attention */
.topbar__btn.is-off::after {
    content: '';
    position: absolute;
    top: 7px;
    right: 7px;
    width: 11px;
    height: 11px;
    border: 2px solid #3A4288;
    border-radius: 50%;
    background: #FFB020;
}
:root[data-theme='dark'] .topbar__btn.is-off::after {
    border-color: var(--surface-2);
}
.topbar__btn:focus-visible {
    outline-color: #FFFFFF;
}

/* --------------------------------------------------------------------- stats */

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 12px calc(16px + var(--safe-right)) 4px calc(16px + var(--safe-left));
}
.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    border-radius: 14px;
    color: var(--ink);
    text-align: left;
    box-shadow: none;
}
.stat__label {
    overflow: hidden;
    color: var(--text-3);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.stat__value {
    font-size: 30px;
    line-height: 32px;
    white-space: nowrap;
}
.stat__value.is-long {
    font-size: 24px;
}

/* ---------------------------------------------------------------------- tabs */

.tab {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
}
.tab__head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    margin-right: -8px;
    padding-top: 8px;
}
.tab__titles {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-width: 0;
}
.tab__title {
    font-size: 18px;
    font-weight: 700;
    line-height: 24px;
}
.tab__sub {
    min-height: 16px;
    color: var(--text-3);
    font-size: 12px;
    line-height: 16px;
}

.list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.list--tight {
    gap: 8px;
}
.sentinel {
    height: 1px;
}

/* The bar at the bottom */
.tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-width: 640px;
    height: calc(var(--tabs-height) + var(--safe-bottom));
    margin: 0 auto;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.tabs__item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    padding: 0 2px;
    border: 0;
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
}
.tabs__item .icon {
    width: 24px;
    height: 24px;
}
.tabs__label {
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.tabs__item[aria-current='page'] {
    color: var(--brand);
    font-weight: 700;
}
.tabs__item[aria-current='page']::before {
    content: '';
    position: absolute;
    top: 0;
    right: 18px;
    left: 18px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
}
.tabs__item:focus-visible {
    outline-offset: -3px;
}
.tabs__badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 6px);
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--r-pill);
    background: var(--brand);
    color: var(--on-brand);
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}
.tabs__badge--accent {
    background: var(--accent-strong);
    color: var(--surface);
}

/* --------------------------------------------------------------- order cards */

.order {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}
.order.is-new {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), var(--shadow-1);
}
.order.is-busy {
    opacity: 0.6;
    pointer-events: none;
}

.order__top {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.order__head {
    display: flex;
    align-items: baseline;
    gap: 12px;
}
.order__store {
    flex-grow: 1;
    min-width: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 24px;
    overflow-wrap: anywhere;
}
.order__fee {
    flex-shrink: 0;
    color: var(--success);
    font-size: 26px;
    line-height: 28px;
    white-space: nowrap;
}
.order__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    color: var(--text-3);
    font-size: 13px;
    line-height: 18px;
}

/* The two ends of a delivery, in short */
.stops {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stops__item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
    color: var(--text-2);
    font-size: 15px;
    line-height: 20px;
    overflow-wrap: anywhere;
}
.stops__item b {
    color: var(--ink);
    font-weight: 600;
}
.stops__item .icon {
    margin-top: 0;
}
.icon--pickup { color: var(--brand); }
.icon--drop { color: var(--accent-strong); }

/* Steps of an order that is on its way */
.steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}
.steps__item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-3);
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
}
.steps__item::before {
    content: '';
    height: 4px;
    border-radius: var(--r-pill);
    background: var(--border);
}
.steps__item.is-done {
    color: var(--success);
}
.steps__item.is-done::before {
    background: var(--success);
}
.steps__item.is-now {
    color: var(--ink);
    font-weight: 700;
}
.steps__item.is-now::before {
    background: var(--accent);
}

/* Time left to reach the store */
.clock {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    background: var(--accent);
    color: var(--on-accent);
}
.clock__text {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.clock__label {
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
}
.clock__time {
    font-size: 44px;
    line-height: 44px;
}
.clock__change {
    min-height: var(--tap);
    padding: 0 16px;
    border: 2px solid currentColor;
    border-radius: var(--r-md);
    background: transparent;
    color: inherit;
    font-size: 15px;
    font-weight: 700;
}
.clock.is-late {
    background: var(--danger-soft);
    color: var(--danger-soft-text);
    box-shadow: inset 0 0 0 2px var(--danger-soft-text);
}

/* One end of the delivery, with its two actions */
.place {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.place__where {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.place__where .icon {
    margin-top: 2px;
}
.place__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.place__label {
    color: var(--text-3);
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
    overflow-wrap: anywhere;
}
.place__address {
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
    overflow-wrap: anywhere;
}
.place__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.place__actions .btn {
    min-height: 48px;
    padding: 0 8px;
}

.order__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.order__actions--two {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

/* Placeholder cards while the first answer is on its way */
.order--loading {
    gap: 14px;
}
.order--loading .skeleton {
    height: 16px;
}
.order--loading .skeleton:first-child { width: 60%; height: 22px; }
.order--loading .skeleton:nth-child(2) { width: 40%; }
.order--loading .skeleton:nth-child(4) { height: 52px; border-radius: var(--r-md); }

/* Choosing the minutes to the store */
.minutes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.minutes__btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
}
.minutes__btn:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.minutes__btn[disabled] {
    opacity: 0.5;
}
.minutes__number {
    font-size: 28px;
    line-height: 30px;
}
.minutes__unit {
    color: var(--text-3);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
}

/* ---------------------------------------------------------------------- live */

.live {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
}
.live.is-mine {
    border-color: var(--brand);
}
.live__avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-soft-text);
    font-size: 15px;
    font-weight: 700;
}
.live__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
    min-width: 0;
}
.live__top {
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.live__name {
    flex-grow: 1;
    overflow: hidden;
    font-size: 15px;
    font-weight: 700;
    line-height: 20px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.live__when {
    flex-shrink: 0;
    color: var(--text-3);
    font-size: 13px;
}
.live__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    color: var(--text-2);
    font-size: 14px;
    line-height: 18px;
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------- history */

.day {
    margin-top: 8px;
    color: var(--text-3);
    font-size: 13px;
    font-weight: 700;
    line-height: 18px;
    text-transform: none;
}
.day:first-child {
    margin-top: 0;
}

.past {
    box-shadow: none;
}
.past__summary {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 60px;
    padding: 8px 8px 8px 14px;
    border: 0;
    border-radius: var(--r-lg);
    background: transparent;
    color: inherit;
    text-align: left;
}
.past__main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
    min-width: 0;
}
.past__store {
    overflow: hidden;
    font-size: 15px;
    font-weight: 700;
    line-height: 20px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.past__line {
    overflow: hidden;
    color: var(--text-3);
    font-size: 13px;
    line-height: 18px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.past__side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
}
.past__fee {
    font-size: 20px;
    line-height: 22px;
}
.past__fee.is-earned {
    color: var(--success);
}
.past__chevron {
    color: var(--text-3);
    transition: transform 0.15s ease;
}
.past[data-open='true'] .past__chevron {
    transform: rotate(180deg);
}
.past__details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 14px 14px;
    border-top: 1px solid var(--border);
}
.past__details .row {
    min-height: 0;
    padding: 8px 0;
    align-items: flex-start;
}
.past__details .row__label {
    flex: 0 0 38%;
    font-size: 14px;
}
.past__details .row__value {
    flex: 1 1 auto;
    font-size: 14px;
}

.field--inline .select {
    min-height: 44px;
}

/* ------------------------------------------------------------------ settings */

/* Steps in a dialog: how to install, how to allow notifications */
.howto {
    display: flex;
    flex-direction: column;
    gap: 10px;
    counter-reset: step;
}
.howto li {
    position: relative;
    min-height: 28px;
    padding-left: 40px;
    color: var(--ink);
    font-size: 15px;
    line-height: 22px;
    counter-increment: step;
}
.howto li::before {
    content: counter(step);
    position: absolute;
    top: -2px;
    left: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-soft-text);
    font-size: 14px;
    font-weight: 700;
    line-height: 28px;
    text-align: center;
}
.howto .icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    vertical-align: -3px;
}

/* A narrow phone */
@media (max-width: 359px) {
    .stat__value { font-size: 24px; line-height: 28px; }
    .stat__value.is-long { font-size: 20px; }
    .order__actions--two { grid-template-columns: minmax(0, 1fr); }
    .clock__time { font-size: 36px; line-height: 38px; }
    .tabs__item { font-size: 11px; }
}
