/* PestControl Web — Theme & Components */
/* Matches iOS Theme.swift exactly */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* Colors */
    --bg: #1A1A2E;
    --surface-primary: #16213E;
    --surface-secondary: #0F3460;
    --accent: #AAFF00;
    --accent-dim: #88CC00;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A0B8;
    --text-tertiary: #6B6B80;
    --destructive: #FF4757;
    --warning: #FFA502;
    --success: #2ED573;
    --info: #45AAF2;
    --card-bg: #1E2A4A;
    --divider: rgba(255,255,255,0.08);
    --glass-bg: rgba(26,26,46,0.85);

    /* Spacing */
    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;
    --sp-xxl: 48px;

    /* Radii */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 24px;

    /* Typography */
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Shadows */
    --shadow-card: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-elevated: 0 8px 32px rgba(0,0,0,0.4);
}

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

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dim); }

input, button, textarea, select { font-family: inherit; font-size: inherit; }

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

.sidebar {
    width: 260px;
    background: var(--surface-primary);
    border-right: 1px solid var(--divider);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: var(--sp-lg);
    border-bottom: 1px solid var(--divider);
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
}

.sidebar-logo .logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--bg);
    font-weight: 700;
}

.sidebar-logo span {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: var(--sp-md) var(--sp-sm);
    display: flex;
    flex-direction: column;
    gap: var(--sp-xs);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
    padding: var(--sp-sm) var(--sp-md);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.925rem;
    transition: all 0.15s ease;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.sidebar-nav a.active {
    background: rgba(170,255,0,0.1);
    color: var(--accent);
}

.sidebar-nav a .nav-icon {
    width: 22px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-user {
    padding: var(--sp-md) var(--sp-lg);
    border-top: 1px solid var(--divider);
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
}

.sidebar-user .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent);
    overflow: hidden;
}

.sidebar-user .user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.sidebar-user .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: capitalize;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    min-height: 100dvh;
    padding: var(--sp-lg) var(--sp-xl);
    max-width: 1200px;
}

/* Bottom Tab Bar (mobile) */
.bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-primary);
    border-top: 1px solid var(--divider);
    z-index: 100;
    padding: var(--sp-xs) 0;
    padding-bottom: env(safe-area-inset-bottom, var(--sp-xs));
}

.bottom-tabs a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--sp-xs) 0;
    color: var(--text-tertiary);
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.15s;
}

.bottom-tabs a .tab-icon { font-size: 1.3rem; }
.bottom-tabs a.active { color: var(--accent); }

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-lg);
    gap: var(--sp-md);
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.page-header-actions {
    display: flex;
    gap: var(--sp-sm);
}

/* Back button */
.back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--sp-xs);
    font-size: 1.2rem;
    border-radius: var(--r-sm);
    transition: all 0.15s;
}

.back-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

/* === COMPONENTS === */

/* Buttons */
.pc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-md);
    border: none;
    border-radius: var(--r-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 44px;
    line-height: 1;
}

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

.pc-btn--primary {
    background: var(--accent);
    color: var(--bg);
}

.pc-btn--primary:hover:not(:disabled) {
    background: var(--accent-dim);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(170,255,0,0.25);
}

.pc-btn--secondary {
    background: var(--surface-secondary);
    color: var(--text-primary);
}

.pc-btn--secondary:hover:not(:disabled) {
    background: rgba(15,52,96,0.8);
}

.pc-btn--destructive {
    background: rgba(255,71,87,0.15);
    color: var(--destructive);
}

.pc-btn--destructive:hover:not(:disabled) {
    background: rgba(255,71,87,0.25);
}

.pc-btn--ghost {
    background: transparent;
    color: var(--text-secondary);
}

.pc-btn--ghost:hover:not(:disabled) {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.pc-btn--small {
    padding: var(--sp-xs) var(--sp-sm);
    font-size: 0.8rem;
    min-height: 32px;
}

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

.pc-btn--icon {
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 1.2rem;
}

/* Cards */
.pc-card {
    background: var(--card-bg);
    border-radius: var(--r-lg);
    padding: var(--sp-md);
    border: 1px solid var(--divider);
    transition: all 0.2s ease;
}

.pc-card--clickable {
    cursor: pointer;
}

.pc-card--clickable:hover {
    border-color: rgba(170,255,0,0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-card);
}

.pc-card--glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Fields */
.pc-field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-xs);
}

.pc-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pc-field input,
.pc-field textarea,
.pc-field select {
    background: var(--surface-primary);
    border: 1px solid var(--divider);
    border-radius: var(--r-sm);
    padding: var(--sp-sm) var(--sp-md);
    color: var(--text-primary);
    min-height: 44px;
    transition: border-color 0.15s;
    outline: none;
}

.pc-field input:focus,
.pc-field textarea:focus,
.pc-field select:focus {
    border-color: var(--accent);
}

.pc-field textarea {
    resize: vertical;
    min-height: 88px;
}

.pc-field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23A0A0B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.pc-field select option {
    background: var(--surface-primary);
    color: var(--text-primary);
}

/* Form grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-md);
}

.form-grid .full-width { grid-column: 1 / -1; }

/* Search bar */
.pc-search-bar {
    position: relative;
}

.pc-search-bar input {
    width: 100%;
    background: var(--surface-primary);
    border: 1px solid var(--divider);
    border-radius: var(--r-sm);
    padding: var(--sp-sm) var(--sp-md) var(--sp-sm) 40px;
    color: var(--text-primary);
    min-height: 44px;
    outline: none;
    transition: border-color 0.15s;
}

.pc-search-bar input:focus {
    border-color: var(--accent);
}

