/* Mystery Shopping PWA – Global Styles */
:root {
    --color-bg: #f9fafb;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-secondary: #6b7280;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-success: #059669;
    --color-warning: #d97706;
    --color-badge-email: #2563eb;
    --color-badge-call: #7c3aed;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    min-height: 100dvh;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}
.header-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
    padding: 6px;
    border-radius: var(--radius-sm);
    font-size: 16px;
}
.header-btn:hover { background: var(--color-bg); }
.header-btn--logout { color: var(--color-text-secondary); font-size: 18px; padding: 6px 8px; }

.btn-back {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: var(--color-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 0;
}
.btn-back:hover { opacity: 0.8; }

/* Content */
.content { flex: 1; padding: 20px; }

/* Cards */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.card:hover {
    box-shadow: var(--shadow);
    border-color: #d1d5db;
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}
.card-subtitle {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
}
.card-badges {
    display: flex;
    gap: 8px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 99px;
    background: var(--color-bg);
    color: var(--color-text-secondary);
}
.badge--email { background: #eff6ff; color: var(--color-badge-email); }
.badge--call { background: #f5f3ff; color: var(--color-badge-call); }
.badge--success { background: #ecfdf5; color: var(--color-success); }
.badge--warning { background: #fffbeb; color: var(--color-warning); }
.badge--danger { background: #fef2f2; color: var(--color-danger); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
    line-height: 1;
}
.btn--primary {
    background: var(--color-primary);
    color: white;
}
.btn--primary:hover { background: var(--color-primary-hover); }
.btn--danger {
    background: var(--color-danger);
    color: white;
}
.btn--danger:hover { background: var(--color-danger-hover); }
.btn--ghost {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}
.btn--ghost:hover { background: var(--color-bg); }
.btn-link { background: none; border: none; color: var(--color-primary); font-size: 14px; cursor: pointer; padding: 4px 8px; }
.btn-link:hover { text-decoration: underline; }
.btn-link:disabled { color: var(--color-text-secondary); cursor: default; text-decoration: none; }

/* Segmented Control (Tab Toggle) */
.segmented { display: inline-flex; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 6px 16px; font-size: 13px; font-weight: 500; border: none; background: var(--color-surface); color: var(--color-text-secondary); cursor: pointer; transition: background .15s, color .15s; }
.segmented button + button { border-left: 1px solid var(--color-border); }
.segmented button.active { background: var(--color-primary); color: #fff; }

/* Toast notification */
.toast { position: fixed; bottom: 12px; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 9999; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.15); display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; animation: toastIn .25s ease-out; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 14px; font-weight: 600; color: var(--color-text); }
.toast-text { font-size: 13px; color: var(--color-text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-close { background: none; border: none; font-size: 20px; color: var(--color-text-secondary); cursor: pointer; padding: 0 4px; line-height: 1; }
@keyframes toastIn { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* File Viewer (fullscreen overlay) */
.file-viewer { position: fixed; inset: 0; z-index: 10000; background: var(--color-bg); display: flex; flex-direction: column; }
.file-viewer-header { display: flex; align-items: center; gap: 12px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--color-surface); border-bottom: 1px solid var(--color-border); min-height: 44px; }
.file-viewer-close { background: none; border: none; font-size: 28px; line-height: 1; color: var(--color-text); cursor: pointer; padding: 0 4px; }
.file-viewer-title { flex: 1; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-viewer-share { background: none; border: none; font-size: 22px; color: var(--color-text); cursor: pointer; padding: 0 4px; }
.file-viewer-content { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 0; }
.file-viewer-content iframe { width: 100%; height: 100%; }
.file-viewer-content img { max-width: 100%; max-height: 100%; object-fit: contain; }
.btn--full { width: 100%; }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-textarea { resize: vertical; min-height: 100px; }

/* PIN input */
.pin-input {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.pin-input input {
    width: 44px;
    height: 52px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
}
.pin-input input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Login screen */
.login-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 40px 20px;
}
.login-logo {
    width: 64px;
    height: 64px;
    background: var(--color-primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}
.login-logo svg { width: 32px; height: 32px; }
.login-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}
.login-subtitle {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 32px;
}
.login-form { width: 100%; max-width: 320px; }

/* Error/success messages */
.msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
}
.msg--error { background: #fef2f2; color: var(--color-danger); border: 1px solid #fecaca; }
.msg--success { background: #ecfdf5; color: var(--color-success); border: 1px solid #a7f3d0; }

/* List items (emails, calls) */
.list-item {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s;
}
.list-item:hover { background: var(--color-bg); }
.list-item--unread { background: #f0f7ff; }
.list-item--unread:hover { background: #e8f2ff; }
.list-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}
.list-icon--email { background: #eff6ff; color: var(--color-badge-email); }
.list-icon--call-in { background: #ecfdf5; color: var(--color-success); }
.list-icon--call-out { background: #f5f3ff; color: var(--color-badge-call); }
.list-icon--call-missed { background: #fef2f2; color: var(--color-danger); }
.list-body { flex: 1; min-width: 0; }
.list-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-desc {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-meta {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}
.unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
    flex-shrink: 0;
    align-self: center;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}
.tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.tab--active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}
.tab:hover { color: var(--color-text); }

/* Table (admin) */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
th {
    font-weight: 600;
    font-size: 12px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--color-bg);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 24px 20px;
    padding-bottom: calc(24px + var(--safe-bottom));
}
.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.modal-actions .btn { flex: 1; }

/* Empty state */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-secondary);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading overlay */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
.loading .spinner {
    border-color: rgba(37, 99, 235, 0.2);
    border-top-color: var(--color-primary);
}

/* Utility */
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--color-text-secondary); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* Responsive – desktop stretch */
@media (min-width: 481px) {
    #app {
        border-left: 1px solid var(--color-border);
        border-right: 1px solid var(--color-border);
    }
}
