/* ============================================================
   AMC-Go — shared theme
   Same structural pattern as Snap2Fix's theme.css (mobile-first,
   fixed header/footer shell, no desktop split-panel layouts),
   using the AMC-Go logo's brand colors: #123B6D deep blue as
   primary, #20A85A green as the accent (technician role, FABs,
   in-progress highlights, site-boundary polygon, etc.).
   ============================================================ */

:root {
    --primary: #123B6D;
    --primary-deep: #0C2850;
    --primary-light: #3E6699;
    --accent: #20A85A;
    --accent-deep: #178246;
    --danger: #E5484D;
    --success: #22B14C;

    --ink: #10162F;
    --muted: #5B6178;
    --muted-light: #9AA1B4;

    --bg: #EEF1F8;
    --surface: #FFFFFF;
    --line: #DEE3F0;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --font-display: 'Sora', sans-serif;
    --font-body: 'Inter', sans-serif;

    --header-h: 56px;
    --footer-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

h1, h2, h3, .ag-display { font-family: var(--font-display); font-weight: 700; color: var(--ink); margin: 0; }

a { color: var(--primary); }

/* ---------- Page shell ---------- */
.ag-page {
    min-height: 100%;
    padding-top: calc(var(--header-h) + var(--safe-top));
    padding-bottom: calc(var(--footer-h) + var(--safe-bottom));
}
.ag-page.no-footer { padding-bottom: calc(16px + var(--safe-bottom)); }
.ag-page.no-header { padding-top: 16px; }

/* ---------- Header bar ---------- */
.ag-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 500;
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between;
    padding-left: 14px; padding-right: 10px;
}
.ag-header .ag-back { font-size: 1.1rem; color: var(--ink); padding: 8px; margin-left: -8px; }
.ag-header .ag-title { font-family: var(--font-display); font-weight: 700; font-size: 1rem; flex: 1; text-align: left; padding-left: 4px; }
.ag-header .ag-title .ag-subtitle { display: block; font-family: var(--font-body); font-weight: 500; font-size: 0.72rem; color: var(--muted); margin-top: 1px; }

/* Uniform header variant: logo left, version+role stacked right, then the
   3-dot menu button. .role-admin tints the role label brand-blue,
   .role-tech tints it brand-orange. */
.ag-header.uniform { justify-content: space-between; }
.ag-header .hdr-logo { height: 28px; }
.ag-header .hdr-right { display: flex; align-items: center; gap: 10px; }
.ag-header .hdr-text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.ag-header .hdr-version { font-size: 0.7rem; font-weight: 700; color: var(--accent-deep); }
.ag-header .hdr-role { font-weight: 700; font-size: 0.82rem; }
.ag-header.role-admin .hdr-role { color: var(--primary); }
.ag-header.role-tech .hdr-role { color: var(--accent-deep); }
.ag-header .ag-menu-btn { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.1rem; border: none; background: none; cursor: pointer; }
.ag-header .ag-menu-btn:active { background: var(--bg); }

.menu-pop {
    position: fixed; top: calc(var(--header-h) + var(--safe-top) + 4px); right: 10px; z-index: 600;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
    box-shadow: 0 10px 26px rgba(16,22,47,0.14); overflow: hidden; display: none; min-width: 170px;
}
.menu-pop a { display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-size: 0.88rem; color: var(--ink); font-weight: 500; text-decoration: none; }
.menu-pop a:active { background: var(--bg); }

/* ---------- Footer nav bar ---------- */
.ag-footer {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 500;
    height: calc(var(--footer-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
    display: flex;
}
.ag-footer .ag-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: var(--muted-light); font-size: 0.68rem; font-weight: 600; text-decoration: none;
}
.ag-footer .ag-tab i { font-size: 1.15rem; }
.ag-footer .ag-tab.active { color: var(--primary); }

/* ---------- Buttons ---------- */
.ag-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; border: none; cursor: pointer;
    padding: 0.95rem; border-radius: var(--radius-md);
    font-family: var(--font-body); font-weight: 600; font-size: 0.95rem;
}
.ag-btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-deep)); color: #fff; box-shadow: 0 6px 16px rgba(18,59,109,0.28); }
.ag-btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #fff; box-shadow: 0 6px 16px rgba(32,168,90,0.28); }
.ag-btn-outline { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary-light); }
.ag-btn-danger { background: var(--danger); color: #fff; }
.ag-btn:disabled { opacity: 0.55; pointer-events: none; }

/* ---------- Inputs ---------- */
.ag-field { position: relative; margin-bottom: 14px; }
.ag-field label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.ag-field input, .ag-field select, .ag-field textarea {
    width: 100%; border: 1.5px solid var(--line); border-radius: var(--radius-md);
    background: var(--surface); padding: 0.85rem 1rem; font-family: var(--font-body);
    font-size: 0.95rem; color: var(--ink);
}
.ag-field input:focus, .ag-field select:focus, .ag-field textarea:focus {
    outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(18,59,109,0.14);
}
.ag-field .ag-field-toggle {
    position: absolute; right: 6px; top: 30px; width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--muted-light); padding: 0; cursor: pointer;
}
.ag-field .ag-field-toggle i { font-size: 1rem; line-height: 1; }

