/* Сброс стилей и базовые настройки */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1976d2;
    --primary-dark: #1565c0;
    --primary-light: #42a5f5;
    --accent-color: #4caf50;
    --error-color: #f44336;
    --warning-color: #ff9800;
    --text-primary: #212121;
    --text-secondary: #757575;
    --background: #f5f5f5;
    --surface: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Offline Banner */
.offline-banner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--error-color);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    border: none;
    box-shadow: var(--shadow);
    pointer-events: none;
}

.offline-banner.hidden {
    display: none;
}

/* Notification */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    max-width: 90%;
    text-align: center;
    animation: slideUp 0.3s ease;
}

.notification.hidden {
    display: none;
}

.notification.success {
    background: var(--accent-color);
}

.notification.error {
    background: var(--error-color);
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* App Container */
.app-container {
    min-height: 100vh;
    width: 100%;
}

/* Pages */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--primary-color);
}

.logo {
    margin-bottom: 24px;
    animation: fadeIn 0.5s ease;
}

.login-container h1 {
    color: white;
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 8px;
    animation: fadeIn 0.5s ease 0.1s both;
    text-align: center;
}

.subtitle {
    color: white;
    font-size: 16px;
    margin-bottom: 32px;
    animation: fadeIn 0.5s ease 0.2s both;
    text-align: center;
}

.login-form {
    width: 100%;
    max-width: 400px;
    background: transparent;
    padding: 0;
    border-radius: 8px;
    box-shadow: none;
    animation: fadeIn 0.5s ease 0.3s both;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.form-group {
    margin-bottom: 20px;
    width: 100%;
}

.login-container .form-group label {
    color: white;
}

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

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.3s ease;
    background: var(--surface);
}

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

.form-group input:invalid {
    border-color: var(--error-color);
}

/* Error Message */
.error-message {
    padding: 12px;
    background: #ffebee;
    color: var(--error-color);
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 16px;
}

.error-message.hidden {
    display: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    gap: 8px;
}

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

.btn-primary {
    background: white;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    font-weight: bold;
}

.btn-primary:hover:not(:disabled) {
    background: #f0f0f0;
    box-shadow: var(--shadow);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

#login-form > .btn {
    align-self: center;
    margin: 10px auto 0;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.3s ease;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
}

/* Version */
.version {
    margin-top: 24px;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    animation: fadeIn 0.5s ease 0.4s both;
}

/* Main Page */
.main-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: var(--primary-color);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 20px;
    font-weight: 500;
}

.header .btn-icon {
    color: white;
}

.content {
    flex: 1;
    padding: 20px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 600px) {
    .login-form {
        padding: 24px 20px;
    }
    
    .login-container h1 {
        font-size: 28px;
    }
}

