/* ── Davila Field PWA — Mobile-first dark theme ── */
:root {
    --bg:        #0F172A;
    --surface:   #1E293B;
    --surface2:  #263045;
    --border:    rgba(255,255,255,.08);
    --border2:   rgba(255,255,255,.14);
    --text:      #F1F5F9;
    --muted:     rgba(255,255,255,.45);
    --hint:      rgba(255,255,255,.28);
    --blue:      #3B82F6;
    --blue-dark: #2563EB;
    --green:     #34D399;
    --amber:     #FBBF24;
    --red:       #F87171;
    --radius:    12px;
    --radius-sm: 8px;
    --safe-top:  env(safe-area-inset-top);
    --safe-bot:  env(safe-area-inset-bottom);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    overscroll-behavior: none;
}

/* ── Auth ──────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px 20px; }
.auth-wrap  { width: 100%; max-width: 380px; }

.auth-logo            { text-align: center; margin-bottom: 40px; }
.auth-logo__icon      { font-size: 48px; margin-bottom: 12px; }
.auth-logo__name      { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; }
.auth-logo__sub       { font-size: .875rem; color: var(--muted); margin-top: 4px; }

.auth-form   { display: flex; flex-direction: column; gap: 16px; }
.auth-forgot { display: block; text-align: center; margin-top: 20px; font-size: .875rem; color: var(--muted); text-decoration: none; }
.auth-forgot:hover { color: var(--text); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group  { display: flex; flex-direction: column; gap: 6px; }
.form-label  { font-size: .8125rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form-input  { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text); font-size: 1rem; padding: 14px 16px; outline: none; width: 100%; transition: border-color .15s; -webkit-appearance: none; }
.form-input:focus  { border-color: var(--blue); }
.form-input::placeholder { color: var(--hint); }
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 80px; }

.pin-wrap         { position: relative; }
.pin-wrap .form-input { padding-right: 48px; }
.pin-toggle       { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px; display: flex; align-items: center; }
.pin-toggle:hover { color: var(--text); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn           { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-size: .9375rem; font-weight: 600; padding: 12px 20px; text-decoration: none; transition: opacity .15s, transform .1s; -webkit-appearance: none; }
.btn:active    { transform: scale(.97); }
.btn--primary  { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-dark); }
.btn--ghost    { background: var(--surface2); border: 1px solid var(--border2); color: var(--text); }
.btn--ghost:hover { border-color: var(--border2); background: var(--surface); }
.btn--danger   { background: rgba(248,113,113,.15); border: 1px solid rgba(248,113,113,.3); color: var(--red); }
.btn--success  { background: rgba(52,211,153,.15); border: 1px solid rgba(52,211,153,.3); color: var(--green); }
.btn--full     { width: 100%; }
.btn--lg       { font-size: 1.0625rem; padding: 16px 24px; border-radius: var(--radius); }
.btn--sm       { font-size: .8125rem; padding: 8px 14px; }
.btn--xs       { font-size: .75rem; padding: 5px 10px; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert          { border-radius: var(--radius-sm); font-size: .9375rem; margin-bottom: 16px; padding: 14px 16px; }
.alert--error   { background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.3); color: var(--red); }
.alert--success { background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.3); color: var(--green); }
.alert--info    { background: rgba(59,130,246,.12); border: 1px solid rgba(59,130,246,.3); color: #93C5FD; }

/* ── App shell ─────────────────────────────────────────────── */
.app-shell    { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: calc(68px + var(--safe-bot)); }
.app-header   { background: var(--surface); border-bottom: 1px solid var(--border); padding: calc(var(--safe-top) + 12px) 16px 12px; position: sticky; top: 0; z-index: 50; }
.app-header__row   { display: flex; align-items: center; gap: 12px; }
.app-header__title { font-size: 1.125rem; font-weight: 700; flex: 1; }
.app-header__sub   { font-size: .8125rem; color: var(--muted); margin-top: 2px; }
.app-back     { color: var(--blue); font-size: .9375rem; text-decoration: none; display: flex; align-items: center; gap: 4px; }

.app-content  { flex: 1; padding: 16px; }

