/* ============================================================
   pwa-app.css  —  SafeHouse Tech PWA
   Mobile-first layout system.
   Depends on: pwa-theme.css (loaded first)
   ============================================================ */

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

html, body {
    height: 100%;
    font-family: 'DM Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: var(--font-base);
    color: var(--text-primary);
    background: var(--surface-secondary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── App shell ──────────────────────────────────────────────────── */
.pwa-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;          /* dynamic viewport — accounts for mobile browser chrome */
    overflow: hidden;
    position: relative;
}

/* ── Top header ─────────────────────────────────────────────────── */
.pwa-header {
    height: var(--pwa-header-height);
    background: #1e293b;     /* always dark — brand element matching main app global bar */
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.pwa-header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.pwa-header-wordmark {
    font-size: var(--font-sm);
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}

.pwa-header-module {
    font-size: var(--font-xs);
    color: var(--accent-mid);
    font-weight: 500;
    margin-top: 1px;
}

.pwa-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pwa-icon-btn {
    width: var(--touch-min);
    height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.7);
    border-radius: var(--radius-md);
    transition: background var(--trans-fast);
    position: relative;
}

.pwa-icon-btn:hover, .pwa-icon-btn:active { background: rgba(255,255,255,0.1); }
.pwa-icon-btn svg { width: 20px; height: 20px; }

.pwa-notif-dot {
    position: absolute;
    top: 8px; right: 8px;
    width: 7px; height: 7px;
    background: #E24B4A;
    border-radius: 50%;
    border: 1.5px solid #1e293b;
}

.pwa-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

/* ── Page content area ──────────────────────────────────────────── */
.pwa-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: var(--pwa-content-pad);
    padding-bottom: calc(var(--pwa-bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
}

/* ── Bottom navigation ──────────────────────────────────────────── */
.pwa-bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--pwa-bottom-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 0.5px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 200;
}

.pwa-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-tertiary);
    font-size: 10px;
    font-weight: 500;
    transition: color var(--trans-fast);
    min-height: var(--touch-min);
    position: relative;
    cursor: pointer;
}

.pwa-nav-item svg { width: 22px; height: 22px; }

.pwa-nav-item.active {
    color: var(--accent);
}

.pwa-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 32px; height: 2px;
    background: var(--accent);
    border-radius: 0 0 2px 2px;
}

.pwa-nav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
    min-width: 16px;
    height: 16px;
    background: var(--color-danger);
    color: #fff;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 1.5px solid var(--surface);
}

/* ── Page header ────────────────────────────────────────────────── */
.pwa-page-hdr {
    margin-bottom: 16px;
}

