/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --green: #1e8e3e;
    --green-light: #e6f4ea;
    --orange: #e37400;
    --orange-light: #fef7e0;
    --red: #d93025;
    --red-light: #fce8e6;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f4;
    --gray-200: #e8eaed;
    --gray-300: #dadce0;
    --gray-500: #9aa0a6;
    --gray-700: #5f6368;
    --gray-900: #202124;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 56px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--gray-900);
    line-height: 1.5;
    padding-top: calc(var(--nav-height) + var(--safe-top));
    padding-bottom: var(--safe-bottom);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Navbar ──────────────────────────────────────────── */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 16px;
    padding-right: 16px;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
}

.nav-logo { width: 32px; height: 32px; border-radius: 6px; }

.nav-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-user {
    font-size: 0.85rem;
    opacity: 0.9;
    background: rgba(255,255,255,0.15);
    padding: 4px 10px;
    border-radius: 20px;
}

.nav-btn {
    color: white;
    text-decoration: none;
    font-size: 1.2rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.nav-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Container ───────────────────────────────────────── */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 8px 12px 80px;
}

/* ── Flash Messages ──────────────────────────────────── */
.flash-messages { margin-bottom: 8px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 8px;
    transition: opacity 0.3s, transform 0.3s;
}
.flash-error { background: var(--red-light); color: var(--red); }
.flash-success { background: var(--green-light); color: var(--green); }
.flash-info { background: var(--primary-light); color: var(--primary); }

/* ── Login ───────────────────────────────────────────── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-height));
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px 30px;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-icon {
    width: 72px;
    height: 72px;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

.login-subtitle {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
}

input[type="text"],
input[type="password"],
select {
    padding: 12px 14px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    background: white;
    -webkit-appearance: none;
}

input:focus, select:focus { border-color: var(--primary); }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-full { width: 100%; }

.btn-outline {
    background: transparent;
    border: 2px solid var(--gray-300);
    color: var(--gray-700);
    padding: 8px 14px;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #c5221f; }

/* ── Stats Bar ───────────────────────────────────────── */
.stats-bar {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
    margin-bottom: 8px;
}

.stat { text-align: center; }
.stat-num { font-size: 1.5rem; font-weight: 800; display: block; color: var(--primary); }
.stat-green { color: var(--green); }
.stat-orange { color: var(--orange); }
.stat-label { font-size: 0.75rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Toggle Filters Button ───────────────────────────── */
.toggle-filters-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: var(--card-bg);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-700);
    cursor: pointer;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.toggle-filters-btn:hover { border-color: var(--primary); color: var(--primary); }

.filter-count {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px;
}

.hidden { display: none !important; }

/* ── Filter Bar ──────────────────────────────────────── */
.filter-bar {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px;
    margin-bottom: 8px;
    display: none;
}

.filter-bar.open { display: block; }

.filter-row { margin-bottom: 8px; }
.filter-row:last-child { margin-bottom: 0; }

.filter-selects {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.search-input {
    width: 100%;
    padding: 10px 14px !important;
    font-size: 0.95rem !important;
}

.filter-select {
    width: 100%;
    padding: 8px 10px !important;
    font-size: 0.82rem !important;
    background: var(--gray-50);
    cursor: pointer;
}

/* ── Job Cards ───────────────────────────────────────── */
.jobs-list { display: flex; flex-direction: column; gap: 8px; }

.job-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    transition: all 0.2s;
    border-left: 4px solid transparent;
    position: relative;
}

.job-card.is-hold { border-left-color: var(--orange); opacity: 0.7; }
.job-card.is-past-due { border-left-color: var(--red); }
.job-card.is-completed {
    border-left-color: var(--green);
    background: var(--green-light);
}

.complete-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid var(--gray-300);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.complete-btn:hover { border-color: var(--green); }
.complete-btn:active { transform: scale(0.9); }