/* ── Bottom nav ────────────────────────────────────────────── */
.bottom-nav   { background: var(--surface); border-top: 1px solid var(--border); bottom: 0; display: flex; left: 0; padding-bottom: var(--safe-bot); position: fixed; right: 0; z-index: 50; }
.bottom-nav__item     { align-items: center; color: var(--muted); display: flex; flex: 1; flex-direction: column; font-size: .6875rem; gap: 3px; padding: 10px 4px; text-decoration: none; transition: color .15s; }
.bottom-nav__item.active, .bottom-nav__item:hover { color: var(--blue); }
.bottom-nav__icon { font-size: 22px; line-height: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card         { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.card__header { align-items: center; border-bottom: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; padding: 14px 16px; }
.card__title  { font-size: 1rem; font-weight: 700; }
.card__body   { padding: 16px; }
.card--tap    { cursor: pointer; transition: border-color .15s; }
.card--tap:active { border-color: var(--blue); transform: scale(.99); }

/* ── Job list ──────────────────────────────────────────────── */
.job-card     { align-items: center; display: flex; gap: 14px; padding: 16px; }
.job-card__icon    { background: rgba(59,130,246,.15); border-radius: 10px; font-size: 24px; height: 48px; line-height: 48px; text-align: center; width: 48px; flex-shrink: 0; }
.job-card__info    { flex: 1; min-width: 0; }
.job-card__name    { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card__meta    { color: var(--muted); font-size: .8125rem; margin-top: 2px; }
.job-card__arrow   { color: var(--muted); font-size: 1.25rem; }

/* ── Scope list ─────────────────────────────────────────────── */
.scope-item        { align-items: center; border-bottom: 1px solid var(--border); display: flex; gap: 12px; padding: 14px 16px; }
.scope-item:last-child { border-bottom: none; }
.scope-item__label { flex: 1; }
.scope-item__name  { font-size: .9375rem; font-weight: 600; }
.scope-item__type  { color: var(--muted); font-size: .8125rem; margin-top: 2px; }
.scope-item__actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Photo grid ─────────────────────────────────────────────── */
.photo-grid   { display: grid; gap: 4px; grid-template-columns: repeat(3, 1fr); }
.photo-cell   { aspect-ratio: 1; background: var(--surface2); border-radius: 6px; cursor: pointer; overflow: hidden; position: relative; }
.photo-cell img    { height: 100%; object-fit: cover; width: 100%; }
.photo-cell__type  { background: rgba(0,0,0,.6); border-radius: 4px; bottom: 4px; color: #fff; font-size: .625rem; font-weight: 700; left: 4px; padding: 2px 5px; position: absolute; text-transform: uppercase; }
.photo-upload-btn  { align-items: center; aspect-ratio: 1; background: var(--surface2); border: 2px dashed var(--border2); border-radius: 6px; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; font-size: .8125rem; gap: 4px; justify-content: center; width: 100%; }
.photo-upload-btn .icon { font-size: 28px; }

/* ── Type badges ─────────────────────────────────────────────── */
.badge        { border-radius: 20px; display: inline-flex; font-size: .75rem; font-weight: 700; padding: 3px 10px; }
.badge--before { background: rgba(251,191,36,.15); color: var(--amber); }
.badge--after  { background: rgba(52,211,153,.15); color: var(--green); }
.badge--issue  { background: rgba(248,113,113,.15); color: var(--red); }
.badge--general { background: rgba(255,255,255,.08); color: var(--muted); }

/* ── Checklist ───────────────────────────────────────────────── */
.check-item        { align-items: flex-start; border-bottom: 1px solid var(--border); display: flex; gap: 14px; padding: 14px 16px; }
.check-item:last-child { border-bottom: none; }
.check-item__box   { appearance: none; -webkit-appearance: none; background: var(--surface2); border: 2px solid var(--border2); border-radius: 6px; cursor: pointer; flex-shrink: 0; height: 24px; margin-top: 1px; position: relative; transition: background .15s, border-color .15s; width: 24px; }
.check-item__box:checked { background: var(--blue); border-color: var(--blue); }
.check-item__box:checked::after { color: #fff; content: '✓'; font-size: 14px; font-weight: 700; left: 50%; position: absolute; top: 50%; transform: translate(-50%,-50%); }
.check-item__label { flex: 1; font-size: .9375rem; line-height: 1.5; padding-top: 2px; }
.check-item__label.done { color: var(--muted); text-decoration: line-through; }
.check-item__note  { color: var(--muted); font-size: .8125rem; margin-top: 4px; }

/* ── Mileage ─────────────────────────────────────────────────── */
.mile-row          { border-bottom: 1px solid var(--border); display: flex; gap: 12px; padding: 14px 16px; }
.mile-row:last-child { border-bottom: none; }
.mile-row__info    { flex: 1; }
.mile-row__date    { font-size: .8125rem; color: var(--muted); margin-bottom: 2px; }
.mile-row__route   { font-size: .9375rem; font-weight: 600; }
.mile-row__val     { color: var(--blue); font-size: 1.125rem; font-weight: 800; text-align: right; }

/* ── Crew ─────────────────────────────────────────────────────── */
.crew-row          { align-items: center; border-bottom: 1px solid var(--border); display: flex; gap: 14px; padding: 14px 16px; }
.crew-row:last-child { border-bottom: none; }
.crew-row__avatar  { align-items: center; background: rgba(59,130,246,.18); border-radius: 50%; color: var(--blue); display: flex; font-size: 1.125rem; font-weight: 700; height: 44px; justify-content: center; width: 44px; flex-shrink: 0; }
.crew-row__info    { flex: 1; min-width: 0; }
.crew-row__name    { font-size: .9375rem; font-weight: 700; }
.crew-row__email   { color: var(--muted); font-size: .8125rem; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crew-row__actions { display: flex; gap: 8px; flex-shrink: 0; }
.crew-role         { font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 20px; }
.crew-role--admin  { background: rgba(251,191,36,.15); color: var(--amber); }
.crew-role--crew   { background: rgba(255,255,255,.08); color: var(--muted); }

/* ── Dashboard stats ─────────────────────────────────────────── */
.stat-grid    { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
.stat-card    { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card__val   { font-size: 1.75rem; font-weight: 900; }
.stat-card__label { color: var(--muted); font-size: .75rem; margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }

/* ── Section headers ─────────────────────────────────────────── */
.section-title { color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; margin-bottom: 10px; margin-top: 20px; text-transform: uppercase; }
.section-title:first-child { margin-top: 0; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty        { color: var(--muted); font-size: .9375rem; padding: 40px 20px; text-align: center; }
.empty__icon  { font-size: 48px; margin-bottom: 12px; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-ov     { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 100; align-items: flex-end; justify-content: center; }
.modal-ov.open { display: flex; }
.modal        { background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; padding: 24px 20px calc(24px + var(--safe-bot)); width: 100%; max-width: 480px; }
.modal__handle { background: var(--border2); border-radius: 3px; height: 4px; margin: -8px auto 20px; width: 40px; }
.modal__title  { font-size: 1.125rem; font-weight: 700; margin-bottom: 16px; }
.modal-form    { display: flex; flex-direction: column; gap: 14px; }
.modal-footer  { display: flex; gap: 10px; margin-top: 20px; }
.modal-footer .btn { flex: 1; }

/* ── Loading spinner ─────────────────────────────────────────── */
.spinner      { animation: spin 1s linear infinite; border: 3px solid var(--border2); border-top-color: var(--blue); border-radius: 50%; height: 32px; width: 32px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Offline banner ──────────────────────────────────────────── */
.offline-bar  { background: var(--amber); color: #1a1000; font-size: .8125rem; font-weight: 700; padding: 8px 16px; text-align: center; display: none; }
.offline-bar.show { display: block; }

/* ── Photo type selector ─────────────────────────────────────── */
.type-pills   { display: flex; gap: 8px; flex-wrap: wrap; }
.type-pill    { border-radius: 20px; border: 2px solid var(--border2); color: var(--muted); cursor: pointer; font-size: .875rem; padding: 6px 14px; }
.type-pill.active { border-color: var(--blue); color: var(--blue); }

