/* ============================================
   PIXFIXER AI - UNIVERSAL DESIGN SYSTEM
   Mobile-First Foundation
   ============================================ */

/* ===========================================
   1. DESIGN TOKENS
   =========================================== */
:root {
    /* Core Colors */
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-darker: #047857;
    --primary-light: rgba(16, 185, 129, 0.1);
    --primary-border: rgba(16, 185, 129, 0.3);
    
    /* Semantic Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    /* Dark Theme Backgrounds */
    --bg-primary: #1e293b;
    --bg-secondary: #0f172a;
    --bg-tertiary: #334155;
    
    /* Text Colors */
    --text-primary: #e2e8f0;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-muted: #64748b;
    
    /* Borders */
    --border-primary: #334155;
    --border-secondary: #475569;
    
    /* Spacing Scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.2);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    
    /* Z-Index Layers */
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal: 1050;
    --z-tooltip: 1070;
}

/* ===========================================
   2. RESET & BASE
   =========================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-sans);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-secondary);
    min-height: 100vh;
}

img, video, canvas, svg {
    display: block;
    max-width: 100%;
}

input, button, textarea, select {
    font: inherit;
}

/* ===========================================
   3. UNIVERSAL AI STATUS BAR
   =========================================== */
.ai-status-bar {
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md);
    margin: var(--space-md) auto;
    margin-bottom: var(--space-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 40px;
    height: auto;
    width: calc(100% - 2rem);
    max-width: 1200px;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 10;
}

/* The bar spans the page, but its contents line up with the column beneath
   it. Without this the Back button sits at the far left of a 1200px bar while
   the card it belongs to is a 600px column in the middle of the screen, so
   Back appears to belong to nothing. Pages that are already full width set
   nothing and are unaffected. */
.ai-status-content {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: var(--page-column, 100%);
    margin: 0 auto;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

@media (max-width: 480px) {
    .ai-status-content {
        flex-wrap: nowrap;
    }
}

.ai-status-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    /* No wrapping, and the children allowed to shrink: this row is a back
       arrow, a dot and a short status, and it has to stay one line beside
       Sign Out. */
    flex-wrap: nowrap;
    min-width: 0;
}

.ai-status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    min-width: 0;
}

@media (max-width: 480px) {
    .ai-status-left {
        gap: var(--space-xs);
    }
}

.back-button svg,
.back-link svg {
    flex: none;
    display: block;
}

.back-button,
.back-link {
    display: inline-flex;
    align-items: center;
    /* The icon and the word are one unit centred in the pill. Without this the
       svg baseline-aligns and the label sits low and left of centre. */
    justify-content: center;
    line-height: 1;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: var(--radius-full);
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all var(--transition-base);
    cursor: pointer;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .back-button span:not(:first-child),
    .back-link span:not(:first-child) {
        display: none;
    }
    
    .back-button,
    .back-link {
        padding: var(--space-xs);
        min-width: auto;
    }
}

.btn-support {
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

@media (max-width: 480px) {
    .btn-support {
        font-size: 0.75rem;
        padding: var(--space-xs) var(--space-xs);
    }
}

.back-button:hover,
.back-link:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.ai-status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.status-online {
    background: var(--success);
}

.status-text {
    font-weight: 600;
    font-size: 0.875rem;
    color: white;

    /* Sized to the gap it sits in - between the back arrow and Sign Out -
       rather than to the sentence it happens to be carrying. A claim status
       is a phrase, and a phrase that wraps pushes the whole bar onto two
       lines on a phone. It stays on one line and truncates; the full text is
       on the page underneath, which is where somebody reads it. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 14rem;
}

@media (max-width: 480px) {
    .status-text {
        font-size: 0.8125rem;
        max-width: 9rem;
    }
}

.ai-status-message {
    display: none;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

@media (min-width: 768px) {
    .ai-status-message {
        display: block;
    }
}

/* Pulse animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===========================================
   4. LAYOUT CONTAINERS
   =========================================== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.container {
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

/* Desktop: max-width constraint */
@media (min-width: 768px) {
    .container {
        max-width: 1280px;
    }
}

/* ===========================================
   5. REUSABLE COMPONENTS
   =========================================== */

/* ============ Headers (DEPRECATED - Use AI Status Bar) ============ */
.header {
    /* Kept for backward compatibility but should not be used */
    display: none;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-weight: 600;
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    cursor: pointer;
    border: 1px solid transparent;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 44px;
    text-decoration: none;
}

.btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Button Variants */
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
    background: var(--bg-secondary);
    border-color: var(--border-secondary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-support {
    padding: var(--space-xs) var(--space-md);
    background: transparent;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-support:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-xs) var(--space-md);
    min-height: 36px;
    font-size: 0.875rem;
}

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    min-height: 52px;
    font-size: 1.125rem;
}

.btn-block {
    width: 100%;
}

/* ============ Cards ============ */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-primary);
    overflow: hidden;
}

.card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
    background: linear-gradient(135deg, #0f172a, #1e293b);
}

.card-body {
    padding: var(--space-lg);
}

.card-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

/* ============ Forms ============ */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* ============ Badges ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary-border);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid var(--primary-border);
}

