* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #e9e9ea;
    --card-bg: #ffffff;
    --border: #e4e4e6;
    --text: #17181a;
    --text-muted: #8b8d94;
    --text-faint: #b4b6bc;
    --accent: #17181a;
    --accent-text: #ffffff;
    --green: #1fa26e;
    --green-bg: #e7f7f0;
    --orange: #c07a17;
    --orange-bg: #fdf3e3;
    --red: #b8433a;
    --red-bg: #fbeceb;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(20, 20, 25, 0.04), 0 1px 10px rgba(20, 20, 25, 0.04);
}

html, body {
    height: 100%;
}

body.has-bottom-nav { padding-bottom: 60px; }
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
    z-index: 50;
    max-width: 480px;
    margin: 0 auto;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-faint);
}
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--text); }
.bottom-nav-icon-wrap { position: relative; display: inline-flex; }
.bottom-nav-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -5px;
    right: -8px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    line-height: 1;
}

/* Payments / history screens */
.summary-row {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}
.summary-card {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 12px 14px;
}
.summary-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-faint);
    margin-bottom: 4px;
}
.summary-value { font-size: 16px; font-weight: 700; }
.summary-value.debt { color: var(--orange); }
.summary-value.unpaid { color: var(--red); }

.tx-row, .history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.tx-row:last-child, .history-row:last-child { border-bottom: none; padding-bottom: 0; }
/* Each row as its own standalone card (objects.html, object-history.html) —
   no divider/padding needed since .card already frames it on its own. */
.card > .tx-row, .card > .history-row { padding: 0; border-bottom: none; }
.row-title { font-size: 14.5px; font-weight: 600; }
.row-weekday { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.row-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.row-hours { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.tx-confirm-btn {
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 600;
    flex-shrink: 0;
    cursor: pointer;
}
.tx-confirm-btn:disabled { opacity: 0.5; }
.tx-confirm-btn.danger { background: var(--red-bg); color: var(--red); }
.tx-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.badge-sm {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
}
.badge-sm.paid { background: var(--green-bg); color: var(--green); }
.badge-sm.unpaid { background: var(--red-bg); color: var(--red); }

.row-comments-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #eeeeef;
    border-radius: 999px;
    padding: 3px 8px 3px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    border: none;
    margin-top: 6px;
}
.row-comments-btn svg { width: 13px; height: 13px; }
.row-comments-btn.unread { background: var(--red-bg); color: var(--red); font-weight: 700; }
.row-comments-btn.add { padding: 5px; background: transparent; border: 1px dashed var(--border); color: var(--text-faint); }

.row-media-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #eeeeef;
    border-radius: 999px;
    padding: 3px 8px 3px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    border: none;
    margin-top: 6px;
}
.row-media-btn svg { width: 13px; height: 13px; }

/* Photo/video viewer opens as a CENTERED modal (like the admin panel),
   not the bottom sheet the rest of this app's overlays use (result,
   payment request, city map, install steps) — those stay bottom sheets
   on purpose. Chat goes further still — fullscreen, see below. ID
   selectors here deliberately override the shared .overlay's
   align-items: flex-end without touching that base rule for every
   other overlay. */
#commentsOverlay, #mediaOverlay { align-items: center; }
#mediaOverlay { padding: 20px; }
.overlay-sheet.media-sheet {
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}

/* Photo/video report viewer — one item per row at full width with its
   natural aspect ratio, matching the admin panel's session media modal
   (not a cropped thumbnail grid). */
.overlay-sheet.media-sheet { max-height: 85vh; overflow-y: auto; }
.media-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 14px 0;
}
.media-grid img, .media-grid video {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    background: #f0f0f2;
    display: block;
}

/* Session chat (comments) — bubble-style thread between the employee
   and any admin (panel), one thread per session. Opens fullscreen
   (same reasoning as the admin panel's mirror of this) — #commentsOverlay
   gets no padding so the sheet can reach every edge, unlike the
   centered/padded photo-video viewer above. */