.pwa-page-title {
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.pwa-page-sub {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-top: 3px;
}

/* ── Section label ──────────────────────────────────────────────── */
.pwa-section-label {
    font-size: var(--font-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    margin-bottom: 8px;
    margin-top: 20px;
}

.pwa-section-label:first-child { margin-top: 0; }

/* ── Card ───────────────────────────────────────────────────────── */
.pwa-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 10px;
}

.pwa-card-body { padding: 14px; }

.pwa-card-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.pwa-card-tap {
    /* full-card tap target */
    display: block;
    cursor: pointer;
    transition: background var(--trans-fast);
}

.pwa-card-tap:active { background: var(--surface-secondary); }

/* ── KPI strip ──────────────────────────────────────────────────── */
.pwa-kpi-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.pwa-kpi {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 10px;
    text-align: center;
}

.pwa-kpi-val {
    font-size: var(--font-2xl);
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.pwa-kpi-val.accent { color: var(--accent); }
.pwa-kpi-val.danger { color: var(--color-danger); }
.pwa-kpi-val.success { color: var(--color-success); }

.pwa-kpi-label {
    font-size: var(--font-xs);
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

/* ── Status badge ───────────────────────────────────────────────── */
.pwa-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: var(--font-xs);
    font-weight: 600;
    white-space: nowrap;
}

.pwa-badge-open        { background: var(--status-open-bg);        color: var(--status-open-text); }
.pwa-badge-inprogress  { background: var(--status-inprogress-bg);  color: var(--status-inprogress-text); }
.pwa-badge-completed   { background: var(--status-completed-bg);   color: var(--status-completed-text); }
.pwa-badge-overdue     { background: var(--status-overdue-bg);     color: var(--status-overdue-text); }
.pwa-badge-pending     { background: var(--status-pending-bg);     color: var(--status-pending-text); }

/* ── Priority dot ───────────────────────────────────────────────── */
.pwa-priority {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--font-xs);
    font-weight: 600;
}

.pwa-priority::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pwa-priority-critical::before { background: #7C1F1F; }
.pwa-priority-high::before     { background: var(--color-danger); }
.pwa-priority-medium::before   { background: var(--accent-mid); }
.pwa-priority-low::before      { background: var(--color-success); }

.pwa-priority-critical { color: #7C1F1F; }
.pwa-priority-high     { color: var(--color-danger); }
.pwa-priority-medium   { color: var(--accent); }
.pwa-priority-low      { color: var(--color-success); }

/* ── List item (job card style) ─────────────────────────────────── */
.pwa-list-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border-bottom: 0.5px solid var(--border);
    cursor: pointer;
    transition: background var(--trans-fast);
    background: var(--surface);
}

.pwa-list-item:last-child { border-bottom: none; }
.pwa-list-item:active     { background: var(--surface-secondary); }

.pwa-list-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    background: var(--accent-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent);
}

.pwa-list-icon svg { width: 18px; height: 18px; }

.pwa-list-body { flex: 1; min-width: 0; }

.pwa-list-title {
    font-size: var(--font-base);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-list-meta {
    font-size: var(--font-xs);
    color: var(--text-secondary);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.pwa-list-chevron {
    color: var(--gray-400);
    flex-shrink: 0;
    align-self: center;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.pwa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--touch-min);
    padding: 0 18px;
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    font-weight: 600;
    transition: background var(--trans-fast), opacity var(--trans-fast);
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

.pwa-btn:active { opacity: 0.8; }
.pwa-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pwa-btn-primary  { background: var(--accent);     color: #fff; }
.pwa-btn-primary:hover  { background: var(--accent-hover); }

.pwa-btn-secondary { background: var(--surface-tertiary); color: var(--text-primary); border: 0.5px solid var(--border-mid); }
.pwa-btn-secondary:hover { background: var(--gray-200); }

.pwa-btn-danger   { background: var(--color-danger-bg);  color: var(--color-danger); border: 0.5px solid var(--color-danger-border); }

.pwa-btn-full     { width: 100%; }

.pwa-btn-sm {
    height: 34px;
    padding: 0 12px;
    font-size: var(--font-xs);
}

/* ── Form elements ──────────────────────────────────────────────── */
.pwa-form-group { margin-bottom: 14px; }

.pwa-label {
    display: block;
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.pwa-input,
.pwa-select,
.pwa-textarea {
    width: 100%;
    height: var(--touch-min);
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    font-size: var(--font-base);
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--trans-fast);
    -webkit-appearance: none;
}

.pwa-textarea {
    height: auto;
    min-height: 100px;
    padding: 12px;
    resize: vertical;
    line-height: 1.5;
}

.pwa-input:focus, .pwa-select:focus, .pwa-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.pwa-input::placeholder, .pwa-textarea::placeholder { color: var(--text-tertiary); }

.pwa-input-error { border-color: var(--color-danger) !important; }
.pwa-field-error { font-size: var(--font-xs); color: var(--color-danger); margin-top: 4px; }

/* ── Search bar ─────────────────────────────────────────────────── */
.pwa-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-lg);
    padding: 0 12px;
    height: 42px;
    margin-bottom: 14px;
}

.pwa-search svg { color: var(--text-tertiary); flex-shrink: 0; width: 16px; height: 16px; }

.pwa-search input {
    flex: 1;
    border: none;
    background: none;
    font-size: var(--font-base);
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
}

.pwa-search input::placeholder { color: var(--text-tertiary); }

/* ── Filter chips ───────────────────────────────────────────────── */
.pwa-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 14px;
    scrollbar-width: none;
}

.pwa-chips::-webkit-scrollbar { display: none; }

.pwa-chip {
    flex-shrink: 0;
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    font-size: var(--font-xs);
    font-weight: 600;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--trans-fast);
    white-space: nowrap;
}

.pwa-chip.active {
    background: var(--accent-bg);
    border-color: var(--accent-mid);
    color: var(--accent-dark);
}

/* ── Empty state ────────────────────────────────────────────────── */
.pwa-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    gap: 10px;
}

.pwa-empty-icon { color: var(--gray-300); }
.pwa-empty-icon svg { width: 48px; height: 48px; }

.pwa-empty-title {
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--text-secondary);
}

.pwa-empty-sub {
    font-size: var(--font-sm);
    color: var(--text-tertiary);
}

/* ── Loading skeleton ───────────────────────────────────────────── */
.pwa-skeleton {
    background: linear-gradient(90deg,
        var(--surface-tertiary) 25%,
        var(--surface-secondary) 50%,
        var(--surface-tertiary) 75%);
    background-size: 200% 100%;
    animation: pwa-shimmer 1.4s infinite;
    border-radius: var(--radius-md);
}

@keyframes pwa-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Toast / inline alert ───────────────────────────────────────── */
.pwa-alert {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    font-weight: 500;
    margin-bottom: 12px;
}

.pwa-alert-error   { background: var(--color-danger-bg);  color: var(--color-danger);  border: 1px solid var(--color-danger-border); }
.pwa-alert-success { background: var(--color-success-bg); color: var(--color-success); }
.pwa-alert-warn    { background: var(--color-warn-bg);    color: var(--color-warn); }
.pwa-alert-info    { background: var(--color-info-bg);    color: var(--color-info); }

/* ── Divider ────────────────────────────────────────────────────── */
.pwa-divider {
    height: 0.5px;
    background: var(--border);
    margin: 16px 0;
}

/* ── Offline banner ─────────────────────────────────────────────── */
.pwa-offline-banner {
    background: var(--color-warn-bg);
    color: var(--color-warn);
    font-size: var(--font-xs);
    font-weight: 600;
    text-align: center;
    padding: 6px 16px;
    display: none;
}

.pwa-offline-banner.visible { display: block; }

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