.complete-btn.checked {
    background: var(--green);
    border-color: var(--green);
    color: white;
}

.job-info { flex: 1; min-width: 0; }

.job-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray-900);
    margin-bottom: 2px;
}

.job-address {
    font-size: 0.85rem;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.job-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-city { background: var(--primary-light); color: var(--primary); }
.badge-freq { background: #f3e8fd; color: #7b1fa2; }
.badge-section { background: var(--orange-light); color: var(--orange); }
.badge-service { background: var(--gray-100); color: var(--gray-700); font-size: 0.65rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.badge-day { background: #e0f2f1; color: #00695c; }
.badge-hold { background: var(--orange-light); color: var(--orange); }
.badge-past-due { background: var(--red-light); color: var(--red); }
.badge-admin { background: var(--primary-light); color: var(--primary); }

.job-completion {
    font-size: 0.8rem;
    color: var(--green);
    margin-top: 4px;
    font-weight: 500;
}

.job-service-detail {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-top: 2px;
    line-height: 1.3;
}

/* ── Loading ─────────────────────────────────────────── */
.loading-spinner {
    text-align: center;
    padding: 40px;
    color: var(--gray-500);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
    font-size: 0.95rem;
}

/* ── Admin ───────────────────────────────────────────── */
.admin-page { padding-bottom: 40px; }

.page-title {
    font-size: 1.3rem;
    margin-bottom: 16px;
    color: var(--gray-900);
}

.admin-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.admin-card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--gray-900);
    border-bottom: 2px solid var(--gray-100);
    padding-bottom: 8px;
}

.admin-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.admin-form .form-group { margin-bottom: 10px; }

.user-list { display: flex; flex-direction: column; gap: 10px; }

.user-item {
    padding: 10px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.user-name { font-weight: 700; }
.user-date { font-size: 0.75rem; color: var(--gray-500); }

.user-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.inline-form { display: flex; gap: 4px; align-items: center; }
.input-sm { padding: 6px 8px !important; font-size: 0.8rem !important; width: 100px; }

.completion-list { display: flex; flex-direction: column; gap: 6px; }

.completion-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: var(--green-light);
    border-radius: var(--radius-sm);
    gap: 8px;
}

.completion-name { font-weight: 600; font-size: 0.9rem; }
.completion-address { font-size: 0.78rem; color: var(--gray-700); display: block; }
.completion-meta { text-align: right; flex-shrink: 0; }
.completion-user { font-size: 0.8rem; font-weight: 600; color: var(--primary); display: block; }
.completion-time { font-size: 0.75rem; color: var(--gray-500); }

/* ── Note Modal ──────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.2s;
}

.modal-overlay.visible { opacity: 1; }

.modal {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.2s;
}

.modal-overlay.visible .modal { transform: scale(1); }

.modal h3 { margin-bottom: 12px; font-size: 1.1rem; }

.modal textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    resize: vertical;
    min-height: 80px;
    outline: none;
    font-family: inherit;
}

.modal textarea:focus { border-color: var(--primary); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* ── Animations ──────────────────────────────────────── */
.job-card {
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 380px) {
    .container { padding: 6px 8px 80px; }
    .job-card { padding: 10px; }
    .filter-selects { grid-template-columns: 1fr; }
    .admin-form .form-row { grid-template-columns: 1fr; }
}

@media (min-width: 601px) {
    .container { padding: 16px 20px 80px; }
}

/* ── PWA Install Prompt ──────────────────────────────── */
.install-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    max-width: 560px;
    margin: 0 auto;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-lg);
    z-index: 1500;
    gap: 12px;
}

.install-banner p { font-size: 0.9rem; font-weight: 500; }
.install-banner .btn { background: white; color: var(--primary); padding: 8px 16px; font-size: 0.85rem; }
.install-banner .dismiss { background: transparent; color: rgba(255,255,255,0.8); border: none; cursor: pointer; font-size: 1.2rem; }

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