#commentsOverlay { padding: 0; }
.overlay-sheet.chat-sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    overflow: hidden;
    /* Edge-to-edge now, so — unlike the base .overlay-sheet's flat 24px/
       28px — the title and close button need to clear a real notch/
       gesture bar (viewport-fit=cover is set, see <meta viewport>). */
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    margin-bottom: 12px;
}
.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-faint);
    font-size: 13px;
}
.chat-bubble {
    max-width: 82%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.4;
}
.chat-bubble .chat-text { white-space: pre-wrap; word-break: break-word; }
.chat-bubble .chat-author { font-size: 11px; font-weight: 700; margin-bottom: 2px; opacity: 0.7; }
.chat-bubble .chat-time { font-size: 10px; opacity: 0.55; margin-top: 3px; text-align: right; }
.chat-bubble.own {
    align-self: flex-end;
    background: var(--accent);
    color: var(--accent-text);
    border-bottom-right-radius: 4px;
}
.chat-bubble.other {
    align-self: flex-start;
    background: #eeeeef;
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-input-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}
.chat-input-row textarea {
    width: 100%;
    box-sizing: border-box;
    resize: none;
    max-height: 90px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    background: #fafafb;
}
.chat-input-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.chat-send-btn {
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.5; }
.chat-audio { max-width: 220px; height: 36px; }
.chat-voice-btn {
    background: #eeeeef;
    color: var(--text-muted);
    border: none;
    border-radius: 999px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-voice-btn svg { width: 18px; height: 18px; }
.chat-voice-btn.recording { background: var(--red); color: #fff; }
.chat-voice-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: var(--radius-sm);
    background: var(--red-bg);
    color: var(--red);
    font-size: 13px;
}
.chat-voice-indicator.show { display: flex; }
.chat-voice-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--red);
    animation: chat-voice-pulse 1s ease-in-out infinite;
}
@keyframes chat-voice-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
#voiceRecordTime { font-variant-numeric: tabular-nums; font-weight: 600; }
.chat-voice-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--red);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

.page {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px 16px 24px;
}

/* Top bar (home.html) */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.topbar-title {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.employee-avatar {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    object-fit: cover;
}
.profile-summary { margin: -6px 0 16px; }
.profile-greeting { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.profile-meta { font-size: 12.5px; color: var(--text-muted); }

.topbar-badge {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.icon-btn:disabled { cursor: default; }
.icon-btn.loading svg { animation: icon-btn-pulse 0.9s ease-in-out infinite; }
@keyframes icon-btn-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.lang-switch {
    display: inline-flex;
    background: #f0f0f2;
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}
.lang-switch button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.lang-switch button.active {
    background: var(--accent);
    color: var(--accent-text);
}

/* Offline / sync status strip */
.status-strip {
    display: none;
    align-items: center;
    gap: 8px;
    background: var(--orange-bg);
    color: var(--orange);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 12.5px;
    font-weight: 600;
    margin-bottom: 12px;
}
.status-strip.show { display: flex; }
.status-strip .dot {
    width: 7px; height: 7px; border-radius: 999px; background: var(--orange); flex-shrink: 0;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 18px;
    margin-bottom: 14px;
}
.card h1 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
}
.card .sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Login page */
.login-body { display: flex; align-items: center; min-height: 100vh; }
.login-card { width: 100%; }
.login-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
}
.text-link {
    display: block;
    text-align: center;
    margin-top: 14px;
    font-size: 13.5px;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
}
.text-link b { color: var(--text); }

.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 12px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: #fff;
    color: var(--text);
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-primary:not(:disabled):active { opacity: 0.85; }
.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-secondary.unread { background: var(--red-bg); color: var(--red); border-color: var(--red); }

.filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    padding: 2px 0 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}
.filter-toggle-label { display: flex; align-items: center; gap: 7px; }
.filter-toggle-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--accent); }
.filter-toggle-chevron { width: 14px; height: 14px; color: var(--text-muted); transition: transform 0.15s ease; }
.filter-toggle-chevron.open { transform: rotate(180deg); }
.filter-panel { padding-bottom: 4px; }
.filter-row { display: flex; gap: 8px; }
.filter-row .form-group { flex: 1; margin-bottom: 0; }
.filter-actions { display: flex; gap: 8px; margin-top: 12px; }
.filter-actions .btn { padding: 10px 14px; font-size: 13.5px; }
.load-more-row { margin: 4px 0 14px; }
.load-more-row .btn { padding: 11px 14px; font-size: 14px; }

