/* ===========================================================================
   BESUAL FIELD OPS - Base styles (mobile-first, iPhone Safari optimized)
   Modern, minimal, operational. No frameworks.
   =========================================================================== */

:root {
    --bg:        #0f172a;   /* slate-900 */
    --bg-soft:   #111c33;
    --surface:   #ffffff;
    --surface-2: #f1f5f9;
    --ink:       #0f172a;
    --ink-soft:  #475569;
    --muted:     #94a3b8;
    --line:      #e2e8f0;
    --brand:     #2563eb;   /* blue-600 */
    --brand-ink: #1d4ed8;
    --ok:        #16a34a;
    --warn:      #d97706;
    --danger:    #dc2626;
    --radius:    14px;
    --shadow:    0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--surface-2);
    -webkit-text-size-adjust: 100%;
    line-height: 1.45;
}

/* --- Top bar ------------------------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: var(--bg);
    color: #e2e8f0;
}
.topbar-brand { font-size: 14px; letter-spacing: .12em; }
.topbar-brand b { color: #fff; }
.topbar-user { font-size: 12px; color: var(--muted); }

/* --- Layout -------------------------------------------------------------- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px calc(96px + var(--safe-bottom));
}
.page-title { font-size: 22px; margin: 4px 0 16px; }
.section { margin-bottom: 22px; }
.section-title {
    font-size: 13px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--ink-soft); margin: 0 0 10px;
    display: flex; align-items: center; gap: 8px;
}

/* --- Cards / stats ------------------------------------------------------- */
.card-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

/* --- Lists --------------------------------------------------------------- */
.list {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.list-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-title { font-weight: 600; }
.list-sub { font-size: 12px; color: var(--ink-soft); }
.qty { text-align: right; }
.qty-main { font-weight: 600; }
.qty-sub { font-size: 12px; color: var(--ink-soft); }

/* --- Badges / pills ------------------------------------------------------ */
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 600; }
.badge-ok  { background: #dcfce7; color: #166534; }
.badge-off { background: #f1f5f9; color: #64748b; }
.pill {
    font-size: 11px; background: var(--surface-2); color: var(--ink-soft);
    border-radius: 999px; padding: 2px 8px; font-weight: 600;
}
.pill-demo { background: #fef3c7; color: #92400e; }
.muted-note { font-size: 12px; color: var(--muted); margin: 10px 2px 0; }

/* --- Buttons ------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 50px; padding: 12px 18px; border-radius: 12px;
    border: 1px solid transparent; font-size: 16px; font-weight: 600;
    cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-ink); }
.btn-block { width: 100%; }

/* --- Forms --------------------------------------------------------------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.field-input {
    width: 100%; min-height: 50px; padding: 12px 14px; font-size: 16px;
    border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.field-input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

/* --- Auth card ----------------------------------------------------------- */
.auth-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 24px; margin-top: 28px;
}
.auth-title { margin: 0 0 4px; font-size: 22px; }
.auth-sub { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }

/* --- Flash --------------------------------------------------------------- */
.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-info    { background: #dbeafe; color: #1e40af; }

/* --- Offline banner ------------------------------------------------------ */
.offline-banner {
    position: sticky; top: 0; z-index: 30;
    background: var(--warn); color: #fff; text-align: center;
    font-size: 13px; font-weight: 600; padding: 8px 12px;
}

/* --- Bottom nav ---------------------------------------------------------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 8px 8px calc(8px + var(--safe-bottom));
}
.nav-item {
    flex: 1; text-align: center; text-decoration: none; color: var(--ink-soft);
    font-size: 12px; font-weight: 600; padding: 8px 4px; border-radius: 10px;
}
.nav-item:active { background: var(--surface-2); }
.nav-logout { color: var(--danger); }

/* --- Phase 2: page head, buttons, forms, chips -------------------------- */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin: 4px 0 16px;
}
.page-head .page-title { margin: 0; }

.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.btn-ghost {
    background: #fff; color: var(--ink); border: 1px solid var(--line);
}
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:active { filter: brightness(.92); }

.link { color: var(--brand); text-decoration: none; font-weight: 600; font-size: 14px; }
.link:active { color: var(--brand-ink); }

.row-actions { display: flex; align-items: center; gap: 12px; }

.form-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 480px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
}

.fieldset { border: 0; padding: 0; margin: 0 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--line); border-radius: 999px;
    padding: 8px 12px; font-size: 14px; background: #fff; cursor: pointer;
}
.chip input { accent-color: var(--brand); }
.chip:has(input:checked) { border-color: var(--brand); background: #eff6ff; color: var(--brand-ink); }

.switch {
    display: inline-flex; align-items: center; gap: 10px;
    margin: 4px 0 16px; font-weight: 600;
}
.switch input { width: 20px; height: 20px; accent-color: var(--brand); }

.danger-zone { margin-top: 18px; display: grid; gap: 10px; }
.inline-form { margin: 0; }

.nav-item.is-active { color: var(--brand); background: var(--surface-2); }

/* --- Phase 3: visit flow ------------------------------------------------- */
.store-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.pick-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; text-align: left; cursor: pointer; box-shadow: var(--shadow);
    min-height: 76px; font: inherit; color: var(--ink);
}
.pick-card:active { background: var(--surface-2); }
.pick-card.is-selected { border-color: var(--brand); background: #eff6ff; box-shadow: 0 0 0 2px var(--brand) inset; }
.pick-name { font-weight: 700; font-size: 16px; }
.pick-code { font-size: 12px; color: var(--ink-soft); }

.sticky-action {
    position: sticky; bottom: calc(72px + var(--safe-bottom)); z-index: 5;
    padding-top: 8px;
}

.step-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.step-soon { opacity: .6; }
.step-head { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 8px; }
.step-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 999px; background: var(--brand); color: #fff;
    font-size: 13px; font-weight: 700;
}
.step-soon .step-num { background: var(--muted); }