.badge-warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* ============ Modals ============ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-primary);
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    background: var(--bg-secondary);
}

/* The adjuster's choice at sign-in - see chooseStart in js/app.js. */
.start-choices {
    display: grid;
    gap: var(--space-sm);
    margin: var(--space-md) 0;
}

.start-choice-help {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ============ Tabs ============ */
.tabs {
    display: flex;
    gap: var(--space-xs);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.tab {
    padding: var(--space-sm) var(--space-lg);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-bottom: 2px solid transparent;
}

.tab:hover {
    color: var(--text-secondary);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ============ Loading States ============ */
.loading {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-primary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-sm {
    width: 1rem;
    height: 1rem;
}

.loading-lg {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

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

/* ============ Progress Bar ============ */
.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    transition: width var(--transition-base);
}

/* ===========================================
   6. UTILITY CLASSES
   =========================================== */

/* Display */
.hidden { display: none !important; }
.block { display: block !important; }
.flex { display: flex !important; }
.grid { display: grid !important; }

/* Flexbox */
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* Spacing */
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }

/* Text */
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* ===========================================
   7. ANIMATIONS
   =========================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

/* ===========================================
   8. COMMON PATTERNS
   =========================================== */

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-text {
    color: var(--text-secondary);
}

/* Message Container
   showMessage() builds `message-container alert alert-<type>`. The container
   only ever positioned it - the alert classes it also asks for were never
   defined, so every error in the app rendered as naked text floating in the
   corner with no background behind it. */
.message-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: var(--z-tooltip);
    max-width: 400px;
    animation: slideInDown 0.3s ease;
}

.alert {
    --alert-accent: var(--primary);

    display: flex;
    align-items: stretch;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--alert-accent);
    background: var(--bg-secondary);
    /* The bar carries the meaning, so the message itself stays at full
       reading contrast rather than being tinted red. */
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.4;
    /* It lands over a card, over a photo, over anything. */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.alert::before {
    content: '';
    flex: none;
    width: 3px;
    border-radius: var(--radius-full);
    background: var(--alert-accent);
}

.alert-error   { --alert-accent: var(--danger); }
.alert-success { --alert-accent: var(--success); }
.alert-warning { --alert-accent: var(--warning); }
.alert-info    { --alert-accent: var(--primary); }

/* ===========================================
   9. RESPONSIVE HELPERS
   =========================================== */
@media (max-width: 767px) {
    .md\:hidden { display: none !important; }
}

@media (min-width: 768px) {
    .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
    .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .md\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}
/* =============================================================================
   PIXFIXER BRAND MARK
   =============================================================================
   The "P" logomark that replaced the generic 🤖 emoji. Sized in `em` so a
   single class works everywhere the emoji did - a 1rem inline status icon, a
   1.5rem indicator, a 3rem hero icon - by inheriting the surrounding
   font-size instead of needing a variant per context. */

.pf-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    border-radius: 0.24em;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
    vertical-align: -0.15em;
    user-select: none;
}

/* The glyph is drawn from CSS so the letter is never selected, copied or
   translated as page text. */
.pf-mark::before {
    content: "P";
    font-size: 0.66em;
}

/* Softer treatment for use on an already-green surface. */
.pf-mark.pf-mark-ghost {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

/* Matches the pulse the processing emoji used to carry. */
.pf-mark.pf-mark-live {
    animation: pulse 2s infinite;
}


/* ===========================================
   SUPPORT PANEL
   How to reach a human. Built by app.js rather than sitting in any one
   page's markup, because the nav that opens it is built there too - a
   handler that depends on one page's HTML is how the Support tab came to
   call a function that did not exist.
   =========================================== */

.support-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    /* The page's own dark, dimmed, so it reads as the page receding. */
    background: rgba(15, 23, 42, 0.72);
}

.support-card {
    width: 100%;
    max-width: 22rem;
    padding: var(--space-lg);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.support-title {
    margin: 0 0 var(--space-xs);
    font-size: 1.125rem;
    color: var(--text-primary);
}

.support-body {
    margin: 0 0 var(--space-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Big enough to hit with a thumb, and clearly a thing you can act on
   rather than a line of text about one. */
.support-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    /* An address wraps rather than running off the side of the card. */
    word-break: break-word;
}

.support-line:hover { border-color: var(--primary); }
.support-icon { flex: none; }

.support-hours {
    margin: var(--space-md) 0;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.support-close {
    width: 100%;
    padding: 0.625rem;
    background: none;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font: inherit;
    cursor: pointer;
}

.support-close:hover { color: var(--text-primary); border-color: var(--primary); }


/* ===========================================
   ROLE TOGGLE
   Shown only to somebody who holds more than one staff role. It switches
   the console, never the permission - the server re-reads the roster on
   every request behind either page.
   =========================================== */
.role-toggle {
    display: inline-flex;
    margin-left: auto;
    margin-right: var(--space-sm);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.role-toggle-option {
    padding: .3rem .85rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
}
.role-toggle-option + .role-toggle-option { border-left: 1px solid var(--border-secondary); }
.role-toggle-option:hover { color: var(--text-primary); }
.role-toggle-option.is-current {
    background: var(--primary-light);
    color: var(--primary);
}