/* ---------- Cards ---------- */
.ag-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; }

/* ---------- Loading overlay ---------- */
.ag-loading {
    position: fixed; inset: 0; z-index: 999999;
    background: rgba(238,241,248,0.9); backdrop-filter: blur(2px);
    display: none; align-items: center; justify-content: center;
}
.ag-loading .ag-spinner {
    width: 38px; height: 38px; border-radius: 50%;
    border: 3px solid var(--line); border-top-color: var(--primary);
    animation: ag-spin 0.7s linear infinite;
}
@keyframes ag-spin { to { transform: rotate(360deg); } }

/* ---------- Status pills ---------- */
.ag-pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.ag-pill-open { background: rgba(32,168,90,0.15); color: #A9500E; }
.ag-pill-progress { background: rgba(18,59,109,0.12); color: var(--primary-deep); }
.ag-pill-closed { background: rgba(34,177,76,0.14); color: #1C8A3C; }

/* ---------- Role segmented toggle (login page) ---------- */
.ag-seg { display: flex; background: var(--bg); border-radius: var(--radius-md); padding: 4px; margin-bottom: 22px; }
.ag-seg button {
    flex: 1; border: none; background: none; padding: 0.7rem; border-radius: calc(var(--radius-md) - 2px);
    font-family: var(--font-body); font-weight: 600; font-size: 0.88rem; color: var(--muted); cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ag-seg button.active { background: var(--surface); color: var(--primary); box-shadow: 0 2px 6px rgba(18,59,109,0.12); }
.ag-seg button:not(.active) { border: 1px solid var(--line); }
.ag-seg button:not(.active):active { background: rgba(18,59,109,0.05); }
.ag-seg button.active.tech-active { color: var(--accent-deep); }

.status-pill { display: inline-block; margin-top: 2px; margin-left: 6px; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status-pill.st-active { color: #1C8A3C; background: rgba(34,177,76,0.14); }
.status-pill.st-inactive { color: var(--muted); background: rgba(91,97,120,0.12); }
.status-pill.st-expired { color: var(--danger); background: rgba(229,72,77,0.12); }
.status-pill.st-progress { color: var(--accent-deep); background: rgba(32,168,90,0.14); }
.qr-secondary-btn { flex: 1 1 47%; width: auto; font-size: 0.82rem; padding: 0.6rem 0.5rem; }

.status-pill.mini, .interval-pill.mini { font-size: 0.68rem; padding: 1px 7px; margin-left: 6px; }

.cr-sm-cm { display: flex; flex-wrap: nowrap; gap: 10px; margin-top: 5px; font-size: 0.72rem; color: var(--muted-light); align-items: center; overflow: hidden; }
.cr-sm-cm .crsc-item { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-sm-cm .crsc-item:first-child { flex-shrink: 0; } /* SM stays fully visible; CM truncates first if space runs out */
.cr-sm-cm .crsc-num { font-weight: 700; color: var(--muted-light); }
.cr-sm-cm .crsc-num-danger { color: var(--danger); }
.cr-sm-cm .crsc-num-success { color: var(--accent-deep); }
.cr-sm-cm .mini-pill { display: inline-block; font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.cr-sm-cm .mini-pill.mp-danger { color: var(--danger); background: rgba(229,72,77,0.12); }
.cr-sm-cm .mini-pill.mp-success { color: var(--accent-deep); background: rgba(32,168,90,0.14); }
.interval-pill { display: inline-block; margin-top: 2px; margin-left: 6px; font-size: 0.7rem; font-weight: 700; color: var(--primary); background: rgba(18,59,109,0.08); padding: 2px 8px; border-radius: 999px; }

.fab-pill.no-footer-page { bottom: calc(16px + var(--safe-bottom)); }

/* ---------- Detail timeline (Reported -> Accepted -> Completed), Snap2Fix style ---------- */
.detail-step { display: flex; gap: 12px; margin-bottom: 18px; }
.detail-step .ds-dot { width: 34px; height: 34px; border-radius: 50%; background: var(--bg); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.9rem; }
.detail-step .ds-body { flex: 1; min-width: 0; }
.detail-step .ds-label { font-weight: 700; font-size: 0.92rem; }
.detail-step .ds-time { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.detail-step .ds-duration { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.detail-step .ds-photo { width: 100%; border-radius: var(--radius-md); margin-top: 8px; cursor: pointer; display: block; }
.detail-step .ds-note { font-size: 0.85rem; color: var(--ink); margin-top: 6px; line-height: 1.5; }

/* ---------- Fullscreen photo viewer with pinch-zoom + pan ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(10,14,30,0.94); z-index: 900; display: none; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.lightbox img { max-width: 100%; max-height: 100%; touch-action: none; will-change: transform; user-select: none; -webkit-user-drag: none; }
.lightbox .lb-close { position: fixed; top: calc(16px + var(--safe-top)); right: 16px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.15); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; z-index: 901; border: none; }
.lightbox .lb-hint { position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 0; right: 0; text-align: center; color: rgba(255,255,255,0.6); font-size: 0.76rem; }

.visit-num-pill { display: inline-block; font-size: 0.72rem; font-weight: 700; color: var(--primary); background: rgba(18,59,109,0.08); padding: 2px 9px; border-radius: 999px; flex-shrink: 0; margin-left: 8px; }

/* ---------- Technician dashboard: visit rows, multi-photo capture ---------- */
.visit-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; margin-bottom: 10px; cursor: pointer; }
.visit-row .vr-icon { width: 42px; height: 42px; border-radius: 10px; background: rgba(32,168,90,0.1); display: flex; align-items: center; justify-content: center; color: var(--accent-deep); font-size: 1.05rem; flex-shrink: 0; }
.visit-row .vr-info { flex: 1; min-width: 0; }
.visit-row .vr-name { font-weight: 700; font-size: 0.9rem; }
.visit-row .vr-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }

.visit-pair-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.visit-pair-row .visit-pair-arrow { color: var(--muted-light); font-size: 1.1rem; flex-shrink: 0; }
.visit-pair-row .photo-slot, .visit-pair-row .add-photo-btn { width: auto; flex: 1; height: 160px; }

.photo-slot-grid { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.photo-slot { width: 100%; height: 220px; border-radius: var(--radius-md); position: relative; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-md); }
.photo-slot .ps-remove { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; background: rgba(16,22,47,0.7); color: #fff; border: none; display: flex; align-items: center; justify-content: center; font-size: 0.72rem; }
/* Checklist Yes / No / N/A answer buttons */
.yna-row { display: flex; gap: 8px; }
.yna-btn { flex: 1; border: 1.5px solid var(--line); background: var(--surface); border-radius: var(--radius-md); padding: 0.65rem 0.4rem; font-family: var(--font-body); font-weight: 600; font-size: 0.9rem; color: var(--muted); cursor: pointer; }
.yna-btn.selected[data-val="Yes"] { background: rgba(34,177,76,0.14); border-color: #1C8A3C; color: #1C8A3C; }
.yna-btn.selected[data-val="No"] { background: rgba(229,72,77,0.12); border-color: var(--danger); color: var(--danger); }
.yna-btn.selected[data-val="N/A"] { background: rgba(91,97,120,0.12); border-color: var(--muted); color: var(--ink); }

.add-photo-btn { width: 100%; height: 220px; border-radius: var(--radius-md); border: 1.5px dashed var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted-light); cursor: pointer; font-size: 0.8rem; gap: 6px; background: none; }

/* ---------- Public contract page (anonymous, QR-scanned) ---------- */
.pc-hero { padding: 22px 20px 16px; text-align: center; }
.pc-hero .pc-client { font-size: 1.2rem; }
.pc-hero .pc-sub { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

.pc-action-card { margin: 0 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; text-align: center; }
.pc-action-card i { font-size: 1.6rem; color: var(--accent-deep); margin-bottom: 8px; display: block; }
.pc-action-card .pc-action-title { font-family: var(--font-display); font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.pc-action-card .pc-action-sub { font-size: 0.82rem; color: var(--muted); margin-bottom: 14px; }
.pc-limit-note { font-size: 0.8rem; color: var(--danger); margin-top: 10px; }

.pc-section-title { padding: 0 16px; font-size: 0.95rem; font-weight: 700; margin-bottom: 10px; }

.visit-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; margin: 0 16px 12px; }
.visit-card .vc-date { font-weight: 700; font-size: 0.88rem; margin-bottom: 6px; }
.visit-card .vc-details { font-size: 0.84rem; color: var(--ink); line-height: 1.5; margin-bottom: 10px; }
.visit-card .vc-photos { display: flex; gap: 12px; }
.visit-card .vc-photo-group { flex: 1; }
.visit-card .vc-photo-label { font-size: 0.68rem; font-weight: 700; color: var(--muted-light); text-transform: uppercase; margin-bottom: 4px; }
.visit-card .vc-photo-row { display: flex; gap: 4px; flex-wrap: wrap; }
.visit-card .vc-photo-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }

.photo-capture-box { border: 1.5px dashed var(--line); border-radius: var(--radius-md); padding: 20px; text-align: center; margin-bottom: 14px; cursor: pointer; }
.photo-capture-box i { font-size: 1.4rem; color: var(--muted-light); display: block; margin-bottom: 6px; }
.photo-capture-box .pcb-text { font-size: 0.84rem; color: var(--muted); }
.photo-preview-wrap { position: relative; margin-bottom: 14px; }
.photo-preview-wrap img { width: 100%; border-radius: var(--radius-md); max-height: 220px; object-fit: cover; }
.photo-preview-wrap .ppw-remove { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; background: rgba(16,22,47,0.6); color: #fff; border: none; display: flex; align-items: center; justify-content: center; }

/* ---------- CM requests list ---------- */
.cm-filter-row { display: flex; gap: 6px; padding: 0 16px 12px; }
.cm-filter-row button { flex: 1; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 0.5rem 0.4rem; font-family: var(--font-body); font-weight: 600; font-size: 0.76rem; color: var(--muted); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-filter-row button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Tab rows with more tabs than fit a phone: keep each tab its natural width
   and let the row scroll sideways (no visible scrollbar). */
.cm-filter-row.scroll-tabs { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.cm-filter-row.scroll-tabs::-webkit-scrollbar { display: none; }
.cm-filter-row.scroll-tabs button { flex: 0 0 auto; padding: 0.5rem 0.9rem; }

.cm-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px; margin-bottom: 10px; cursor: pointer; }
.cm-row .cm-thumb { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--bg); }
.cm-row .cm-thumb-placeholder { width: 48px; height: 48px; border-radius: 10px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--muted-light); font-size: 1.1rem; flex-shrink: 0; }
.cm-row .cm-info { flex: 1; min-width: 0; }
.cm-row .cm-client { font-weight: 700; font-size: 0.9rem; }
.cm-row .cm-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.cm-row .fa-chevron-right { color: var(--muted-light); }

/* ---------- CM detail sheet ---------- */
.cm-detail-section { margin-bottom: 16px; }
.cm-detail-section .cds-label { font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.cm-detail-section .cds-text { font-size: 0.88rem; color: var(--ink); line-height: 1.5; }
.cm-detail-section img { width: 100%; border-radius: var(--radius-md); margin-top: 6px; }

/* ---------- Technicians list ---------- */
.tech-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; margin-bottom: 10px; cursor: pointer; }
.tech-avatar {
    width: 42px; height: 42px; border-radius: 50%; background: rgba(32,168,90,0.12);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display); font-weight: 700; color: var(--accent-deep); font-size: 0.9rem; flex-shrink: 0;
}
.tech-avatar.tech-avatar-photo { padding: 0; overflow: hidden; background: var(--line); }
.tech-avatar.tech-avatar-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.tech-row .tech-info { flex: 1; min-width: 0; }
.tech-row .tech-name { font-weight: 700; font-size: 0.92rem; }
.tech-row .tech-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.tech-row .fa-chevron-right { color: var(--muted-light); }

/* ---------- Contracts list ---------- */
.contract-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; margin-bottom: 10px; cursor: pointer; }
.contract-row .cr-icon { width: 42px; height: 42px; border-radius: 10px; background: rgba(18,59,109,0.08); display: flex; align-items: center; justify-content: center; color: var(--primary); font-size: 1.05rem; flex-shrink: 0; }
.contract-row .cr-icon.cr-icon-photo { padding: 0; overflow: hidden; background: var(--line); }
.contract-row .cr-icon.cr-icon-photo img { width: 100%; height: 100%; object-fit: cover; }
.contract-row .cr-info { flex: 1; min-width: 0; }
.contract-row .cr-name { font-weight: 700; font-size: 0.92rem; }
.contract-row .cr-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.contract-row .fa-chevron-right { color: var(--muted-light); }

.fab-pill {
    position: fixed; right: 16px; bottom: calc(var(--footer-h) + var(--safe-bottom) + 16px); z-index: 400;
    display: flex; align-items: center; gap: 8px; border: none; border-radius: 999px;
    padding: 0.85rem 1.2rem; background: linear-gradient(135deg, var(--primary), var(--primary-deep)); color: #fff;
    font-family: var(--font-body); font-weight: 700; font-size: 0.88rem; box-shadow: 0 8px 20px rgba(18,59,109,0.3); cursor: pointer;
}

.empty-state { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-state i { font-size: 1.8rem; color: var(--muted-light); margin-bottom: 10px; display: block; }
.empty-state .es-text { font-size: 0.88rem; }

/* ---------- Profile page ---------- */
.profile-hero { display: flex; flex-direction: column; align-items: center; padding: 26px 16px 20px; }
.profile-avatar-wrap { position: relative; cursor: pointer; margin-bottom: 12px; }
.profile-avatar {
    width: 72px; height: 72px; border-radius: 50%; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; color: var(--primary);
}
.profile-avatar-img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; display: none; }
.profile-avatar-wrap.has-photo .profile-avatar { display: none; }
.profile-avatar-wrap.has-photo .profile-avatar-img { display: block; }
.avatar-cam-badge {
    position: absolute; bottom: 0; right: -2px; width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; border: 2px solid #fff;
}
.profile-name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.profile-name .edit-icon { color: var(--muted-light); font-size: 0.85rem; cursor: pointer; }
.profile-email { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }

.section { padding: 0 16px; margin-bottom: 16px; }
.section-label { font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }

.facility-card { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; }
.facility-card .fc-icon { width: 42px; height: 42px; border-radius: 10px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--primary); font-size: 1.1rem; flex-shrink: 0; }
.facility-card .fc-info { flex: 1; min-width: 0; }
.facility-card .fc-name { font-weight: 700; font-size: 0.92rem; }
.facility-card .fc-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }

.action-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.action-item { display: flex; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.action-item:last-child { border-bottom: none; }
.action-item i:first-child { width: 20px; text-align: center; color: var(--muted); }
.action-item .ai-label { flex: 1; font-size: 0.88rem; font-weight: 500; }
.action-item.danger .ai-label { color: var(--danger); }
.action-item.danger i:first-child { color: var(--danger); }

/* ---------- Bottom sheet ---------- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(16,22,47,0.4); z-index: 700; display: none; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 701; background: var(--surface); border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom)); display: none; }
.sheet .sheet-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; margin-bottom: 14px; }

/* Full-height variant - fills the whole screen instead of a bottom sheet,
   used for the boundary map so it gets real room to work with. */
.sheet.sheet-full { top: 0; border-radius: 0; flex-direction: column; padding-top: calc(10px + var(--safe-top)); }
.sheet.sheet-full .map-container.full { flex: 1; height: auto; min-height: 0; margin-bottom: 6px; }
.sheet.sheet-full .sheet-title { margin-bottom: 8px; }
.map-btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.map-btn-row .ag-btn { flex: 1; padding: 0.7rem; }

/* ---------- Dashboard content ---------- */
.dash-welcome { padding: 18px 20px 4px; }
.dash-welcome .dash-company { font-size: 1.2rem; }
.dash-welcome .dash-plan { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 10px; border-radius: 999px; background: rgba(18,59,109,0.08); color: var(--primary); font-size: 0.74rem; font-weight: 700; }

.stat-card-row { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px 20px; }
.stat-card {
    display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: 16px; text-decoration: none; color: var(--ink);
}
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0; }
.stat-card .stat-icon.si-contracts { background: rgba(18,59,109,0.1); color: var(--primary); }
.stat-card .stat-icon.si-tech { background: rgba(32,168,90,0.12); color: var(--accent-deep); }
.stat-card .stat-icon.si-cm { background: rgba(229,72,77,0.1); color: var(--danger); }
.stat-card .stat-icon.si-visits { background: rgba(18,59,109,0.1); color: var(--primary); }

.stat-breakdown { display: flex; flex-wrap: wrap; column-gap: 10px; row-gap: 2px; margin-top: 4px; }
.stat-breakdown .sb-item { font-size: 0.74rem; color: var(--muted-light); white-space: nowrap; flex-shrink: 0; }
.stat-breakdown .sb-item .sb-num { font-weight: 700; margin-right: 2px; color: var(--muted-light); }
.stat-breakdown .sb-item.sb-active .sb-num { color: var(--primary); }
.stat-card .stat-info { flex: 1; min-width: 0; }
.stat-card .stat-label { font-weight: 700; font-size: 0.95rem; color: var(--ink); }
.stat-card .stat-value { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.stat-card .fa-chevron-right { color: var(--muted-light); }

/* ---------- Dashboard: SM by day (10 day boxes + table) ---------- */
.sm-days-section { padding: 0 20px 28px; }
.sm-days-wrap { display: flex; align-items: center; gap: 6px; }
.sm-days-arrow { flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.sm-days { flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 4px 2px; }
.sm-days::-webkit-scrollbar { display: none; }
.smd-box { flex: 0 0 84px; min-height: 92px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-md); padding: 8px 6px; text-align: center; cursor: pointer; }
.smd-box.today { background: #FFF5D6; border-color: #E8C766; }
.smd-box.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(18,59,109,0.18); }
.smd-day { font-size: 0.68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.smd-date { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; }
.smd-line { font-size: 0.74rem; font-weight: 600; color: var(--ink); white-space: nowrap; }
.smd-line.smd-bad { color: var(--danger); }
.smd-line.smd-wait { color: var(--accent-deep); }
.smd-sub { font-size: 0.66rem; color: var(--muted-light); }
.sm-day-title { font-weight: 700; font-size: 0.9rem; margin: 16px 0 8px; }
.sm-day-table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.sm-day-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 0.82rem; }
.sm-day-table th { text-align: left; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.sm-day-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
.sm-day-table tbody tr:last-child td { border-bottom: none; }
.sm-day-table tbody tr { cursor: pointer; }
.sm-day-table tbody tr.smt-expected { cursor: default; color: var(--muted); }
.sm-day-table .smt-sub { font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.sm-day-empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); text-align: center; color: var(--muted); font-size: 0.85rem; padding: 22px 16px; }

/* ---------- Contract setup: technician chips, QR box, boundary map ---------- */
.map-container { width: 100%; height: 260px; border-radius: var(--radius-md); overflow: hidden; border: 1.5px solid var(--line); margin-bottom: 8px; }
.map-hint { font-size: 0.76rem; color: var(--muted-light); margin-bottom: 6px; }
.map-clear-btn { font-size: 0.78rem; color: var(--primary); background: none; border: none; padding: 0; cursor: pointer; font-weight: 600; margin-bottom: 16px; display: block; }
.tech-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tech-chip {
    display: flex; align-items: center; gap: 6px; padding: 0.5rem 0.85rem; border-radius: 999px;
    border: 1.5px solid var(--line); font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tech-chip.selected { border-color: var(--primary); color: var(--primary); background: rgba(18,59,109,0.06); }
.tech-chip.readonly { cursor: default; border-color: var(--primary); color: var(--primary); background: rgba(18,59,109,0.06); }

.date-row { display: flex; gap: 12px; }
.date-row .ag-field { flex: 1; }

.qr-box { background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-lg); padding: 22px; text-align: center; margin-bottom: 18px; }
.qr-box .qr-canvas-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.qr-box .qr-contract-line { font-weight: 700; margin-bottom: 2px; }
.qr-box .qr-contract-sub { font-size: 0.82rem; color: var(--muted); margin-bottom: 16px; }
.qr-box .key-actions { display: flex; gap: 10px; justify-content: center; }
.qr-box .key-copy-btn {
    display: inline-flex; align-items: center; gap: 6px; background: var(--bg);
    color: var(--primary); border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 0.5rem 1rem;
    font-family: var(--font-body); font-weight: 600; font-size: 0.82rem; cursor: pointer;
}

/* ---------- Onboarding stepper ---------- */
.ag-stepper { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 4px 0 26px; }
.ag-stepper .step-dot {
    width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex-shrink: 0;
}
.ag-stepper .step-line { width: 18px; height: 2px; background: var(--line); flex-shrink: 0; }
.ag-stepper .step-dot.done { background: var(--success); }
.ag-stepper .step-dot.current { background: var(--primary); width: 12px; height: 12px; }
.ag-stepper .step-line.done { background: var(--success); }

/* ---------- Technician key display ---------- */
.key-box {
    background: linear-gradient(135deg, var(--primary), var(--primary-deep));
    border-radius: var(--radius-lg); padding: 24px 20px; text-align: center; margin-bottom: 18px;
}
.key-box .key-label { color: rgba(255,255,255,0.75); font-size: 0.78rem; font-weight: 600; margin-bottom: 8px; }
.key-box .key-value {
    font-family: var(--font-display); font-size: 2.1rem; font-weight: 700; letter-spacing: 3px;
    color: #fff; margin-bottom: 14px;
}
.key-box .key-actions { display: flex; gap: 10px; justify-content: center; }
.key-box .key-copy-btn {
    display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.15);
    color: #fff; border: none; border-radius: var(--radius-sm); padding: 0.5rem 1rem;
    font-family: var(--font-body); font-weight: 600; font-size: 0.82rem; cursor: pointer;
}
.key-copy-btn:active { background: rgba(255,255,255,0.25); }
.key-hint { font-size: 0.82rem; color: var(--muted); text-align: center; margin-bottom: 22px; line-height: 1.5; }

/* ---------- Alert / confirm dialogs (ui-dialog.js) ---------- */
.ui-dialog-overlay {
    position: fixed; inset: 0; z-index: 1000000;
    background: rgba(16,22,47,0.45); backdrop-filter: blur(1px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
    animation: ui-dialog-fade 0.15s ease-out;
}
@keyframes ui-dialog-fade { from { opacity: 0; } to { opacity: 1; } }

.ui-dialog-box {
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(16,22,47,0.25);
    width: 100%; max-width: 340px; padding: 24px 22px 20px;
    text-align: center; animation: ui-dialog-pop 0.16s ease-out;
}
@keyframes ui-dialog-pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.ui-dialog-icon { font-size: 1.9rem; margin-bottom: 10px; display: block; }
.ui-dialog-red .ui-dialog-icon { color: var(--danger); }
.ui-dialog-blue .ui-dialog-icon { color: var(--primary); }
.ui-dialog-green .ui-dialog-icon { color: var(--success); }

.ui-dialog-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; margin-bottom: 8px; }
.ui-dialog-msg { font-size: 0.88rem; color: var(--ink); line-height: 1.5; margin-bottom: 18px; }
.ui-dialog-msg p { margin: 0 0 6px; }
.ui-dialog-msg p:last-child { margin-bottom: 0; }

.ui-dialog-ok { width: 100%; }

.ui-dialog-actions { display: flex; gap: 10px; }
.ui-dialog-actions .ag-btn { flex: 1; }

/* ============================================================
   Desktop layout (opt-in)
   Pages that work on computers add class="wide-ok" to <body>
   (plus "with-side" when they have the admin nav bar, and
   "narrow" for single-column pages like Profile). Below 900px
   nothing here applies - the phone layout stays exactly as is.
   ============================================================ */

/* Text shown only to touch devices / only to mouse users */
.only-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
    .only-touch { display: none; }
    .only-mouse { display: inline; }
}

/* Nav links that only exist in the desktop sidebar */
.ag-footer .ag-tab.side-only { display: none; }

@media (hover: hover) and (pointer: fine) {
    .wide-ok .cm-row:hover,
    .wide-ok .visit-row:hover,
    .wide-ok .contract-row:hover,
    .wide-ok .tech-row:hover,
    .wide-ok .stat-card:hover { border-color: var(--primary-light); box-shadow: 0 4px 14px rgba(18,59,109,0.08); }
    .wide-ok .vc-photo-row img,
    .wide-ok .cm-thumb { cursor: zoom-in; }
    .wide-ok .photo-capture-box:hover { border-color: var(--primary-light); background: rgba(18,59,109,0.03); }
    .wide-ok .cm-filter-row button:not(.active):hover,
    .wide-ok .ag-seg button:not(.active):hover { color: var(--primary); }
    .wide-ok .ag-menu-btn:hover,
    .wide-ok .menu-pop a:hover,
    .wide-ok .action-item:hover { background: var(--bg); }
    .wide-ok .ag-btn-primary:hover, .wide-ok .ag-btn-accent:hover, .wide-ok .fab-pill:hover { filter: brightness(1.12); }
    .wide-ok .ag-btn-outline:hover { background: rgba(18,59,109,0.04); }
    .wide-ok .tech-chip:not(.readonly):hover { border-color: var(--primary-light); }
    .wide-ok .smd-box:hover { border-color: var(--primary-light); }
    .wide-ok .sm-day-table tbody tr:not(.smt-expected):hover td { background: rgba(18,59,109,0.03); }
    .wide-ok .sm-days-arrow:hover { color: var(--primary); border-color: var(--primary-light); }
}

@media (min-width: 900px) {
    .wide-ok {
        --side-w: 220px;
        --wide-max: 1100px;
        /* distance from the screen edge to the content column */
        --wide-gutter: max(16px, calc((100vw - var(--wide-max)) / 2 + 16px));
    }
    .wide-ok.with-side { --wide-gutter: max(24px, calc((100vw - var(--side-w) - var(--wide-max)) / 2 + 16px)); }

    /* Content column, centered. Without a sidebar the header's contents
       line up with the column; with one, the logo sits above the sidebar. */
    .wide-ok .ag-page { max-width: var(--wide-max); margin: 0 auto; }
    .wide-ok:not(.with-side) .ag-header { padding-left: var(--wide-gutter); padding-right: var(--wide-gutter); }
    .wide-ok.with-side .ag-header { padding-left: 24px; padding-right: 16px; }
    .wide-ok .fab-pill { right: var(--wide-gutter); bottom: 24px; }

    /* Bottom nav bar becomes a left sidebar */
    .wide-ok.with-side .ag-footer {
        top: calc(var(--header-h) + var(--safe-top)); bottom: 0; right: auto; width: var(--side-w); height: auto;
        flex-direction: column; gap: 2px; padding: 16px 12px;
        border-top: none; border-right: 1px solid var(--line);
    }
    .wide-ok.with-side.no-hdr .ag-footer { top: 0; }
    .wide-ok.with-side .ag-footer .ag-tab {
        flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
        padding: 11px 14px; border-radius: var(--radius-md); font-size: 0.88rem; color: var(--muted);
    }
    .wide-ok.with-side .ag-footer .ag-tab i { width: 20px; text-align: center; font-size: 1.05rem; }
    .wide-ok.with-side .ag-footer .ag-tab:hover { background: var(--bg); color: var(--ink); }
    .wide-ok.with-side .ag-footer .ag-tab.active { background: rgba(18,59,109,0.08); color: var(--primary); }
    .wide-ok.with-side .ag-footer .ag-tab.side-only { display: flex; }
    .wide-ok.with-side .ag-footer .ag-tab.side-only.side-hidden { display: none; }
    .wide-ok.with-side .ag-page { max-width: none; margin: 0 0 0 var(--side-w); padding-bottom: 32px; }
    .wide-ok.with-side .ag-page > * { max-width: var(--wide-max); margin-left: auto; margin-right: auto; }
    .wide-ok.with-side.narrow .ag-page > * { max-width: 680px; }

    /* Pop-up sheets become centered dialogs */
    .wide-ok .sheet:not(.sheet-full) {
        left: 50%; right: auto; top: 50%; bottom: auto; transform: translate(-50%, -50%);
        width: 560px; max-width: calc(100vw - 48px); max-height: 85vh; overflow-y: auto;
        border-radius: var(--radius-lg); padding: 24px 24px 22px;
        box-shadow: 0 24px 60px rgba(16,22,47,0.25);
    }
    .wide-ok .sheet.sheet-wide:not(.sheet-full) { width: 680px; }
    .wide-ok .sheet-overlay { background: rgba(16,22,47,0.5); }
    .wide-ok .menu-pop { right: 16px; }

    /* Lists: two columns of cards */
    .wide-ok .card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; padding-left: 16px; padding-right: 16px; }
    .wide-ok .card-grid > * { margin: 0 !important; }
    .wide-ok .card-grid > .empty-state { grid-column: 1 / -1; }
    .wide-ok .cm-filter-row { max-width: 520px !important; margin: 6px auto 4px; }
    .wide-ok .cm-filter-row.scroll-tabs { max-width: 680px !important; }
    .wide-ok .cm-filter-row.scroll-tabs button { flex: 1 0 auto; }
    .wide-ok .page-title-row { padding-top: 24px !important; }
    .wide-ok .page-title { font-size: 1.35rem !important; }

    /* Dashboard */
    .wide-ok .dash-welcome { padding: 26px 16px 4px; }
    .wide-ok .dash-welcome .dash-company { font-size: 1.5rem; }
    .wide-ok .stat-card-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding: 18px 16px 20px; }
    .wide-ok .stat-card { padding: 20px 18px; }
    .wide-ok .stat-breakdown { flex-wrap: wrap; row-gap: 2px; }
    .wide-ok .sm-days-section { padding: 0 16px 32px; }
    .wide-ok .smd-box { flex: 1 0 84px; }

    /* Public contract page */
    .wide-ok .pc-hero { padding: 32px 20px 22px; }
    .wide-ok .pc-hero .pc-client { font-size: 1.5rem; }
    .wide-ok .pc-hero .pc-sub { font-size: 0.9rem; }
    .wide-ok .pc-toolbar { max-width: 520px; margin-left: auto !important; margin-right: auto !important; }
    .wide-ok .pc-toolbar .ag-menu-btn, .wide-ok .page-title-row .ag-menu-btn { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface); color: var(--muted); cursor: pointer; }
    .wide-ok .visit-card { padding: 18px; }
    .wide-ok .visit-card .vc-photo-row { gap: 6px; }
    .wide-ok .visit-card .vc-photo-row img { width: 90px; height: 90px; border-radius: 10px; }

    /* Sign-in and setup pages: the form sits on a white card */
    .wide-ok .auth-shell, .wide-ok .setup-shell { padding-top: 6vh; }
    .wide-ok .auth-card, .wide-ok .setup-card {
        max-width: 440px !important; background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius-lg); padding: 28px 30px; box-shadow: 0 12px 34px rgba(16,22,47,0.07);
    }
}