/* iOS Safe Area */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .content {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* --- НОВЫЕ СТИЛИ ДЛЯ ИТЕРАЦИИ 10 --- */

/* Views instead of Pages */
.view {
    min-height: 100vh;
    width: 100%;
    display: none;
    flex-direction: column;
    animation: fadeInView 0.4s ease;
}
.view.active {
    display: flex;
}

@keyframes fadeInView {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* FAB Button */
.btn-fab {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    font-size: 28px;
    line-height: 56px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
}
.btn-fab:hover {
    background-color: var(--primary-dark);
}
.btn-fab:active {
    transform: scale(0.95);
}


/* Wizard Styles */
.wizard-content {
    padding-bottom: 80px; /* Space for nav buttons */
}

.progress-bar {
    width: 100%;
    height: 6px;
    background-color: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    bottom: 0;
    left: 0;
}

.progress-bar-inner {
    height: 100%;
    width: 0%;
    background-color: var(--accent-color);
    transition: width 0.3s ease;
}

.wizard-step {
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

.wizard-step h2 {
    font-size: 22px;
    margin-bottom: 24px;
}

.wizard-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px max(20px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom));
    background-color: var(--surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.wizard-nav .btn {
    flex-grow: 1;
}

/* Form elements */
textarea {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.3s ease;
    background: var(--surface);
    font-family: inherit;
    resize: vertical;
}

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

.radio-group label {
    display: block;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.radio-group input[type="radio"] {
    margin-right: 12px;
}

.radio-group input[type="radio"]:checked + label {
    border-color: var(--primary-color);
    background-color: #e3f2fd;
}
/* This is a workaround for the :has selector not being fully supported */
.radio-group label:has(input:checked) {
     border-color: var(--primary-color);
     background-color: #e3f2fd;
}


input[type="file"] {
    display: block;
    margin-top: 8px;
    font-size: 14px;
}

.file-preview {
    max-width: 100%;
    height: auto;
    margin-top: 16px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.meter-form {
    background-color: #f9f9f9;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.meter-form h4 {
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.summary {
    background-color: var(--surface);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.summary p {
    margin-bottom: 12px;
    font-size: 16px;
}
.summary p:last-child {
    margin-bottom: 0;
}
.summary strong {
    color: var(--text-secondary);
}
.login-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
}

.progress-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 15px;
}
#wizard-progress-text {
    color: #fff;
    font-size: 14px;
}
.wizard-header {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--primary-color);
    color: #fff;
    padding: 10px 15px;
}
.wizard-header h1 { margin: 0; color: #fff; font-weight: 600; }
.wizard-header .btn { background: #fff; color: var(--primary-color); }

/* Прогресс: текст одной строкой, полоса ниже */
.progress-wrap { display: flex; flex-direction: column; gap: 6px; padding: 6px 15px; background-color: var(--primary-color); }
#wizard-progress-text { color: #fff; font-size: 14px; white-space: nowrap; }
.progress-bar { width: 100%; height: 6px; background-color: rgba(255,255,255,0.4); border-radius: 3px; overflow: hidden; position: relative; }
.progress-bar-inner { height: 100%; width: 0%; background-color: #2ecc71; transition: width 0.3s ease; }

/* Контент */
.wizard-content { padding: 20px 15px 80px; }

/* Превью фото */
.preview-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border-color); cursor: pointer; position: relative; }
.thumb-wrap { position: relative; display: inline-block; }
.thumb-delete { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--error-color); color: #fff; border: none; cursor: pointer; font-weight: 700; line-height: 18px; text-align: center; }
.camera-btn { margin-left: 8px; background: var(--primary-dark); color: #fff; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; }
.camera-btn:before { content: '\1F4F7'; margin-right: 6px; }

/* Модалка для просмотра фото */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.modal.hidden { display: none; }
.modal img { max-width: 90vw; max-height: 80vh; border-radius: 6px; box-shadow: var(--shadow-lg); }
.modal-close { position: absolute; top: 12px; right: 12px; background: var(--error-color); color: #fff; border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer; }

/* Таблица сводки */
.summary table { width: 100%; border-collapse: collapse; margin-top: 10px; background: #fff; }
.summary th, .summary td { border: 1px solid var(--border-color); padding: 8px; text-align: left; }
.summary .ok { color: #2e7d32; font-weight: 600; }
.summary .warn { color: var(--error-color); font-weight: 600; }

/* Апбар главного экрана */
.app-header { display: flex; align-items: center; justify-content: space-between; background: var(--primary-color); color: #fff; padding: 12px 15px; }
.app-header h1 { margin: 0; font-weight: 600; color: #fff; }
.app-header .header-actions { display: flex; gap: 8px; align-items: center; }
.app-header .btn-exit { background: #fff; color: var(--primary-color); border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 500; }
.btn-sync { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: 14px; font-weight: 500; min-height: 36px; }
.btn-sync .btn-sync-icon { display: inline-flex; align-items: center; }
.btn-sync.syncing .btn-sync-icon { animation: rotate 1s linear infinite; }
@keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Контент главного экрана */
.main-content { padding: 20px 15px; }
.wizard-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin-bottom: 20px;
}

.wizard-toolbar .btn {
    flex-shrink: 0;
}


/* Список заявок */
.applications-list { margin-top: 20px; }
.application-item { border: 1px solid var(--border-color); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; background: #fff; transition: box-shadow 0.2s; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.application-item.editable { cursor: pointer; border-left: 4px solid var(--error-color); background: #fff5f5; box-shadow: 0 2px 6px rgba(198, 40, 40, 0.15); }
.application-item.editable:hover { box-shadow: 0 3px 10px rgba(198, 40, 40, 0.25); }
.application-item.editable:active { transform: scale(0.98); }
.application-item.readonly { opacity: 0.85; cursor: default; }
.application-content { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.application-address { font-weight: 500; font-size: 15px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.application-type { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.application-type.hvs { background: #e3f2fd; color: #1976d2; }
.application-type.gvs { background: #fff3e0; color: #f57c00; }
.application-status { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 10px; font-size: 12px; font-weight: 500; white-space: nowrap; flex-shrink: 0; }
.application-status.sent { background: #e8f5e9; color: #2e7d32; }
.application-status.pending { background: #fff8e1; color: #f57f17; }
.application-status.approved { background: #e1f5fe; color: #0277bd; }
.application-status.rejected { background: #ffebee; color: #c62828; font-weight: 600; }
.applications-empty { text-align: center; padding: 40px 20px; color: var(--text-secondary); }

/* Список-проверка (шаг 7) */
.checklist { list-style: none; padding: 0; margin: 10px 0 0; }
.check-item { border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fff; }
.check-title { font-weight: 600; margin-bottom: 6px; }
.check-meta { color: var(--text-secondary); font-size: 14px; margin-bottom: 6px; }
.check-flags { display: flex; flex-wrap: wrap; gap: 8px; }
.flag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 16px; border: 1px solid var(--border-color); font-size: 14px; transition: transform 0.2s, box-shadow 0.2s; }
.flag.ok { background: #e8f5e9; color: #2e7d32; border-color: #c8e6c9; }
.flag.err { background: #ffebee; color: var(--error-color); border-color: #ffcdd2; }
.flag input { pointer-events: none; }
.flag[style*="cursor: pointer"]:hover { transform: translateY(-2px); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.flag[style*="cursor: pointer"]:active { transform: translateY(0); }

#application-form-preview-wrap { position: relative; display: inline-block; margin-top: 8px; }
#application-form-preview-wrap .thumb-delete { position: absolute; top: 2px; right: 2px; }

/* Индикатор синхронизации */
.sync-indicator {
    position: fixed;
    top: env(safe-area-inset-top, 10px);
    right: 10px;
    background: var(--primary-color);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
}

.sync-indicator.hidden {
    display: none;
}

.sync-indicator.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

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

.sync-icon {
    font-size: 18px;
    display: inline-block;
}

/* Блок черновиков */
.drafts-section {
    margin: 20px 0;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.drafts-section.hidden {
    display: none;
}

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

.drafts-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.drafts-section h3::before {
    content: '📝';
    font-size: 18px;
}

#drafts-count {
    color: var(--primary-color);
    font-weight: 700;
}

/* Список черновиков */
.drafts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.draft-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
    transition: all 0.2s;
}

.draft-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.draft-item.draft {
    border-left: 4px solid var(--warning-color);
    background: #fffbf0;
}

.draft-item.syncing {
    border-left: 4px solid var(--primary-color);
    background: #f0f7ff;
}

.draft-item.error {
    border-left: 4px solid var(--error-color);
    background: #fff5f5;
}

.draft-content {
    flex: 1;
    min-width: 0;
}

.draft-address {
    font-weight: 500;
    font-size: 15px;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.draft-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.draft-status {
    font-weight: 500;
}

.draft-item.syncing .draft-status {
    color: var(--primary-color);
}

.draft-item.error .draft-status {
    color: var(--error-color);
}

.form-hint {
    font-size: 0.85rem;
    color: var(--text-secondary, #666);
}

.application-reason {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--error-color, #d14343);
}

.draft-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-draft-edit,
.btn-draft-delete {
    background: transparent;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.btn-draft-edit:hover {
    background: rgba(25, 118, 210, 0.1);
}

.btn-draft-delete:hover {
    background: rgba(244, 67, 54, 0.1);
}

.btn-draft-edit:active,
.btn-draft-delete:active {
    transform: scale(0.95);
}