.modal-error {
    display: none;
    margin-bottom: 12px;
    background: var(--red-bg);
    border: 1px solid #f6c6c6;
    color: var(--red);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12.5px;
}
.modal-error.show { display: block; }

.modal-success {
    display: none;
    margin-bottom: 12px;
    background: var(--green-bg);
    border: 1px solid #b9e8c9;
    color: var(--green);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12.5px;
}
.modal-success.show { display: block; }

/* Home: idle vs active states */
.idle-state, .active-state, .loading-state {
    display: none;
}
.idle-state.show, .active-state.show, .loading-state.show {
    display: block;
}
.loading-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 13px;
}

.session-project {
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 4px;
}
.session-time {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 18px;
}

.photo-hint {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: var(--orange-bg);
    color: var(--orange);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12.5px;
    margin-bottom: 14px;
}

.media-count {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.media-manage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
.media-manage-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #eeeeef;
}
.media-manage-item img, .media-manage-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.media-manage-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.media-manage-delete:hover { background: var(--red); }
.media-manage-delete:disabled { opacity: 0.5; cursor: default; }

.action-row { margin-bottom: 10px; }
.action-row:last-child { margin-bottom: 0; }

input[type="file"] { display: none; }

/* End-of-session result overlay */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 25, 0.45);
    align-items: flex-end;
    justify-content: center;
    /* Must beat .bottom-nav (also 50) — with equal z-index the element
       later in the DOM wins ties regardless of stated value, and
       #bottomNavHolder sits at the end of <body>, so it was rendering
       on top of every overlay's bottom button (result modal, chat,
       media viewer, payment request). */
    z-index: 60;
}
.overlay.show { display: flex; }
.overlay-sheet {
    background: var(--card-bg);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 480px;
    padding: 24px 20px 28px;
    max-height: 90vh;
    overflow-y: auto;
}
.overlay-sheet h2 {
    font-size: 18px;
    margin-bottom: 14px;
}
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.result-row:last-of-type { border-bottom: none; }
.result-row .label { color: var(--text-muted); }
.result-row .value { font-weight: 600; }

/* Install banner (persistent, all pages, no dismiss) — position:fixed
   (not sticky/in-flow) deliberately: some pages' body is itself a flex
   container with no flex-direction set (.login-body), so an in-flow
   sibling would end up in a row next to the page content instead of
   above it. Fixed removes it from that layout entirely — same reasoning
   as .bottom-nav below, compensated the same way via a body padding
   class rather than flow. z-index kept BELOW .overlay/.bottom-nav (50)
   so a fullscreen modal still visually covers the banner while open. */
body.has-install-banner { padding-top: 54px; }
.install-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--accent);
    color: var(--accent-text);
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    font-size: 12.5px;
}
.install-banner-text { flex: 1; }
.install-banner-btn {
    background: var(--accent-text);
    color: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.install-step { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.install-step:last-of-type { border-bottom: none; }
.install-step-num {
    width: 24px; height: 24px; border-radius: 50%; background: var(--accent);
    color: var(--accent-text); display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.install-step-text { font-size: 13.5px; color: var(--text); }

.select-project-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.project-option {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 14.5px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.project-option.selected {
    border-color: var(--accent);
    background: #f5f5f6;
}
.project-option .flag {
    font-size: 11px;
    color: var(--orange);
    font-weight: 600;
}

.empty-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 20px 0;
}

/* Objects page (map modal) + Object history page (media gallery) */
.map-frame {
    width: 100%;
    aspect-ratio: 4 / 3;
    border: none;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    background: #eee;
}
.media-gallery {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-top: 8px;
    padding-bottom: 2px;
}
.media-thumb {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: #e4e4e6;
    cursor: pointer;
    border: none;
    padding: 0;
    position: relative;
    display: block;
}
.media-thumb-video {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: #55565c;
}
.media-thumb-video svg { width: 18px; height: 18px; }
#lightboxOverlay img, #lightboxOverlay video {
    width: 100%;
    border-radius: 12px;
    max-height: 70vh;
    object-fit: contain;
    background: #000;
    display: block;
}