.list-row-link { text-decoration: none; color: inherit; }
.list-row-link:active { background: var(--surface-2); }

@media (min-width: 640px) {
    .card-grid { grid-template-columns: repeat(4, 1fr); }
}

/* --- Inventory (Phase 4) ------------------------------------------------- */
.btn-secondary {
    background: var(--surface-2); color: var(--ink-soft); border-color: var(--line);
}
.btn-secondary:active { background: #e2e8f0; }

.inv-product {
    border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px;
}
.inv-product:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.inv-product-name { font-weight: 700; margin-bottom: 8px; }
.inv-product-name .muted-note { font-weight: 400; }
.inv-count { margin-bottom: 10px; }
.inv-count-head {
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    color: var(--ink-soft); margin: 12px 0 6px;
}
.inv-moves { margin-bottom: 8px; }

.recon {
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 12px; padding: 10px 12px;
}
.recon-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.recon-var { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 8px; }

/* --- Photo evidence (Phase 5) ------------------------------------------- */
.photo-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    padding: 10px 0; border-top: 1px solid var(--line);
}
.photo-row:first-of-type { border-top: 0; }
.photo-row-label { flex: 1 1 100%; font-weight: 600; font-size: 14px; }
.photo-form { flex: 1 1 auto; display: flex; gap: 8px; align-items: center; }
.photo-input { padding: 8px; font-size: 14px; }
.photo-thumb {
    width: 84px; height: 84px; object-fit: cover; border-radius: 10px;
    border: 1px solid var(--line);
}
.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.photo-cell { margin: 0; }
.photo-cell img { width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); }
.photo-cell figcaption {
    font-size: 13px; color: var(--ink-soft); margin-top: 4px;
    display: flex; align-items: center; gap: 6px; justify-content: space-between;
}
@media (min-width: 640px) {
    .photo-grid { grid-template-columns: repeat(4, 1fr); }
}

/* --- Chips (Phase 9 period selector) ------------------------------------ */
.chip {
    display: inline-block; padding: 8px 14px; border-radius: 999px;
    background: var(--surface-2); color: var(--ink-soft); text-decoration: none;
    font-size: 14px; border: 1px solid var(--line);
}
.chip-on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* --- Reports (Phase 6): printable HTML → Save as PDF -------------------- */
.report-toolbar {
    position: sticky; top: 0; z-index: 5; display: flex; gap: 10px;
    align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.report { max-width: 820px; margin: 0 auto; padding: 20px 16px 60px; }
.report-head { border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 18px; }
.report-brand { font-size: 13px; letter-spacing: .12em; color: var(--brand); font-weight: 700; }
.report-title { font-size: 24px; margin: 2px 0 0; }
.report-sub { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }
.report-section { margin: 18px 0; }
.report-section h3 {
    font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-soft); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin: 0 0 8px;
}
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.report-table th { color: var(--ink-soft); font-weight: 600; }
.report-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: 14px; }
.report-kv div { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: 3px 0; }
.report-kv span { color: var(--ink-soft); }
.report-photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.report-photos img { width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.report-note { color: var(--ink-soft); font-size: 12px; margin-top: 24px; border-top: 1px solid var(--line); padding-top: 8px; }

@media print {
    .no-print, .topbar, .bottom-nav, .report-toolbar { display: none !important; }
    body { background: #fff; }
    .report { max-width: none; margin: 0; padding: 0; }
    .report-photos { grid-template-columns: repeat(2, 1fr); }
    .report-section, figure, tr, .report-head { break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
    @page { margin: 14mm; }
}
