:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

/* Анимации */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    /* Отключаем стандартный pull-to-refresh */
    overscroll-behavior-y: contain;
}

/* Экраны */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 20px;
}

/* Авторизация */
.login-box {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: 0 4px 12px var(--shadow);
    margin-top: 20vh;
}

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

.logo svg {
    color: var(--primary);
    margin-bottom: 12px;
}

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.logo p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Формы */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.input, .select {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

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

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

.btn-block {
    width: 100%;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

/* Спиннеры */
.spinner, .spinner-large {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-large {
    width: 40px;
    height: 40px;
    border-color: var(--border);
    border-top-color: var(--primary);
}

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

/* Overlay для проверки сессии */
.session-check-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

/* Pull to Refresh индикатор */
.pull-to-refresh-indicator {
    position: fixed;
    top: -100px;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.ptr-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin-bottom: 8px;
}

.pull-to-refresh-indicator.refreshing .ptr-spinner {
    animation: spin 1s linear infinite;
}

.ptr-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Ошибки */
.error-message {
    padding: 12px 16px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

/* Шапка */
.header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
}

/* Навигация */
.nav-tabs {
    display: flex;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
    font-size: 12px;
    font-weight: 500;
}

.nav-tab svg {
    stroke-width: 2;
}

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

.nav-tab:hover {
    color: var(--primary);
}

/* Контент */
.content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
}

.tab-content {
    display: none;
}

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

/* Фильтры */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.filter-bar .select {
    flex: 1;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-icon:active {
    transform: scale(0.95);
}

.btn-icon svg {
    flex-shrink: 0;
}

/* Список задач */
.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-card {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 2px 8px var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.task-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.task-id-with-icon {
    display: flex;
    align-items: center;
    gap: 8px;
}

.task-type-icon {
    font-size: 24px;
    line-height: 1;
}

.task-id {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.task-status {
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.task-status.new {
    background: #dbeafe;
    color: #1e40af;
}

.task-status.in_progress {
    background: #fef3c7;
    color: #92400e;
}

.task-status.completed {
    background: #d1fae5;
    color: #065f46;
}

.task-info {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.task-address {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 500;
}

.task-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.btn-map {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-map:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.btn-map:active {
    transform: translateY(0);
}

.btn-map svg {
    flex-shrink: 0;
}

/* Загрузка */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Поиск */
.search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.search-box .input {
    flex: 1;
}

/* Кастомные маркеры на карте */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

/* Карта */
.map-container {
    height: calc(100vh - 200px);
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

/* Leaflet controls styling */
.map-container .leaflet-container {
    height: 100%;
    width: 100%;
    border-radius: var(--radius);
}

/* Task popup styling */
.task-popup {
    padding: 8px;
    min-width: 200px;
}

.task-popup h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

.task-popup p {
    margin: 4px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.task-popup button {
    margin-top: 8px;
    padding: 6px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}

.task-popup button:hover {
    background: var(--primary-dark);
}

.map-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.map-placeholder svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
}

/* Комментарии в задаче */
.task-comments-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border);
}

.task-comments-section h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: var(--text-primary);
}

.task-comments {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.empty-comments {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-style: italic;
}

.loading-comments {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-style: italic;
}

.comment-item {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.comment-author {
    font-weight: 600;
    color: var(--primary);
}

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

.comment-text {
    color: var(--text-primary);
    white-space: pre-wrap;
    line-height: 1.4;
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.comment-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

.comment-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Детали задачи в модалке */
.task-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-details .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.task-details .detail-row.full {
    flex-direction: column;
    gap: 8px;
}

.task-details .label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 120px;
}

.task-details .value {
    color: var(--text-primary);
    text-align: right;
}

.task-details .description {
    margin: 0;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.task-details .error {
    padding: 20px;
    text-align: center;
    color: var(--error);
}

.task-details .loading {
    padding: 40px 20px;
    text-align: center;
}

/* Адаптивность */
@media (max-width: 640px) {
    .container {
        padding: 16px;
    }
    
    .login-box {
        margin-top: 10vh;
        padding: 24px 20px;
    }
    
    .content {
        padding: 16px;
    }
}

/* Стили для смены статуса задачи */
#statusChangeUI {
    padding: 10px 0;
}

.status-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.btn-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.btn-status:hover {
    border-color: #007AFF;
    background: #f0f8ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
}

.btn-status:active {
    transform: translateY(0);
}

.btn-status .status-icon {
    font-size: 20px;
}

.btn-status .status-name {
    color: #333;
}

.status-dropdown {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.status-dropdown label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: #666;
}

.status-dropdown select {
    width: 100%;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.status-dropdown select:focus {
    outline: none;
    border-color: #007AFF;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.loading-states, .error {
    padding: 15px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.error {
    color: #ff3b30;
}

/* Стили для секции с фото */
.task-photos-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.task-photos-section h3 {
    margin-bottom: 15px;
    font-size: 16px;
    color: #333;
}

.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.photo-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
    cursor: pointer;
    transition: transform 0.2s;
}

.photo-item:hover {
    transform: scale(1.05);
}

.photo-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.photo-info {
    padding: 5px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 11px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

.photo-upload-form {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.btn-camera,
.btn-gallery {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #007AFF;
    border-radius: 8px;
    background: white;
    color: #007AFF;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-camera:hover,
.btn-gallery:hover {
    background: #007AFF;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.btn-camera:active,
.btn-gallery:active {
    transform: translateY(0);
}

.loading-photos,
.uploading-photo,
.no-photos {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.uploading-photo {
    color: #007AFF;
}

.no-photos {
    color: #999;
}

/* Ссылка для звонка */
.phone-link {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-block;
}

.phone-link:hover {
    background-color: #007bff;
    color: white;
}

.phone-link:active {
    transform: scale(0.95);
}
