/* ---------- Общее ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --sidebar-bg: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

#app {
    height: 100%;
}

/* ---------- Экран авторизации ---------- */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
}

.auth-card {
    background: #fff;
    padding: 40px 32px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    text-align: center;
    min-width: 320px;
}

.auth-card h1 {
    font-size: 22px;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.auth-error {
    color: var(--danger);
    margin-top: 16px;
    font-size: 13px;
}

/* ---------- Каркас приложения ---------- */
.app-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
}

/* ---------- Боковая панель ---------- */
.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.user-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.filters {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filters input,
.filters select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    outline: none;
}

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

/* ---------- Список территорий ---------- */
.territories-list {
    flex: 1;
    overflow-y: auto;
}

.territory-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

.territory-item:hover {
    background: #f1f5f9;
}

.territory-item.active {
    background: #dbeafe;
}

.territory-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.territory-number {
    font-weight: 600;
    font-size: 15px;
}

.territory-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-available {
    background: #dcfce7;
    color: #166534;
}

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

.status-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.status-inactive {
    background: #e5e7eb;
    color: #4b5563;
}

.territory-name {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.territory-assignee {
    font-size: 12px;
    color: var(--primary);
    margin-top: 4px;
}

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------- Футер панели ---------- */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ---------- Кнопки ---------- */
.btn-primary,
.btn-secondary,
.btn-icon {
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: background 0.1s;
}

.btn-primary {
    width: 100%;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
}

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

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

.btn-secondary {
    padding: 10px 16px;
    background: #e2e8f0;
    color: var(--text);
    border-radius: 6px;
    font-size: 14px;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-icon {
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-icon:hover {
    background: #f1f5f9;
    color: var(--text);
}

/* ---------- Область карты ---------- */
.map-container {
    position: relative;
    background: #e5e7eb;
    overflow: hidden;
}

.map {
    width: 100%;
    height: 100%;
}

.map-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(135deg, #f8fafc 25%, #e2e8f0 25%, #e2e8f0 50%, #f8fafc 50%, #f8fafc 75%, #e2e8f0 75%);
    background-size: 40px 40px;
    pointer-events: none;
}

.map-placeholder-content {
    background: rgba(255, 255, 255, 0.95);
    padding: 32px 40px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    text-align: center;
    max-width: 400px;
}

.map-placeholder-content h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.map-placeholder-content p {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.map-placeholder-content .hint {
    font-size: 12px;
    color: var(--primary);
    margin-top: 12px;
}

/* ---------- Модальное окно ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: #fff;
    padding: 24px 28px;
    border-radius: 12px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.modal h3 {
    font-size: 17px;
    margin-bottom: 16px;
}

.modal label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.modal input,
.modal textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    resize: vertical;
}

.modal input:focus,
.modal textarea:focus {
    border-color: var(--primary);
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 10px 12px;
    border-radius: 6px;
    margin-top: 8px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.modal-actions .btn-primary {
    width: auto;
}

/* ---------- Адаптив для узких экранов ---------- */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }
    .sidebar {
        display: none;
    }
}