.pc-search-bar .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 1rem;
    pointer-events: none;
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-xs);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.02em;
}

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

.status-badge--pending { background: rgba(160,160,184,0.15); color: var(--text-secondary); }
.status-badge--pending::before { background: var(--text-secondary); }
.status-badge--assigned { background: rgba(69,170,242,0.15); color: var(--info); }
.status-badge--assigned::before { background: var(--info); }
.status-badge--in_progress { background: rgba(255,165,2,0.15); color: var(--warning); }
.status-badge--in_progress::before { background: var(--warning); }
.status-badge--completed { background: rgba(46,213,115,0.15); color: var(--success); }
.status-badge--completed::before { background: var(--success); }
.status-badge--cancelled { background: rgba(255,71,87,0.15); color: var(--destructive); }
.status-badge--cancelled::before { background: var(--destructive); }
.status-badge--active { background: rgba(46,213,115,0.15); color: var(--success); }
.status-badge--active::before { background: var(--success); }
.status-badge--inactive { background: rgba(160,160,184,0.15); color: var(--text-tertiary); }
.status-badge--inactive::before { background: var(--text-tertiary); }

/* Filter chips */
.filter-chips {
    display: flex;
    gap: var(--sp-sm);
    flex-wrap: wrap;
}

.filter-chip {
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--surface-primary);
    border: 1px solid var(--divider);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.filter-chip:hover { border-color: rgba(255,255,255,0.15); }
.filter-chip.active { background: rgba(170,255,0,0.12); border-color: var(--accent); color: var(--accent); }

/* Stat cards */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--r-lg);
    padding: var(--sp-md);
    border: 1px solid var(--divider);
    display: flex;
    flex-direction: column;
    gap: var(--sp-xs);
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--accent);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-card .stat-icon {
    font-size: 1.5rem;
    margin-bottom: var(--sp-xs);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--sp-md);
}

/* Empty state */
.pc-empty-state {
    text-align: center;
    padding: var(--sp-xxl) var(--sp-lg);
    color: var(--text-tertiary);
}

.pc-empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: var(--sp-md);
    opacity: 0.5;
}

.pc-empty-state .empty-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--sp-xs);
}

.pc-empty-state .empty-desc {
    font-size: 0.9rem;
    margin-bottom: var(--sp-lg);
}

/* Modal / Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: var(--sp-md);
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--surface-primary);
    border-radius: var(--r-xl);
    padding: var(--sp-lg);
    max-width: 500px;
    width: 100%;
    max-height: 85dvh;
    overflow-y: auto;
    border: 1px solid var(--divider);
    box-shadow: var(--shadow-elevated);
    animation: slideUp 0.2s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-md);
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: var(--sp-xs);
    line-height: 1;
}

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

.modal-actions {
    display: flex;
    gap: var(--sp-sm);
    justify-content: flex-end;
    margin-top: var(--sp-lg);
}

/* Toast */
.toast-container {
    position: fixed;
    top: var(--sp-lg);
    right: var(--sp-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

.toast {
    background: var(--surface-primary);
    border: 1px solid var(--divider);
    border-radius: var(--r-md);
    padding: var(--sp-sm) var(--sp-md);
    font-size: 0.9rem;
    box-shadow: var(--shadow-elevated);
    animation: slideInRight 0.25s ease;
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    min-width: 250px;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--destructive); }
.toast--info { border-left: 3px solid var(--info); }

/* Loading */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-xxl);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--divider);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner--small {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

/* Section divider */
.section-divider {
    height: 1px;
    background: var(--divider);
    margin: var(--sp-lg) 0;
}

/* List */
.pc-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

/* Flow tags */
.flow-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-xs);
}

.flow-tag {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-secondary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
}

/* Timeline */
.timeline {
    display: flex;
    align-items: center;
    gap: 0;
    padding: var(--sp-md) 0;
}

.timeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-xs);
    flex: 1;
    position: relative;
}

.timeline-step .step-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface-secondary);
    border: 2px solid var(--divider);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    z-index: 1;
    transition: all 0.2s;
}

.timeline-step.reached .step-dot {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.timeline-step.current .step-dot {
    background: var(--warning);
    border-color: var(--warning);
    color: var(--bg);
    box-shadow: 0 0 12px rgba(255,165,2,0.4);
}

.timeline-step .step-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-align: center;
    font-weight: 500;
}

.timeline-step.reached .step-label,
.timeline-step.current .step-label {
    color: var(--text-secondary);
}

.timeline-connector {
    flex: 1;
    height: 2px;
    background: var(--divider);
    margin-top: -20px;
}

.timeline-connector.reached { background: var(--accent); }

/* Category chips (for chemicals) */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--sp-sm);
}

.category-chip {
    padding: var(--sp-sm) var(--sp-md);
    border-radius: var(--r-sm);
    background: var(--surface-primary);
    border: 1px solid var(--divider);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}

.category-chip:hover { border-color: rgba(255,255,255,0.15); }
.category-chip.active { background: rgba(170,255,0,0.12); border-color: var(--accent); color: var(--accent); }

/* Toggle */
.pc-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-sm) 0;
}

.pc-toggle label {
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
}

.toggle-switch {
    width: 48px;
    height: 28px;
    background: var(--surface-secondary);
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    appearance: none;
}

.toggle-switch:checked { background: var(--accent); }

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
}

.toggle-switch:checked::after { transform: translateX(20px); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

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

.skeleton {
    background: linear-gradient(90deg, var(--surface-primary) 25%, var(--surface-secondary) 50%, var(--surface-primary) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s ease infinite;
    border-radius: var(--r-sm);
}
